Move OpenGL context creation to the main thread.

This commit is contained in:
Paul Chote
2021-09-20 20:39:17 +01:00
committed by Matthias Mailänder
parent f08a0b113e
commit be8e2cf3a4

View File

@@ -25,15 +25,20 @@ namespace OpenRA.Platforms.Default
public Sdl2GraphicsContext(Sdl2PlatformWindow window)
{
this.window = window;
// SDL requires us to create the GL context on the main thread to avoid various platform-specific issues.
// We must then release it from the main thread before we rebind it to the render thread (in InitializeOpenGL below).
context = SDL.SDL_GL_CreateContext(window.Window);
if (context == IntPtr.Zero || SDL.SDL_GL_MakeCurrent(window.Window, IntPtr.Zero) < 0)
throw new InvalidOperationException($"Can not create OpenGL context. (Error: {SDL.SDL_GetError()})");
}
internal void InitializeOpenGL()
{
SetThreadAffinity();
context = SDL.SDL_GL_CreateContext(window.Window);
if (context == IntPtr.Zero || SDL.SDL_GL_MakeCurrent(window.Window, context) < 0)
throw new InvalidOperationException($"Can not create OpenGL context. (Error: {SDL.SDL_GetError()})");
if (SDL.SDL_GL_MakeCurrent(window.Window, context) < 0)
throw new InvalidOperationException($"Can not bind OpenGL context. (Error: {SDL.SDL_GetError()})");
OpenGL.Initialize(window.GLProfile == GLProfile.Legacy);
OpenGL.CheckGLError();