even less

This commit is contained in:
4sval 2022-08-30 21:46:47 +02:00
parent 6ba553e890
commit 628570e84d
2 changed files with 22 additions and 24 deletions

View File

@ -12,8 +12,6 @@ public class Model : IDisposable
private uint _handle;
private GL _gl;
private Shader _shader;
private BufferObject<uint> _ebo;
private BufferObject<float> _vbo;
private VertexArrayObject<float, uint> _vao;
@ -84,8 +82,6 @@ public class Model : IDisposable
_handle = _gl.CreateProgram();
_shader = new Shader(_gl);
_ebo = new BufferObject<uint>(_gl, Indices, BufferTargetARB.ElementArrayBuffer);
_vbo = new BufferObject<float>(_gl, Vertices, BufferTargetARB.ArrayBuffer);
_vao = new VertexArrayObject<float, uint>(_gl, _vbo, _ebo);
@ -101,7 +97,7 @@ public class Model : IDisposable
}
}
public void Bind(Camera camera)
public void Bind(Shader shader)
{
ImGui.Text($"Entity: {Name}");
if (HasVertexColors)
@ -109,18 +105,7 @@ public class Model : IDisposable
_vao.Bind();
_shader.Use();
_shader.SetUniform("uModel", Matrix4x4.Identity);
_shader.SetUniform("uView", camera.GetViewMatrix());
_shader.SetUniform("uProjection", camera.GetProjectionMatrix());
_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);
shader.SetUniform("display_vertex_colors", _display_vertex_colors);
ImGui.BeginTable("Sections", 2, ImGuiTableFlags.RowBg);
ImGui.TableSetupColumn("Index", ImGuiTableColumnFlags.WidthFixed);
@ -128,20 +113,17 @@ public class Model : IDisposable
ImGui.TableHeadersRow();
for (int section = 0; section < Sections.Length; section++)
{
Sections[section].Bind(_shader, 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();
}
public void Dispose()
{
_shader.Dispose();
_ebo.Dispose();
_vbo.Dispose();
_vao.Dispose();

View File

@ -37,6 +37,8 @@ public class Snooper
private readonly Grid _grid;
private readonly List<Model> _models;
private Shader _shader;
private readonly int _width;
private readonly int _height;
@ -139,6 +141,7 @@ public class Snooper
_skybox.Setup(_gl);
_grid.Setup(_gl);
_shader = new Shader(_gl);
foreach (var model in _models)
{
model.Setup(_gl);
@ -160,17 +163,29 @@ public class Snooper
_skybox.Bind(_camera);
_grid.Bind(_camera);
ImGuiExtensions.DrawNavbar();
_shader.Use();
_shader.SetUniform("uModel", Matrix4x4.Identity);
_shader.SetUniform("uView", _camera.GetViewMatrix());
_shader.SetUniform("uProjection", _camera.GetProjectionMatrix());
_shader.SetUniform("viewPos", _camera.Position);
_shader.SetUniform("material.diffuseMap", 0);
_shader.SetUniform("material.normalMap", 1);
_shader.SetUniform("material.specularMap", 2);
_shader.SetUniform("material.emissionMap", 3);
ImGuiExtensions.DrawNavbar();
ImGui.Begin("ImGui.NET", ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoBringToFrontOnFocus | ImGuiWindowFlags.NoSavedSettings);
foreach (var model in _models)
{
model.Bind(_camera);
model.Bind(_shader);
}
ImGui.End();
ImGuiExtensions.DrawFPS();
_shader.SetUniform("light.position", _camera.Position);
_controller.Render();
}
@ -243,6 +258,7 @@ public class Snooper
{
_grid.Dispose();
_skybox.Dispose();
_shader.Dispose();
foreach (var model in _models)
{
model.Dispose();