using Silk.NET.Input; using Silk.NET.OpenGL; using Silk.NET.OpenGL.Extensions.ImGui; using Silk.NET.Windowing; namespace AcDream.UI.ImGui; /// /// Owns the ImGuiController from Silk.NET.OpenGL.Extensions.ImGui, /// which handles the whole Silk.NET ↔ ImGui.NET integration: /// /// Creates the ImGui context + OpenGL3 backend using Silk.NET's GL binding /// (no GLFW / SDL dependency — unlike Hexa.NET.ImGui, which assumed one). /// Subscribes to Silk.NET's window + input events to drive IO. /// Per frame: Update(dt) calls ImGui.NewFrame(); Render() /// calls ImGui.Render() + uploads draw data via its OpenGL3 backend. /// /// /// /// Instance-scoped rather than static so GL-context lifetime is explicit. /// GameWindow owns the one instance and disposes on shutdown. /// /// /// /// History: tried Hexa.NET.ImGui + Hexa.NET.ImGui.Backends.OpenGL3 first /// per the original plan, but its native OpenGL3 backend resolves GL functions /// via GLFW / SDL internally and crashed (0xC0000005) in InitNative without /// one of those present. Pivoted to the official Silk.NET extension on 2026-04-25. /// /// public sealed class ImGuiBootstrapper : IDisposable { private readonly ImGuiController _controller; public ImGuiBootstrapper(GL gl, IView window, IInputContext input) { ArgumentNullException.ThrowIfNull(gl); ArgumentNullException.ThrowIfNull(window); ArgumentNullException.ThrowIfNull(input); // ImGuiController constructor handles: // - ImGui.CreateContext() // - ImGuiOpenGL3 shader + vertex-buffer init (via Silk.NET GL) // - Keyboard + mouse event subscription (bound to Silk.NET IInputContext) // - Default style = dark _controller = new ImGuiController(gl, window, input); } /// /// Begin an ImGui frame. Call BEFORE any ImGui.* widget calls. /// Internally: consumes buffered input events, calls ImGui.NewFrame(). /// public void BeginFrame(float deltaSeconds) => _controller.Update(deltaSeconds); /// /// Finalise the ImGui frame and draw to the framebuffer. Call AFTER all /// panel draws, within the same frame as . The /// OpenGL3 backend save/restores the GL state it touches (shader, VAO, /// texture, blend, scissor); state not in its save-list (e.g. /// GL_FRAMEBUFFER_SRGB) is caller's responsibility. /// public void Render() => _controller.Render(); public void Dispose() => _controller.Dispose(); }