diff --git a/GlitchyEngine/src/ImGui/ImGuiLayer.bf b/GlitchyEngine/src/ImGui/ImGuiLayer.bf index 09840e1..f6644e3 100644 --- a/GlitchyEngine/src/ImGui/ImGuiLayer.bf +++ b/GlitchyEngine/src/ImGui/ImGuiLayer.bf @@ -8,6 +8,7 @@ using internal ImGui; #if GE_GRAPHICS_DX11 using GlitchyEngine.Platform.DX11; +using GlitchyEngine.Renderer; using internal GlitchyEngine.Platform.DX11; #endif @@ -16,6 +17,8 @@ namespace GlitchyEngine.ImGui { public class ImGuiLayer : Layer { + ImGui.IO* _io; + public this() : base("ImGuiLayer") { } public override void OnAttach() @@ -29,10 +32,10 @@ namespace GlitchyEngine.ImGui ImGui.CreateContext(); ImGui.StyleColorsDark(); - ImGui.IO* io = ImGui.GetIO(); - io.ConfigFlags |= .NavEnableKeyboard; - io.ConfigFlags |= .DockingEnable; - io.ConfigFlags |= .ViewportsEnable; + _io = ImGui.GetIO(); + _io.ConfigFlags |= .NavEnableKeyboard; + _io.ConfigFlags |= .DockingEnable; + _io.ConfigFlags |= .ViewportsEnable; // Todo: currently broken in ImGui //io.ConfigFlags |= .DpiEnableScaleFonts; @@ -40,15 +43,14 @@ namespace GlitchyEngine.ImGui // When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones. ImGui.Style* style = ImGui.GetStyle(); - if(io.ConfigFlags.HasFlag(.ViewportsEnable)) + if(_io.ConfigFlags.HasFlag(.ViewportsEnable)) { style.WindowRounding = 0.0f; style.Colors[(int)ImGui.Col.WindowBg].w = 1.0f; } #if BF_PLATFORM_WINDOWS - // Todo: temporary, needs to be platform independent - ImGuiImplWin32.Init((void*)(uint)(Windows.HWnd)(int)Application.Get().Window.NativeWindow); + ImGuiImplWin32.Init(Application.Get().Window.NativeWindow); #endif #if GE_GRAPHICS_DX11 @@ -59,149 +61,28 @@ namespace GlitchyEngine.ImGui public override void OnDetach() { Debug.Profiler.ProfileFunction!(); - + +#if GE_GRAPHICS_DX11 ImGuiImplDX11.Shutdown(); +#endif + +#if BF_PLATFORM_WINDOWS ImGuiImplWin32.Shutdown(); +#endif + ImGui.DestroyContext(); } - public override void OnEvent(Event event) - { - /* - EventDispatcher dispatcher = scope EventDispatcher(event); - - dispatcher.Dispatch(scope (e) => - { - //ref ImGui.IO io = ref ImGui.GetIO(); - //io.DisplaySize = .(e.Width, e.Height); - //io.DisplayFramebufferScale = .(1.0f, 1.0f); - - return false; - }); - - dispatcher.Dispatch(scope (e) => - { - ref ImGui.IO io = ref ImGui.GetIO(); - io.MousePos = ImGui.Vec2(e.PositionX, e.PositionY); - - return false; - }); - - dispatcher.Dispatch(scope (e) => - { - int button = 0; - switch(e.MouseButton) - { - case .LeftButton: - button = (uint)ImGui.MouseButton.Left; - case .RightButton: - button = (uint)ImGui.MouseButton.Right; - case .MiddleButton: - button = (uint)ImGui.MouseButton.Middle; - case .XButton1: - button = (uint)3; - case .XButton2: - button = (uint)4; - default: - } - - ref ImGui.IO io = ref ImGui.GetIO(); - io.MouseDown[button] = true; - - return false; - }); - - dispatcher.Dispatch(scope (e) => - { - int button = 0; - switch(e.MouseButton) - { - case .LeftButton: - button = (uint)ImGui.MouseButton.Left; - case .RightButton: - button = (uint)ImGui.MouseButton.Right; - case .MiddleButton: - button = (uint)ImGui.MouseButton.Middle; - case .XButton1: - button = (uint)3; - case .XButton2: - button = (uint)4; - default: - } - - ref ImGui.IO io = ref ImGui.GetIO(); - io.MouseDown[button] = false; - - return false; - }); - - dispatcher.Dispatch(scope (e) => - { - ref ImGui.IO io = ref ImGui.GetIO(); - io.MouseWheel += e.YOffset; - io.MouseWheelH += e.XOffset; // Todo: horizontal mousewheel inverted?! - - return false; - }); - - dispatcher.Dispatch(scope (e) => - { - if(e.KeyCode >= (.)256) - return false; - - ref ImGui.IO io = ref ImGui.GetIO(); - io.KeysDown[(int32)e.KeyCode] = true; - - io.KeyCtrl = io.KeysDown[(int32)Key.Control]; - io.KeyShift = io.KeysDown[(int32)Key.Shift]; - io.KeyAlt = io.KeysDown[(int32)Key.Alt]; - io.KeySuper = io.KeysDown[(int32)Key.LeftSuper] || io.KeysDown[(int32)Key.RightSuper]; - - return false; - }); - - dispatcher.Dispatch(scope (e) => - { - if(e.KeyCode >= (.)256) - return false; - - ref ImGui.IO io = ref ImGui.GetIO(); - io.KeysDown[(int32)e.KeyCode] = false; - - io.KeyCtrl = io.KeysDown[(int32)Key.Control]; - io.KeyShift = io.KeysDown[(int32)Key.Shift]; - io.KeyAlt = io.KeysDown[(int32)Key.Alt]; - io.KeySuper = io.KeysDown[(int32)Key.LeftSuper] || io.KeysDown[(int32)Key.RightSuper]; - - return false; - }); - - dispatcher.Dispatch(scope (e) => - { - ref ImGui.IO io = ref ImGui.GetIO(); - io.AddInputCharacterUTF16((uint16)e.Char); - - return false; - }); - */ - } - public void Begin() { Debug.Profiler.ProfileFunction!(); - // Todo: - //var v = DirectX.ImmediateContext; - //v.OutputMerger.SetRenderTargets(1, &DirectX.BackBufferTarget, null); - Application.Get().Window.Context.SetRenderTarget(null); - ImGuiImplDX11.NewFrame(); ImGuiImplWin32.NewFrame(); ImGui.NewFrame(); ImGuizmo.BeginFrame(); } - bool showDemo = true; public void ImGuiRender() { Debug.Profiler.ProfileFunction!(); @@ -214,7 +95,6 @@ namespace GlitchyEngine.ImGui var event = scope ImGuiRenderEvent(); Application.Get().OnEvent(event); } - //ImGui.ShowDemoWindow(&showDemo); End(); } @@ -223,20 +103,19 @@ namespace GlitchyEngine.ImGui { Debug.Profiler.ProfileFunction!(); - ImGui.IO* io = ImGui.GetIO(); - - let window = Application.Get().Window; - io.DisplaySize = .(window.Width, window.Height); - ImGui.Render(); + + RenderCommand.SetDepthStencilTarget(null); + RenderCommand.SetRenderTarget(null); + RenderCommand.BindRenderTargets(); #if GE_GRAPHICS_DX11 ImGuiImplDX11.RenderDrawData(ImGui.GetDrawData()); #endif ImGui.CleanupFrame(); - - if(io.ConfigFlags.HasFlag(.ViewportsEnable)) + + if(_io.ConfigFlags.HasFlag(.ViewportsEnable)) { ImGui.UpdatePlatformWindows(); ImGui.RenderPlatformWindowsDefault();