diff --git a/OpenRA.Platforms.Default/ErrorHandler.cs b/OpenRA.Platforms.Default/ErrorHandler.cs index 10b0e5e764..6b0d5afa48 100644 --- a/OpenRA.Platforms.Default/ErrorHandler.cs +++ b/OpenRA.Platforms.Default/ErrorHandler.cs @@ -15,27 +15,6 @@ namespace OpenRA.Platforms.Default { static class ErrorHandler { - public static void CheckGlVersion() - { - var versionString = OpenGL.glGetString(OpenGL.GL_VERSION); - var version = versionString.Contains(" ") ? versionString.Split(' ')[0].Split('.') : versionString.Split('.'); - - var major = 0; - if (version.Length > 0) - int.TryParse(version[0], out major); - - var minor = 0; - if (version.Length > 1) - int.TryParse(version[1], out minor); - - Console.WriteLine("Detected OpenGL version: {0}.{1}".F(major, minor)); - if (major < 2) - { - OpenGL.WriteGraphicsLog("OpenRA requires OpenGL version 2.0 or greater and detected {0}.{1}".F(major, minor)); - throw new InvalidProgramException("OpenGL Version Error: See graphics.log for details."); - } - } - public static void CheckGlError() { var n = OpenGL.glGetError(); diff --git a/OpenRA.Platforms.Default/OpenGL.cs b/OpenRA.Platforms.Default/OpenGL.cs index 43edffbc7e..ffb5a38d9e 100644 --- a/OpenRA.Platforms.Default/OpenGL.cs +++ b/OpenRA.Platforms.Default/OpenGL.cs @@ -335,8 +335,17 @@ namespace OpenRA.Platforms.Default public delegate int CheckFramebufferStatus(int target); public static CheckFramebufferStatus glCheckFramebufferStatus { get; private set; } - public static void LoadDelegates() + public static void Initialize() { + CheckGlVersion(); + + if (SDL.SDL_GL_ExtensionSupported("GL_EXT_framebuffer_object") == SDL.SDL_bool.SDL_FALSE) + { + OpenGL.WriteGraphicsLog("OpenRA requires the OpenGL extension GL_EXT_framebuffer_object.\n" + + "Please try updating your GPU driver to the latest version provided by the manufacturer."); + throw new InvalidProgramException("Missing OpenGL extension GL_EXT_framebuffer_object. See graphics.log for details."); + } + glFlush = Bind("glFlush"); glViewport = Bind("glViewport"); glClear = Bind("glClear"); @@ -410,6 +419,29 @@ namespace OpenRA.Platforms.Default return (T)(object)Marshal.GetDelegateForFunctionPointer(SDL.SDL_GL_GetProcAddress(name), typeof(T)); } + static void CheckGlVersion() + { + var versionString = OpenGL.glGetString(OpenGL.GL_VERSION); + var version = versionString.Contains(" ") ? versionString.Split(' ')[0].Split('.') : versionString.Split('.'); + + var major = 0; + if (version.Length > 0) + int.TryParse(version[0], out major); + + var minor = 0; + if (version.Length > 1) + int.TryParse(version[1], out minor); + + Console.WriteLine("Detected OpenGL version: {0}.{1}".F(major, minor)); + if (major < 2) + { + OpenGL.WriteGraphicsLog("OpenRA requires OpenGL version 2.0 or greater and detected {0}.{1}".F(major, minor)); + throw new InvalidProgramException("OpenGL Version Error: See graphics.log for details."); + } + + ErrorHandler.CheckGlError(); + } + public static void WriteGraphicsLog(string message) { Log.Write("graphics", message); diff --git a/OpenRA.Platforms.Default/Sdl2GraphicsDevice.cs b/OpenRA.Platforms.Default/Sdl2GraphicsDevice.cs index 0577a6587d..858aa0c0c2 100644 --- a/OpenRA.Platforms.Default/Sdl2GraphicsDevice.cs +++ b/OpenRA.Platforms.Default/Sdl2GraphicsDevice.cs @@ -76,16 +76,7 @@ namespace OpenRA.Platforms.Default if (context == IntPtr.Zero || SDL.SDL_GL_MakeCurrent(window, context) < 0) throw new InvalidOperationException("Can not create OpenGL context. (Error: {0})".F(SDL.SDL_GetError())); - OpenGL.LoadDelegates(); - ErrorHandler.CheckGlVersion(); - ErrorHandler.CheckGlError(); - - if (SDL.SDL_GL_ExtensionSupported("GL_EXT_framebuffer_object") == SDL.SDL_bool.SDL_FALSE) - { - OpenGL.WriteGraphicsLog("OpenRA requires the OpenGL extension GL_EXT_framebuffer_object.\n" - + "Please try updating your GPU driver to the latest version provided by the manufacturer."); - throw new InvalidProgramException("Missing OpenGL extension GL_EXT_framebuffer_object. See graphics.log for details."); - } + OpenGL.Initialize(); OpenGL.glEnableVertexAttribArray(Shader.VertexPosAttributeIndex); ErrorHandler.CheckGlError();