1
0
mirror of synced 2024-11-27 17:00:50 +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; }
private Vector2D<int> ViewPortSize = new Vector2D<int>();
private Vector2D<int> ViewPortOffset = new Vector2D<int>();
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<SKBitmap> 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<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;
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<int> size)

View File

@ -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();
}