From 283b3304038622454a89c46778deacdf80ce8c8f Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Wed, 26 Aug 2020 17:06:00 -0400 Subject: [PATCH] Workaround for GLES 2.0 hardware --- AUTHORS | 1 + .../OpenRA.Platforms.Default.csproj | 2 +- OpenRA.Platforms.Default/Sdl2PlatformWindow.cs | 12 ++++++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/AUTHORS b/AUTHORS index 65270fcf37..2b98d1eca5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -40,6 +40,7 @@ Also thanks to: * Biofreak * Braxton Williams (Buddytex) * Brendan Gluth (Mechanical_Man) + * Brent Gardner (bggardner) * Bryan Wilbur * Bugra Cuhadaroglu (BugraC) * Chris Cameron (Vesuvian) diff --git a/OpenRA.Platforms.Default/OpenRA.Platforms.Default.csproj b/OpenRA.Platforms.Default/OpenRA.Platforms.Default.csproj index 250e32cd4b..e725d63726 100644 --- a/OpenRA.Platforms.Default/OpenRA.Platforms.Default.csproj +++ b/OpenRA.Platforms.Default/OpenRA.Platforms.Default.csproj @@ -29,7 +29,7 @@ - + diff --git a/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs b/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs index ff93732563..467f60bc10 100644 --- a/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs +++ b/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs @@ -145,8 +145,6 @@ namespace OpenRA.Platforms.Default if (Platform.CurrentPlatform == PlatformType.Windows) SetProcessDPIAware(); - SDL.SDL_Init(SDL.SDL_INIT_NOPARACHUTE | SDL.SDL_INIT_VIDEO); - // Decide which OpenGL profile to use. // We first need to query the available profiles on Windows/Linux. // On macOS, known/consistent OpenGL support is provided by the OS. @@ -161,6 +159,10 @@ namespace OpenRA.Platforms.Default throw new InvalidOperationException("No supported OpenGL profiles were found."); profile = supportedProfiles.Contains(requestProfile) ? requestProfile : supportedProfiles.First(); + + // Note: This must be called after the CanCreateGLWindow checks above, + // which needs to create and destroy its own SDL contexts as a workaround for specific buggy drivers + SDL.SDL_Init(SDL.SDL_INIT_VIDEO); SetSDLAttributes(profile); Console.WriteLine("Using SDL 2 with OpenGL ({0}) renderer", profile); @@ -487,6 +489,9 @@ namespace OpenRA.Platforms.Default static bool CanCreateGLWindow(GLProfile profile) { // Implementation inspired by TestIndividualGLVersion from Veldrid + + // Need to create and destroy its own SDL contexts as a workaround for specific buggy drivers + SDL.SDL_Init(SDL.SDL_INIT_VIDEO); SetSDLAttributes(profile); var flags = SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN | SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL; @@ -494,6 +499,7 @@ namespace OpenRA.Platforms.Default if (window == IntPtr.Zero || !string.IsNullOrEmpty(SDL.SDL_GetError())) { SDL.SDL_ClearError(); + SDL.SDL_Quit(); return false; } @@ -502,11 +508,13 @@ namespace OpenRA.Platforms.Default { SDL.SDL_ClearError(); SDL.SDL_DestroyWindow(window); + SDL.SDL_Quit(); return false; } SDL.SDL_GL_DeleteContext(context); SDL.SDL_DestroyWindow(window); + SDL.SDL_Quit(); return true; }