1
0
mirror of synced 2024-11-30 18:24:32 +01:00

Linuxの起動できない問題を修正2 (#531)

This commit is contained in:
Takkkom 2023-11-23 11:04:07 +09:00 committed by GitHub
parent eeefec366b
commit cfdf0d42f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 16 deletions

View File

@ -152,15 +152,18 @@ namespace SampleFramework
} }
public static int MainThreadID { get; private set; } public static int MainThreadID { get; private set; }
private Vector2D<int> ViewPortSize = new Vector2D<int>();
private Vector2D<int> ViewPortOffset = new Vector2D<int>();
public unsafe SKBitmap GetScreenShot() public unsafe SKBitmap GetScreenShot()
{ {
int ViewportWidth = Window_.FramebufferSize.X; int ViewportWidth = ViewPortSize.X;
int ViewportHeight = Window_.FramebufferSize.Y; int ViewportHeight = ViewPortSize.Y;
fixed(uint* pixels = new uint[(uint)ViewportWidth * (uint)ViewportHeight]) fixed(uint* pixels = new uint[(uint)ViewportWidth * (uint)ViewportHeight])
{ {
Gl.ReadBuffer(GLEnum.Front); 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]) fixed(uint* pixels2 = new uint[(uint)ViewportWidth * (uint)ViewportHeight])
{ {
@ -184,13 +187,13 @@ namespace SampleFramework
public unsafe void GetScreenShotAsync(Action<SKBitmap> action) public unsafe void GetScreenShotAsync(Action<SKBitmap> action)
{ {
int ViewportWidth = Window_.FramebufferSize.X; int ViewportWidth = ViewPortSize.X;
int ViewportHeight = Window_.FramebufferSize.Y; int ViewportHeight = ViewPortSize.Y;
byte[] pixels = new byte[(uint)ViewportWidth * (uint)ViewportHeight * 4]; byte[] pixels = new byte[(uint)ViewportWidth * (uint)ViewportHeight * 4];
Gl.ReadBuffer(GLEnum.Front); Gl.ReadBuffer(GLEnum.Front);
fixed(byte* pix = pixels) 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(() =>{ Task.Run(() =>{
@ -445,21 +448,27 @@ namespace SampleFramework
public void Window_Resize(Vector2D<int> size) public void Window_Resize(Vector2D<int> 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; 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 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; 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<int> size) public void Window_Move(Vector2D<int> size)

View File

@ -16,21 +16,26 @@ public class AngleContext : IGLContext
{ {
nint windowHandle; nint windowHandle;
nint display; nint display;
if (OperatingSystem.IsWindows()) if (window.Native.Kind.HasFlag(NativeWindowFlags.Win32))
{ {
windowHandle = window.Native.Win32.Value.Hwnd; windowHandle = window.Native.Win32.Value.Hwnd;
display = window.Native.Win32.Value.HDC; 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; 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; windowHandle = window.Native.Cocoa.Value;
display = 0; display = 0;
} }
else if (window.Native.Kind.HasFlag(NativeWindowFlags.Wayland))
{
windowHandle = window.Native.Wayland.Value.Surface;
display = window.Native.Wayland.Value.Display;
}
else else
{ {
throw new Exception("Window not found"); throw new Exception("Window not found");
@ -98,7 +103,8 @@ public class AngleContext : IGLContext
Egl.NONE 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(); var error1 = Egl.GetError();
} }