Undo previous commits, try setting glx depth explicitly (probably isn't what's needed? maybe it is? ehhh)
TODO: this seems to be an issue anyways with buggy nvidia drivers under xwayland, perhaps that setup can be detected and forced over to GDI+?
This commit is contained in:
parent
516a021add
commit
f18c2467de
|
@ -6,32 +6,6 @@ namespace BizHawk.Bizware.Graphics.Controls
|
|||
{
|
||||
internal sealed class OpenGLControl : GraphicsControl
|
||||
{
|
||||
// workaround a bug with proprietary Nvidia drivers resulting in some BadMatch on setting context to current
|
||||
// seems they don't like whatever depth values mono's winforms ends up setting
|
||||
// mono's winforms seems to try to copy from the "parent" window, so we need to create a "friendly" window
|
||||
private static readonly Lazy<IntPtr> _x11GLParent = new(() =>
|
||||
{
|
||||
// ugh, i hate this, seems just returning an x11 window handle is not good enough (unlike on windows where handing some native HWND is good enough)
|
||||
// instead it has to have been created with mono's internal "Hwnd" class
|
||||
var hwnd = typeof(Control).Assembly.CreateInstance("System.Windows.Forms.Hwnd");
|
||||
if (hwnd == null)
|
||||
{
|
||||
Console.WriteLine("Couldn't find System.Windows.Forms.Hwnd");
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
var clientWindowProp = hwnd.GetType().GetProperty("ClientWindow");
|
||||
if (clientWindowProp == null)
|
||||
{
|
||||
Console.WriteLine("Couldn't find ClientWindow prop");
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
var x11Window = SDL2OpenGLContext.CreateDummyX11ParentWindow(3, 2, true);
|
||||
clientWindowProp.SetValue(hwnd, x11Window);
|
||||
return x11Window;
|
||||
});
|
||||
|
||||
private readonly Action _initGLState;
|
||||
private SDL2OpenGLContext _context;
|
||||
|
||||
|
@ -61,11 +35,6 @@ namespace BizHawk.Bizware.Graphics.Controls
|
|||
// According to OpenTK, this is necessary for OpenGL on windows
|
||||
cp.ClassStyle |= CS_VREDRAW | CS_HREDRAW | CS_OWNDC;
|
||||
}
|
||||
else
|
||||
{
|
||||
// workaround buggy proprietary Nvidia drivers
|
||||
cp.Parent = _x11GLParent.Value;
|
||||
}
|
||||
|
||||
return cp;
|
||||
}
|
||||
|
@ -81,7 +50,7 @@ namespace BizHawk.Bizware.Graphics.Controls
|
|||
protected override void OnHandleDestroyed(EventArgs e)
|
||||
{
|
||||
base.OnHandleDestroyed(e);
|
||||
_context.Dispose();
|
||||
_context?.Dispose();
|
||||
_context = null;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ using System.Runtime.InteropServices;
|
|||
using Silk.NET.OpenGL;
|
||||
#endif
|
||||
|
||||
using BizHawk.Common;
|
||||
using static SDL2.SDL;
|
||||
|
||||
namespace BizHawk.Bizware.Graphics
|
||||
|
@ -46,39 +45,6 @@ namespace BizHawk.Bizware.Graphics
|
|||
private IntPtr _sdlWindow;
|
||||
private IntPtr _glContext;
|
||||
|
||||
// helper function for OpenGLControl
|
||||
public static IntPtr CreateDummyX11ParentWindow(int majorVersion, int minorVersion, bool coreProfile)
|
||||
{
|
||||
if (!OSTailoredCode.IsUnixHost)
|
||||
{
|
||||
throw new NotSupportedException("This function should only be called on Linux");
|
||||
}
|
||||
|
||||
SetAttributes(majorVersion, minorVersion, coreProfile, shareContext: false);
|
||||
var sdlWindow = SDL_CreateWindow(null, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1, 1,
|
||||
SDL_WindowFlags.SDL_WINDOW_OPENGL | SDL_WindowFlags.SDL_WINDOW_HIDDEN);
|
||||
if (sdlWindow == IntPtr.Zero)
|
||||
{
|
||||
throw new($"Could not create SDL Window! SDL Error: {SDL_GetError()}");
|
||||
}
|
||||
|
||||
var wmInfo = default(SDL_SysWMinfo);
|
||||
SDL_GetVersion(out wmInfo.version);
|
||||
if (SDL_GetWindowWMInfo(sdlWindow, ref wmInfo) == SDL_bool.SDL_FALSE)
|
||||
{
|
||||
SDL_DestroyWindow(sdlWindow);
|
||||
throw new($"Failed to obtain SDL window info! SDL error: {SDL_GetError()}");
|
||||
}
|
||||
|
||||
if (wmInfo.subsystem != SDL_SYSWM_TYPE.SDL_SYSWM_X11)
|
||||
{
|
||||
SDL_DestroyWindow(sdlWindow);
|
||||
throw new("Subsystem is not X11!");
|
||||
}
|
||||
|
||||
return wmInfo.info.x11.window;
|
||||
}
|
||||
|
||||
private static void SetAttributes(int majorVersion, int minorVersion, bool coreProfile, bool shareContext)
|
||||
{
|
||||
// set some sensible defaults
|
||||
|
@ -87,6 +53,7 @@ namespace BizHawk.Bizware.Graphics
|
|||
|| SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_GREEN_SIZE, 8) is not 0
|
||||
|| SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_BLUE_SIZE, 8) is not 0
|
||||
|| SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_ALPHA_SIZE, 0) is not 0
|
||||
|| SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_DEPTH_SIZE, 24) is not 0
|
||||
|| SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1) is not 0)
|
||||
{
|
||||
throw new($"Could not set GL attributes! SDL Error: {SDL_GetError()}");
|
||||
|
|
Loading…
Reference in New Issue