From 59896c327aab2654c516ac4bda05066db47f3d09 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 2 Aug 2012 14:42:24 +0200 Subject: [PATCH] Context property fixes. --- src/internal.h | 4 ++-- src/opengl.c | 55 ++++++++++++++++++++++++++++++++------------------ src/window.c | 12 ++++++++--- 3 files changed, 46 insertions(+), 25 deletions(-) diff --git a/src/internal.h b/src/internal.h index 620459e9..fc036bc0 100644 --- a/src/internal.h +++ b/src/internal.h @@ -363,9 +363,9 @@ int _glfwStringInExtensionString(const char* string, const GLubyte* extensions); const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired, const _GLFWfbconfig* alternatives, unsigned int count); -void _glfwRefreshContextParams(void); +GLboolean _glfwRefreshContextParams(void); GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig); -GLboolean _glfwIsValidContext(_GLFWwindow* window, _GLFWwndconfig* wndconfig); +GLboolean _glfwIsValidContext(_GLFWwndconfig* wndconfig); #endif // _internal_h_ diff --git a/src/opengl.c b/src/opengl.c index d06bdb1e..273d2c58 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -38,7 +38,7 @@ // Parses the OpenGL version string and extracts the version number //======================================================================== -static void parseGLVersion(int* major, int* minor, int* rev) +static GLboolean parseGLVersion(int* major, int* minor, int* rev) { GLuint _major, _minor = 0, _rev = 0; const GLubyte* version; @@ -47,7 +47,10 @@ static void parseGLVersion(int* major, int* minor, int* rev) version = glGetString(GL_VERSION); if (!version) + { + _glfwSetError(GLFW_PLATFORM_ERROR, "Failed to retrieve version string"); return; + } if (strncmp((const char*) version, glesPrefix, strlen(glesPrefix)) == 0) { @@ -81,6 +84,8 @@ static void parseGLVersion(int* major, int* minor, int* rev) *major = _major; *minor = _minor; *rev = _rev; + + return GL_TRUE; } @@ -348,13 +353,34 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig) //======================================================================== // Reads back context properties +// It blames glfwOpenWindow because that's the only caller //======================================================================== -void _glfwRefreshContextParams(void) +GLboolean _glfwRefreshContextParams(void) { _GLFWwindow* window = _glfwLibrary.currentWindow; - parseGLVersion(&window->glMajor, &window->glMinor, &window->glRevision); + if (!parseGLVersion(&window->glMajor, + &window->glMinor, + &window->glRevision)) + { + return GL_FALSE; + } + + if (window->glMajor > 2) + { + // OpenGL 3.0+ uses a different function for extension string retrieval + // We cache it here instead of in glfwExtensionSupported mostly to alert + // users as early as possible that their build may be broken + + window->GetStringi = (PFNGLGETSTRINGIPROC) glfwGetProcAddress("glGetStringi"); + if (!window->GetStringi) + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "glfwOpenWindow: Entry point retrieval is broken"); + return GL_FALSE; + } + } // Read back forward-compatibility flag { @@ -408,16 +434,20 @@ void _glfwRefreshContextParams(void) glGetIntegerv(GL_SAMPLES_ARB, &window->samples); else window->samples = 0; + + return GL_TRUE; } //======================================================================== -// Checks whether the specified context fulfils the requirements +// Checks whether the current context fulfils the specified requirements // It blames glfwOpenWindow because that's the only caller //======================================================================== -GLboolean _glfwIsValidContext(_GLFWwindow* window, _GLFWwndconfig* wndconfig) +GLboolean _glfwIsValidContext(_GLFWwndconfig* wndconfig) { + _GLFWwindow* window = _glfwLibrary.currentWindow; + if (window->glMajor < wndconfig->glMajor || (window->glMajor == wndconfig->glMajor && window->glMinor < wndconfig->glMinor)) @@ -434,21 +464,6 @@ GLboolean _glfwIsValidContext(_GLFWwindow* window, _GLFWwndconfig* wndconfig) return GL_FALSE; } - if (window->glMajor > 2) - { - // OpenGL 3.0+ uses a different function for extension string retrieval - // We cache it here instead of in glfwExtensionSupported mostly to alert - // users as early as possible that their build may be broken - - window->GetStringi = (PFNGLGETSTRINGIPROC) glfwGetProcAddress("glGetStringi"); - if (!window->GetStringi) - { - _glfwSetError(GLFW_PLATFORM_ERROR, - "glfwOpenWindow: Entry point retrieval is broken"); - return GL_FALSE; - } - } - return GL_TRUE; } diff --git a/src/window.c b/src/window.c index 919434ec..2e77fa15 100644 --- a/src/window.c +++ b/src/window.c @@ -319,11 +319,17 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, } // Cache the actual (as opposed to desired) window parameters - glfwMakeContextCurrent(window); - _glfwRefreshContextParams(); _glfwPlatformRefreshWindowParams(); - if (!_glfwIsValidContext(window, &wndconfig)) + glfwMakeContextCurrent(window); + + if (!_glfwRefreshContextParams()) + { + glfwCloseWindow(window); + return GL_FALSE; + } + + if (!_glfwIsValidContext(&wndconfig)) { glfwCloseWindow(window); return GL_FALSE;