diff --git a/.editorconfig b/.editorconfig index 2b613f8..a1ebbcd 100644 --- a/.editorconfig +++ b/.editorconfig @@ -15,6 +15,8 @@ csharp_style_namespace_declarations = file_scoped dotnet_style_allow_multiple_blank_lines_experimental = false csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false +dotnet_analyzer_diagnostic.severity = warning + # don't add _ discards for return values dotnet_diagnostic.IDE0058.severity = none @@ -28,7 +30,6 @@ dotnet_diagnostic.IDE0022.severity = none dotnet_diagnostic.IDE0010.severity = none dotnet_diagnostic.IDE0072.severity = none -dotnet_analyzer_diagnostic.severity = warning dotnet_diagnostic.CA1805.severity = none dotnet_diagnostic.CA1051.severity = none dotnet_diagnostic.CA1001.severity = none diff --git a/addons/imgui-godot/ImGuiGodot/ImGuiLayer.cs b/addons/imgui-godot/ImGuiGodot/ImGuiLayer.cs index d32d5e5..a86fdc3 100644 --- a/addons/imgui-godot/ImGuiGodot/ImGuiLayer.cs +++ b/addons/imgui-godot/ImGuiGodot/ImGuiLayer.cs @@ -2,6 +2,9 @@ using ImGuiNET; using System; using System.Collections.Generic; +#if IMGUI_GODOT_DEV +using System.Runtime.InteropServices; +#endif namespace ImGuiGodot; @@ -111,27 +114,9 @@ public override void _EnterTree() } ImGuiGD.RebuildFontAtlas(); - _subViewportContainer = new SubViewportContainer - { - Name = "ImGuiLayer_SubViewportContainer", - AnchorsPreset = 15, - MouseFilter = Control.MouseFilterEnum.Ignore, - Stretch = true - }; - - _subViewport = new SubViewport - { - Name = "ImGuiLayer_SubViewport", - TransparentBg = true, - HandleInputLocally = false, - GuiDisableInput = true, - RenderTargetUpdateMode = SubViewport.UpdateMode.Always - }; - - _subViewportContainer.AddChild(_subViewport); + Internal.AddLayerSubViewport(this, out _subViewportContainer, out _subViewport); Internal.Renderer.InitViewport(_subViewport); - AddChild(_subViewportContainer); _updateFirst = new UpdateFirst { @@ -230,6 +215,7 @@ public static void Connect(ImGuiLayoutEventHandler d) } #if IMGUI_GODOT_DEV +#pragma warning disable CA1822 // Mark members as static // WIP, this will probably be changed or moved public long[] GetImGuiPtrs(string version, int ioSize, int vertSize, int idxSize) { @@ -255,6 +241,7 @@ public long[] GetImGuiPtrs(string version, int ioSize, int vertSize, int idxSize (long)mem_free }; } +#pragma warning restore CA1822 // Mark members as static #endif private static void OnNodeRemoved(Node node) diff --git a/addons/imgui-godot/ImGuiGodot/Internal.cs b/addons/imgui-godot/ImGuiGodot/Internal.cs index ccb6742..f7a14a4 100644 --- a/addons/imgui-godot/ImGuiGodot/Internal.cs +++ b/addons/imgui-godot/ImGuiGodot/Internal.cs @@ -441,6 +441,29 @@ public static void ProcessNotification(long what) }; } + public static void AddLayerSubViewport(Node parent, out SubViewportContainer subViewportContainer, out SubViewport subViewport) + { + subViewportContainer = new SubViewportContainer + { + Name = "ImGuiLayer_SubViewportContainer", + AnchorsPreset = 15, + MouseFilter = Control.MouseFilterEnum.Ignore, + Stretch = true + }; + + subViewport = new SubViewport + { + Name = "ImGuiLayer_SubViewport", + TransparentBg = true, + HandleInputLocally = false, + GuiDisableInput = true, + RenderTargetUpdateMode = SubViewport.UpdateMode.Always + }; + + subViewportContainer.AddChild(subViewport); + parent.AddChild(subViewportContainer); + } + public static void Render(Viewport vp) { ImGui.Render(); diff --git a/addons/imgui-godot/ImGuiGodot/InternalCanvasRenderer.cs b/addons/imgui-godot/ImGuiGodot/InternalCanvasRenderer.cs index 6cbc817..15a5399 100644 --- a/addons/imgui-godot/ImGuiGodot/InternalCanvasRenderer.cs +++ b/addons/imgui-godot/ImGuiGodot/InternalCanvasRenderer.cs @@ -21,6 +21,9 @@ private class ViewportData public void Init(ImGuiIOPtr io) { io.BackendFlags |= ImGuiBackendFlags.RendererHasVtxOffset; +#if IMGUI_GODOT_DEV + io.BackendFlags |= ImGuiBackendFlags.RendererHasViewports; +#endif } public void InitViewport(Viewport vp) @@ -32,6 +35,8 @@ public void InitViewport(Viewport vp) RenderingServer.ViewportAttachCanvas(vprid, canvas); RenderingServer.CanvasItemSetParent(canvasItem, canvas); + RenderingServer.CanvasItemAddRect(canvasItem, new(0, 0, 32, 32), Colors.Red); + _vpData[vprid] = new ViewportData() { Canvas = canvas, diff --git a/addons/imgui-godot/ImGuiGodot/InternalRdRenderer.cs b/addons/imgui-godot/ImGuiGodot/InternalRdRenderer.cs index cdf4a9a..6bf22e1 100644 --- a/addons/imgui-godot/ImGuiGodot/InternalRdRenderer.cs +++ b/addons/imgui-godot/ImGuiGodot/InternalRdRenderer.cs @@ -48,6 +48,7 @@ public InternalRdRenderer() _shader = RD.ShaderCreateFromSpirv(spirv); #if IMGUI_GODOT_DEV +#pragma warning disable CA2201 using var src = new RDShaderSource() { SourceFragment = _fragmentShaderSource, @@ -58,6 +59,7 @@ public InternalRdRenderer() throw new Exception("fragment bytecode mismatch"); if (!System.Linq.Enumerable.SequenceEqual(spirv.BytecodeVertex, freshSpirv.BytecodeVertex)) throw new Exception("vertex bytecode mismatch"); +#pragma warning restore CA2201 #endif // create vertex format @@ -146,6 +148,9 @@ public InternalRdRenderer() public void Init(ImGuiIOPtr io) { io.BackendFlags |= ImGuiBackendFlags.RendererHasVtxOffset; +#if IMGUI_GODOT_DEV + io.BackendFlags |= ImGuiBackendFlags.RendererHasViewports; +#endif } public void InitViewport(Viewport vp) diff --git a/addons/imgui-godot/ImGuiGodot/InternalViewports.cs b/addons/imgui-godot/ImGuiGodot/InternalViewports.cs index c288197..ab3001d 100644 --- a/addons/imgui-godot/ImGuiGodot/InternalViewports.cs +++ b/addons/imgui-godot/ImGuiGodot/InternalViewports.cs @@ -78,6 +78,7 @@ private class GodotImGuiWindow : IDisposable private bool _focused; public Window GodotWindow { get; init; } + public SubViewport LayerSvp { get; init; } public GodotImGuiWindow(ImGuiViewportPtr vp) { @@ -110,10 +111,11 @@ public GodotImGuiWindow(ImGuiViewportPtr vp) // need to do this after AddChild GodotWindow.Transparent = true; - Internal.Renderer.InitViewport(GodotWindow); - RenderingServer.ViewportSetTransparentBackground(GodotWindow.GetViewportRid(), true); + Internal.AddLayerSubViewport(GodotWindow, out SubViewportContainer svpContainer, out SubViewport svp); + LayerSvp = svp; - //RenderingServer.CanvasItemAddRect(RootCanvasItem, new(0, 0, 100, 100), Colors.Red); + Internal.Renderer.InitViewport(LayerSvp); + RenderingServer.ViewportSetTransparentBackground(GodotWindow.GetViewportRid(), true); } public GodotImGuiWindow(ImGuiViewportPtr vp, Window gw) @@ -128,8 +130,6 @@ public void Dispose() { if (GodotWindow.GetParent() != null) { - //RenderingServer.FreeRid(RootCanvasItem); - //RenderingServer.FreeRid(CanvasRid); GodotWindow.QueueFree(); } _gcHandle.Free(); @@ -238,9 +238,8 @@ private static unsafe void InitPlatformInterface() public static void Init(ImGuiIOPtr io) { io.BackendFlags |= ImGuiBackendFlags.PlatformHasViewports; - io.BackendFlags |= ImGuiBackendFlags.RendererHasViewports; - // io.ConfigFlags |= ImGuiConfigFlags.ViewportsEnable; + io.ConfigFlags |= ImGuiConfigFlags.ViewportsEnable; _mainWindow = new(ImGui.GetMainViewport(), ImGuiLayer.Instance.GetViewport() as Window); @@ -250,7 +249,7 @@ public static void Init(ImGuiIOPtr io) private static void Godot_CreateWindow(ImGuiViewportPtr vp) { - new GodotImGuiWindow(vp); + _ = new GodotImGuiWindow(vp); } private static void Godot_DestroyWindow(ImGuiViewportPtr vp) @@ -324,7 +323,7 @@ public static void RenderViewports() { var vp = pio.Viewports[i]; var window = (GodotImGuiWindow)GCHandle.FromIntPtr(vp.PlatformHandle).Target; - Internal.Renderer.RenderDrawData(window.GodotWindow, vp.DrawData); + Internal.Renderer.RenderDrawData(window.LayerSvp, vp.DrawData); } } } diff --git a/src/MyNode.cs b/src/MyNode.cs index 7f6cd1f..648c8c1 100644 --- a/src/MyNode.cs +++ b/src/MyNode.cs @@ -15,6 +15,14 @@ public override void _Ready() public override void _Process(double delta) { +#if IMGUI_GODOT_DEV + ImGui.SetNextWindowPos(new(100, 100)); + ImGui.SetNextWindowSize(new(200, 200)); + ImGui.Begin("test"); + ImGui.Text("some text"); + ImGui.End(); +#endif + ImGui.ShowDemoWindow(); }