diff --git a/FDK/src/01.Framework/Core/Game.cs b/FDK/src/01.Framework/Core/Game.cs index f4bebb89..791a12e6 100644 --- a/FDK/src/01.Framework/Core/Game.cs +++ b/FDK/src/01.Framework/Core/Game.cs @@ -152,15 +152,18 @@ namespace SampleFramework } public static int MainThreadID { get; private set; } + + private Vector2D ViewPortSize = new Vector2D(); + private Vector2D ViewPortOffset = new Vector2D(); public unsafe SKBitmap GetScreenShot() { - int ViewportWidth = Window_.FramebufferSize.X; - int ViewportHeight = Window_.FramebufferSize.Y; + int ViewportWidth = ViewPortSize.X; + int ViewportHeight = ViewPortSize.Y; fixed(uint* pixels = new uint[(uint)ViewportWidth * (uint)ViewportHeight]) { Gl.ReadBuffer(GLEnum.Front); - Gl.ReadPixels(0, 0, (uint)ViewportWidth, (uint)ViewportHeight, PixelFormat.Bgra, GLEnum.UnsignedByte, pixels); + Gl.ReadPixels(ViewPortOffset.X, ViewPortOffset.Y, (uint)ViewportWidth, (uint)ViewportHeight, PixelFormat.Bgra, GLEnum.UnsignedByte, pixels); fixed(uint* pixels2 = new uint[(uint)ViewportWidth * (uint)ViewportHeight]) { @@ -184,13 +187,13 @@ namespace SampleFramework public unsafe void GetScreenShotAsync(Action action) { - int ViewportWidth = Window_.FramebufferSize.X; - int ViewportHeight = Window_.FramebufferSize.Y; + int ViewportWidth = ViewPortSize.X; + int ViewportHeight = ViewPortSize.Y; byte[] pixels = new byte[(uint)ViewportWidth * (uint)ViewportHeight * 4]; Gl.ReadBuffer(GLEnum.Front); fixed(byte* pix = pixels) { - Gl.ReadPixels(0, 0, (uint)ViewportWidth, (uint)ViewportHeight, PixelFormat.Bgra, GLEnum.UnsignedByte, pix); + Gl.ReadPixels(ViewPortOffset.X, ViewPortOffset.Y, (uint)ViewportWidth, (uint)ViewportHeight, PixelFormat.Bgra, GLEnum.UnsignedByte, pix); } Task.Run(() =>{ @@ -445,21 +448,27 @@ namespace SampleFramework public void Window_Resize(Vector2D size) { - if (size.X > 0 && size.Y > 0 && Window_.WindowState == WindowState.Normal) + if (size.X > 0 && size.Y > 0) { float resolutionAspect = (float)GameWindowSize.Width / GameWindowSize.Height; - if (WindowSize.X != size.X) + float windowAspect = (float)size.X / size.Y; + if (windowAspect > resolutionAspect) { - size.Y = (int)(size.X / (resolutionAspect)); + ViewPortSize.X = (int)(size.Y * resolutionAspect); + ViewPortSize.Y = size.Y; } else { - size.X = (int)(size.Y * (resolutionAspect)); + ViewPortSize.X = size.X; + ViewPortSize.Y = (int)(size.X / resolutionAspect); } } + ViewPortOffset.X = (size.X - ViewPortSize.X) / 2; + ViewPortOffset.Y = (size.Y - ViewPortSize.Y) / 2; + WindowSize = size; - Gl.Viewport(0, 0, (uint)size.X, (uint)size.Y); + Gl.Viewport(ViewPortOffset.X, ViewPortOffset.Y, (uint)ViewPortSize.X, (uint)ViewPortSize.Y); } public void Window_Move(Vector2D size) diff --git a/FDK/src/01.Framework/Rendering/Angle/AngleContext.cs b/FDK/src/01.Framework/Rendering/Angle/AngleContext.cs index 75db174a..6c61bb55 100644 --- a/FDK/src/01.Framework/Rendering/Angle/AngleContext.cs +++ b/FDK/src/01.Framework/Rendering/Angle/AngleContext.cs @@ -16,21 +16,26 @@ public class AngleContext : IGLContext { nint windowHandle; nint display; - if (OperatingSystem.IsWindows()) + if (window.Native.Kind.HasFlag(NativeWindowFlags.Win32)) { windowHandle = window.Native.Win32.Value.Hwnd; display = window.Native.Win32.Value.HDC; } - else if (OperatingSystem.IsLinux()) + else if (window.Native.Kind.HasFlag(NativeWindowFlags.X11)) { windowHandle = (nint)window.Native.X11.Value.Window; - display = window.Native.X11.Value.Display; + display = Egl.GetDisplay(window.Native.X11.Value.Display); } - else if (OperatingSystem.IsMacOS()) + else if (window.Native.Kind.HasFlag(NativeWindowFlags.Cocoa)) { windowHandle = window.Native.Cocoa.Value; display = 0; } + else if (window.Native.Kind.HasFlag(NativeWindowFlags.Wayland)) + { + windowHandle = window.Native.Wayland.Value.Surface; + display = window.Native.Wayland.Value.Display; + } else { throw new Exception("Window not found"); @@ -98,7 +103,8 @@ public class AngleContext : IGLContext Egl.NONE }; - Surface = Egl.CreatePlatformWindowSurfaceEXT(Display, configs[0], windowHandle, null); + //Surface = Egl.CreatePlatformWindowSurfaceEXT(Display, configs[0], windowHandle, null); + Surface = Egl.CreateWindowSurface(Display, configs[0], windowHandle, 0); var error1 = Egl.GetError(); }