From 628570e84d3ca5f89fb8e47d2de07be6743f6681 Mon Sep 17 00:00:00 2001 From: 4sval Date: Tue, 30 Aug 2022 21:46:47 +0200 Subject: [PATCH] even less --- FModel/Views/Snooper/Model.cs | 24 +++--------------------- FModel/Views/Snooper/Snooper.cs | 22 +++++++++++++++++++--- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/FModel/Views/Snooper/Model.cs b/FModel/Views/Snooper/Model.cs index 5463d881..c6befbc6 100644 --- a/FModel/Views/Snooper/Model.cs +++ b/FModel/Views/Snooper/Model.cs @@ -12,8 +12,6 @@ public class Model : IDisposable private uint _handle; private GL _gl; - private Shader _shader; - private BufferObject _ebo; private BufferObject _vbo; private VertexArrayObject _vao; @@ -84,8 +82,6 @@ public class Model : IDisposable _handle = _gl.CreateProgram(); - _shader = new Shader(_gl); - _ebo = new BufferObject(_gl, Indices, BufferTargetARB.ElementArrayBuffer); _vbo = new BufferObject(_gl, Vertices, BufferTargetARB.ArrayBuffer); _vao = new VertexArrayObject(_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(); diff --git a/FModel/Views/Snooper/Snooper.cs b/FModel/Views/Snooper/Snooper.cs index 05401e7c..e32960a8 100644 --- a/FModel/Views/Snooper/Snooper.cs +++ b/FModel/Views/Snooper/Snooper.cs @@ -37,6 +37,8 @@ public class Snooper private readonly Grid _grid; private readonly List _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();