Move CheckGlVersion to OpenGL.

This commit is contained in:
Paul Chote
2015-12-28 10:59:43 +00:00
parent d96a32a89f
commit 4372ed650e
3 changed files with 34 additions and 32 deletions

View File

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

View File

@@ -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<Flush>("glFlush");
glViewport = Bind<Viewport>("glViewport");
glClear = Bind<Clear>("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);

View File

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