Skip to content

Commit

Permalink
Fix overlay overlapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Tornado-Technology committed Aug 17, 2024
1 parent dbc3d97 commit c4405f9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
5 changes: 5 additions & 0 deletions Hypercube.Client/Graphics/Events/RenderAfterDrawingEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Hypercube.EventBus.Events;

namespace Hypercube.Client.Graphics.Events;

public readonly record struct RenderAfterDrawingEvent : IEventArgs;
4 changes: 2 additions & 2 deletions Hypercube.Client/Graphics/ImGui/ImGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void PostInject()

_eventBus.Subscribe<InputFrameEvent>(this, OnInputFrame);
_eventBus.Subscribe<UpdateFrameEvent>(this, OnUpdateFrame);
_eventBus.Subscribe<RenderFrameEvent>(this, OnRenderFrame);
_eventBus.Subscribe<RenderAfterDrawingEvent>(this, OnRenderUI);

_eventBus.Subscribe<MouseButtonHandledEvent>(this, OnMouseButton);
_eventBus.Subscribe<MousePositionHandledEvent>(this, OnMousePosition);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -43,9 +44,9 @@ private void OnLoad()
_texturingShaderProgram = _resourceContainer.GetResource<ShaderSourceResource>("/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);
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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()
Expand Down Expand Up @@ -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);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c4405f9

Please sign in to comment.