Browse Source

Fixed OpenGL context version checking when OpenGL ES is used.

--HG--
branch : minor
Alex Szpakowski 10 years ago
parent
commit
84a6dd3b1c
2 changed files with 10 additions and 5 deletions
  1. 9 4
      src/modules/window/sdl/Window.cpp
  2. 1 1
      src/modules/window/sdl/Window.h

+ 9 - 4
src/modules/window/sdl/Window.cpp

@@ -306,7 +306,7 @@ void Window::setGLContextAttributes(const ContextAttribs &attribs)
 	SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, contextflags);
 }
 
-bool Window::checkGLVersion(int versionmajor, int versionminor)
+bool Window::checkGLVersion(const ContextAttribs &attribs)
 {
 	typedef unsigned char GLubyte;
 	typedef unsigned int GLenum;
@@ -328,10 +328,15 @@ bool Window::checkGLVersion(int versionmajor, int versionminor)
 
 	// glGetString(GL_VERSION) returns a string with the format "major.minor",
 	// or "OpenGL ES major.minor" in GLES contexts.
-	if (sscanf(glversion, "%d.%d", &glmajor, &glminor) != 2)
+	const char *format = "%d.%d";
+	if (attribs.gles)
+		format = "OpenGL ES %d.%d";
+
+	if (sscanf(glversion, format, &glmajor, &glminor) != 2)
 		return false;
 
-	if (glmajor < versionmajor || (glmajor == versionmajor && glminor < versionminor))
+	if (glmajor < attribs.versionMajor
+		|| (glmajor == attribs.versionMajor && glminor < attribs.versionMinor))
 		return false;
 
 	return true;
@@ -424,7 +429,7 @@ bool Window::setContext(int msaa, bool vsync, bool sRGB)
 		}
 
 		// Make sure the context's version is at least what we requested.
-		if (context && !checkGLVersion(attribs.versionMajor, attribs.versionMinor))
+		if (context && !checkGLVersion(attribs))
 		{
 			SDL_GL_DeleteContext(context);
 			context = nullptr;

+ 1 - 1
src/modules/window/sdl/Window.h

@@ -113,7 +113,7 @@ private:
 
 	void setGLFramebufferAttributes(int msaa, bool sRGB);
 	void setGLContextAttributes(const ContextAttribs &attribs);
-	bool checkGLVersion(int versionmajor, int versionminor);
+	bool checkGLVersion(const ContextAttribs &attribs);
 	bool setContext(int msaa, bool vsync, bool sRGB);
 
 	// Update the saved window settings based on the window's actual state.