diff --git a/Hypercube.Client/Graphics/Events/RenderAfterDrawingEvent.cs b/Hypercube.Client/Graphics/Events/RenderAfterDrawingEvent.cs new file mode 100644 index 0000000..7e63f1d --- /dev/null +++ b/Hypercube.Client/Graphics/Events/RenderAfterDrawingEvent.cs @@ -0,0 +1,5 @@ +using Hypercube.EventBus.Events; + +namespace Hypercube.Client.Graphics.Events; + +public readonly record struct RenderAfterDrawingEvent : IEventArgs; \ No newline at end of file diff --git a/Hypercube.Client/Graphics/ImGui/ImGui.cs b/Hypercube.Client/Graphics/ImGui/ImGui.cs index 410eb85..36e24b5 100644 --- a/Hypercube.Client/Graphics/ImGui/ImGui.cs +++ b/Hypercube.Client/Graphics/ImGui/ImGui.cs @@ -28,7 +28,7 @@ public void PostInject() _eventBus.Subscribe(this, OnInputFrame); _eventBus.Subscribe(this, OnUpdateFrame); - _eventBus.Subscribe(this, OnRenderFrame); + _eventBus.Subscribe(this, OnRenderUI); _eventBus.Subscribe(this, OnMouseButton); _eventBus.Subscribe(this, OnMousePosition); @@ -54,7 +54,7 @@ private void OnUpdateFrame(ref UpdateFrameEvent args) _controller.Update(args.DeltaSeconds); } - private void OnRenderFrame(ref RenderFrameEvent args) + private void OnRenderUI(ref RenderAfterDrawingEvent args) { var ev = new ImGuiRenderEvent(this); _eventBus.Raise(ev); diff --git a/Hypercube.Client/Graphics/Realisation/OpenGL/Rendering/Renderer.Render.cs b/Hypercube.Client/Graphics/Realisation/OpenGL/Rendering/Renderer.Render.cs index 826f5ed..1c73a69 100644 --- a/Hypercube.Client/Graphics/Realisation/OpenGL/Rendering/Renderer.Render.cs +++ b/Hypercube.Client/Graphics/Realisation/OpenGL/Rendering/Renderer.Render.cs @@ -6,6 +6,7 @@ using Hypercube.Mathematics; using Hypercube.Mathematics.Matrices; using Hypercube.OpenGL.Objects; +using Hypercube.OpenGL.Utilities.Helpers; using Hypercube.Shared.Runtimes.Loop.Event; using OpenToolkit.Graphics.OpenGL4; @@ -43,9 +44,9 @@ private void OnLoad() _texturingShaderProgram = _resourceContainer.GetResource("/Shaders/base_texturing") .ShaderProgram; + _vao = new ArrayObject(); _vbo = new BufferObject(BufferTarget.ArrayBuffer); _ebo = new BufferObject(BufferTarget.ElementArrayBuffer); - _vao = new ArrayObject(); _vao.Bind(); _vbo.SetData(_batchVertices); @@ -95,12 +96,9 @@ public void SetupRender() GL.BlendEquation(BlendEquationMode.FuncAdd); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); - - GL.Disable(EnableCap.CullFace); + GL.Disable(EnableCap.ScissorTest); - GL.Disable(EnableCap.StencilTest); - GL.Disable(EnableCap.PrimitiveRestart); - + GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); GL.ClearColor(0, 0, 0, 0); @@ -111,9 +109,10 @@ public void Render(WindowHandle window) Clear(); GL.Viewport(window.Size); - - var args = new RenderDrawingEvent(); - _eventBus.Raise(ref args); + GL.Clear(ClearBufferMask.ColorBufferBit); + + var ev = new RenderDrawingEvent(); + _eventBus.Raise(ref ev); // break batch so we get all batches BreakCurrentBatch(); @@ -132,9 +131,10 @@ public void Render(WindowHandle window) _vbo.Unbind(); _ebo.Unbind(); - _windowManager.WindowSwapBuffers(window); + var evUI = new RenderAfterDrawingEvent(); + _eventBus.Raise(ref evUI); - GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); + _windowManager.WindowSwapBuffers(window); } public void Clear() @@ -167,6 +167,7 @@ private void Render(Batch batch) GL.DrawElements(batch.PrimitiveType, batch.Size, DrawElementsType.UnsignedInt, batch.Start * sizeof(uint)); shader.Stop(); + GLHelper.UnbindTexture(TextureTarget.Texture2D); } /// diff --git a/Hypercube.ImGui/Implementations/OpenGLImGuiController.Render.cs b/Hypercube.ImGui/Implementations/OpenGLImGuiController.Render.cs index d9c4713..b4024b3 100644 --- a/Hypercube.ImGui/Implementations/OpenGLImGuiController.Render.cs +++ b/Hypercube.ImGui/Implementations/OpenGLImGuiController.Render.cs @@ -123,6 +123,9 @@ private void Render(ImDrawDataPtr data) _vao.Unbind(); _vbo.Unbind(); _ebo.Unbind(); + + GL.Disable(EnableCap.Blend); + GL.Disable(EnableCap.ScissorTest); } private void SetupRender(ImDrawDataPtr data, Vector2Int frameBufferSize)