This commit is contained in:
2026-05-20 11:29:55 -05:00
parent 7d5f242a43
commit 5c17e233bc
4 changed files with 149 additions and 55 deletions
+21 -16
View File
@@ -22,6 +22,7 @@ public sealed unsafe class SDL3Window : IDisposable
}
public event Action? RenderCallback;
public event Action? Disposing;
private ImGuiContextPtr _imGuiContext;
private ImPlotContextPtr _imPlotContext;
@@ -31,7 +32,7 @@ public sealed unsafe class SDL3Window : IDisposable
private readonly FileSystemWatcher? _watcher;
private readonly GL _gl;
public readonly GL GL;
public SDL3Window(string name, int posX, int posY, int width, int height, SDL.WindowFlags flags = SDL.WindowFlags.Resizable | SDL.WindowFlags.HighPixelDensity)
{
@@ -116,11 +117,11 @@ public sealed unsafe class SDL3Window : IDisposable
Console.WriteLine(e);
}
_gl = new GL(new BindingsContext(Window, glContext));
GL = new GL(new BindingsContext(Window, glContext));
// Init platform and renderer
ImGuiSDL3Platform.Init(_gl, Window, glContext);
ImGuiSDL3Renderer.Init(_gl, "#version 330");
ImGuiSDL3Platform.Init(GL, Window, glContext);
ImGuiSDL3Renderer.Init(GL, "#version 330");
}
public bool ShouldClose;
@@ -130,11 +131,6 @@ public sealed unsafe class SDL3Window : IDisposable
while (!_disposed)
{
SDL.PumpEvents();
if (ImGui.GetIO().WantTextInput && !SDL.TextInputActive(Window))
SDL.StartTextInput(Window);
else if (!ImGui.GetIO().WantTextInput && SDL.TextInputActive(Window))
SDL.StopTextInput(Window);
while (SDL.PollEvent(out SDL.Event ev))
{
@@ -149,10 +145,16 @@ public sealed unsafe class SDL3Window : IDisposable
break;
}
}
if (SDL.GetWindowFlags(Window).HasFlag(SDL.WindowFlags.Minimized))
{
SDL.Delay(10);
continue;
}
_gl.MakeCurrent();
_gl.ClearColor(ClearColor.X, ClearColor.Y, ClearColor.Z, ClearColor.W);
_gl.Clear(GLClearBufferMask.ColorBufferBit);
GL.MakeCurrent();
GL.ClearColor(ClearColor.X, ClearColor.Y, ClearColor.Z, ClearColor.W);
GL.Clear(GLClearBufferMask.ColorBufferBit);
ImGuiSDL3Platform.NewFrame();
ImGuiSDL3Renderer.NewFrame();
@@ -164,7 +166,7 @@ public sealed unsafe class SDL3Window : IDisposable
ImGui.Render();
_gl.MakeCurrent();
GL.MakeCurrent();
ImGuiSDL3Renderer.RenderDrawData(ImGui.GetDrawData());
@@ -174,8 +176,8 @@ public sealed unsafe class SDL3Window : IDisposable
ImGui.RenderPlatformWindowsDefault();
}
_gl.MakeCurrent();
_gl.SwapBuffers();
GL.MakeCurrent();
GL.SwapBuffers();
if (ShouldClose)
{
@@ -215,10 +217,13 @@ public sealed unsafe class SDL3Window : IDisposable
ImPlot.SetCurrentContext(_imPlotContext);
}
Disposing?.Invoke();
ImGuiSDL3Renderer.Dispose();
ImGuiSDL3Platform.Dispose();
RenderCallback = null;
Disposing = null;
}
if (_imGuiContext.Handle != null)
@@ -294,4 +299,4 @@ public unsafe class BindingsContext : IGLContext
procAddress = (nint)SDL.GLGetProcAddress(procName).GetPtrForDelegate();
return procAddress != 0;
}
}
}