From 84a6dd3b1c3a2da25a3e0e4ea7c23ee9fa70a950 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Fri, 30 Jan 2015 04:48:09 -0400 Subject: [PATCH] Fixed OpenGL context version checking when OpenGL ES is used. --HG-- branch : minor --- src/modules/window/sdl/Window.cpp | 13 +++++++++---- src/modules/window/sdl/Window.h | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index d555dbc05..40248a164 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/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; diff --git a/src/modules/window/sdl/Window.h b/src/modules/window/sdl/Window.h index e0345a997..b90614523 100644 --- a/src/modules/window/sdl/Window.h +++ b/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.