Skip to content

Commit

Permalink
less shader call
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed Aug 30, 2022
1 parent 37b5989 commit 6ba553e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
9 changes: 8 additions & 1 deletion FModel/Views/Snooper/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,25 @@ public void Bind(Camera camera)
_shader.SetUniform("viewPos", camera.Position);
_shader.SetUniform("display_vertex_colors", _display_vertex_colors);

_shader.SetUniform("material.diffuseMap", 0);
_shader.SetUniform("material.normalMap", 1);
_shader.SetUniform("material.specularMap", 2);
_shader.SetUniform("material.emissionMap", 3);

ImGui.BeginTable("Sections", 2, ImGuiTableFlags.RowBg);
ImGui.TableSetupColumn("Index", ImGuiTableColumnFlags.WidthFixed);
ImGui.TableSetupColumn("Material", ImGuiTableColumnFlags.WidthFixed);
ImGui.TableHeadersRow();
for (int section = 0; section < Sections.Length; section++)
{
Sections[section].Bind(_shader, camera, Indices.Length);
Sections[section].Bind(_shader, Indices.Length);
// if (!Sections[section].Show) continue;
_gl.DrawArrays(PrimitiveType.Triangles, Sections[section].FirstFaceIndex, Sections[section].FacesCount);
}
ImGui.EndTable();

_shader.SetUniform("light.position", camera.Position);

ImGui.Separator();
}

Expand Down
10 changes: 3 additions & 7 deletions FModel/Views/Snooper/Section.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class Section : IDisposable
{
private uint _handle;
private GL _gl;
private FGame _game;

private Texture _diffuseMap;
private Texture _normalMap;
Expand All @@ -31,6 +30,8 @@ public class Section : IDisposable
private Vector3 _diffuseLight;
private Vector3 _specularLight;

private readonly FGame _game;

public readonly string Name;
public readonly int Index;
public readonly uint FacesCount;
Expand Down Expand Up @@ -222,7 +223,7 @@ private void SwapSpecular(UTexture2D specular, FTexture2DMipMap mip, ETexturePla
}
}

public void Bind(Shader shader, Camera camera, float indices)
public void Bind(Shader shader, float indices)
{
ImGui.TableNextRow();

Expand Down Expand Up @@ -252,10 +253,6 @@ public void Bind(Shader shader, Camera camera, float indices)
ImGui.EndTooltip();
}

shader.SetUniform("material.diffuseMap", 0);
shader.SetUniform("material.normalMap", 1);
shader.SetUniform("material.specularMap", 2);
shader.SetUniform("material.emissionMap", 3);
_diffuseMap?.Bind(TextureUnit.Texture0);
_normalMap?.Bind(TextureUnit.Texture1);
_specularMap?.Bind(TextureUnit.Texture2);
Expand All @@ -273,7 +270,6 @@ public void Bind(Shader shader, Camera camera, float indices)
shader.SetUniform("light.ambient", _ambientLight);
shader.SetUniform("light.diffuse", _diffuseLight);
shader.SetUniform("light.specular", _specularLight);
shader.SetUniform("light.position", camera.Position);
}

public void Dispose()
Expand Down

0 comments on commit 6ba553e

Please sign in to comment.