Fix viewports

This commit is contained in:
max 2024-07-12 16:38:42 +02:00
parent d8b41b0827
commit 9890026656

View File

@ -6,16 +6,16 @@ namespace Nerfed.Runtime.Gui
{ {
internal class GuiViewportWindow internal class GuiViewportWindow
{ {
public Window Window => window;
private readonly GCHandle gcHandle; private readonly GCHandle gcHandle;
private readonly GraphicsDevice gd; private readonly GraphicsDevice graphicsDevice;
private readonly ImGuiViewportPtr vp; private readonly ImGuiViewportPtr vp;
private readonly Window window; private readonly Window window;
public Window Window => window; public GuiViewportWindow(GraphicsDevice graphicsDevice, ImGuiViewportPtr vp, Window window)
public GuiViewportWindow(GraphicsDevice gd, ImGuiViewportPtr vp, Window window)
{ {
this.gd = gd; this.graphicsDevice = graphicsDevice;
this.vp = vp; this.vp = vp;
this.window = window; this.window = window;
@ -23,15 +23,15 @@ public GuiViewportWindow(GraphicsDevice gd, ImGuiViewportPtr vp, Window window)
if (!window.Claimed) if (!window.Claimed)
{ {
gd.ClaimWindow(window, SwapchainComposition.SDR, PresentMode.Immediate); // What PresentMode do we need? graphicsDevice.ClaimWindow(window, SwapchainComposition.SDR, PresentMode.Immediate); // What PresentMode do we need?
} }
vp.PlatformUserData = (IntPtr)gcHandle; vp.PlatformUserData = (IntPtr)gcHandle;
} }
public GuiViewportWindow(GraphicsDevice gd, ImGuiViewportPtr vp) public GuiViewportWindow(GraphicsDevice graphicsDevice, ImGuiViewportPtr vp)
{ {
this.gd = gd; this.graphicsDevice = graphicsDevice;
this.vp = vp; this.vp = vp;
gcHandle = GCHandle.Alloc(this); gcHandle = GCHandle.Alloc(this);
@ -48,8 +48,8 @@ public GuiViewportWindow(GraphicsDevice gd, ImGuiViewportPtr vp)
WindowCreateInfo info = new WindowCreateInfo("Window Title", (uint)vp.Pos.X, (uint)vp.Pos.Y, screenMode, systemResizable, false); WindowCreateInfo info = new WindowCreateInfo("Window Title", (uint)vp.Pos.X, (uint)vp.Pos.Y, screenMode, systemResizable, false);
window = new Window(gd, info); window = new Window(graphicsDevice, info);
gd.ClaimWindow(window, SwapchainComposition.SDR, PresentMode.Immediate); // What PresentMode do we need? graphicsDevice.ClaimWindow(window, SwapchainComposition.SDR, PresentMode.Immediate); // What PresentMode do we need?
window.OnMovedEvent += HandleOnMovedEvent; window.OnMovedEvent += HandleOnMovedEvent;
window.OnResizedEvent += HandleOnResizedEvent; window.OnResizedEvent += HandleOnResizedEvent;
@ -64,7 +64,7 @@ public void Dispose()
window.OnResizedEvent -= HandleOnResizedEvent; window.OnResizedEvent -= HandleOnResizedEvent;
window.OnCloseEvent -= HandleOnCloseEvent; window.OnCloseEvent -= HandleOnCloseEvent;
gd.UnclaimWindow(window); graphicsDevice.UnclaimWindow(window);
window.Dispose(); window.Dispose();
gcHandle.Free(); gcHandle.Free();
} }