From fa4a6d431b75eb710f6c50f6f367604850441ede Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 2 May 2019 17:24:57 +0100 Subject: [PATCH] Only use modern extension query on new contexts. Refs #1359 * On mac on legacy contexts (GL2.1) glGetStringi will understandably fail completely, so we can't expect to be able to use modern enumeration of extensions on the assumption that it's really a compatibility context. --- renderdoc/driver/gl/gl_common.cpp | 45 +++++++++++++++++++++---------- renderdoc/driver/gl/gl_common.h | 1 + renderdoc/driver/gl/gl_driver.cpp | 8 +++++- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/renderdoc/driver/gl/gl_common.cpp b/renderdoc/driver/gl/gl_common.cpp index a36ec3442..4f1eadcd7 100644 --- a/renderdoc/driver/gl/gl_common.cpp +++ b/renderdoc/driver/gl/gl_common.cpp @@ -378,14 +378,8 @@ static void CheckExtFromString(const char *ext) } } -void FetchEnabledExtensions() +void GetContextVersion(bool &ctxGLES, int &ctxVersion) { - GLint numExts = 0; - if(GL.glGetIntegerv) - GL.glGetIntegerv(eGL_NUM_EXTENSIONS, &numExts); - - RDCEraseEl(HasExt); - if(GL.glGetString) { const char *version = (const char *)GL.glGetString(eGL_VERSION); @@ -395,15 +389,19 @@ void FetchEnabledExtensions() // "OpenGL ES N.M vendor-specific information" if(strncmp(version, "OpenGL ES", 9) == 0) { - IsGLES = true; + ctxGLES = true; int mj = int(version[10] - '0'); int mn = int(version[12] - '0'); - GLCoreVersion = RDCMAX(GLCoreVersion, mj * 10 + mn); + ctxVersion = mj * 10 + mn; } else { - IsGLES = false; + ctxGLES = false; + + int mj = int(version[0] - '0'); + int mn = int(version[1] - '0'); + ctxVersion = mj * 10 + mn; } } @@ -413,14 +411,33 @@ void FetchEnabledExtensions() GL.glGetIntegerv(eGL_MAJOR_VERSION, &mj); GL.glGetIntegerv(eGL_MINOR_VERSION, &mn); - GLCoreVersion = RDCMAX(GLCoreVersion, mj * 10 + mn); + if(mj > 0) + ctxVersion = mj * 10 + mn; } +} + +void FetchEnabledExtensions() +{ + RDCEraseEl(HasExt); + + int ctxVersion = 0; + bool ctxGLES = false; + GetContextVersion(ctxGLES, ctxVersion); + + GLCoreVersion = RDCMAX(GLCoreVersion, ctxVersion); + IsGLES = ctxGLES; RDCLOG("Checking enabled extensions, running as %s %d.%d", IsGLES ? "OpenGL ES" : "OpenGL", - (GLCoreVersion / 10), (GLCoreVersion % 10)); + (ctxVersion / 10), (ctxVersion % 10)); - if(GL.glGetStringi) + // only use glGetStringi on 3.0 contexts and above (ES and GL), even if we have the function + // pointer + if(GL.glGetStringi && ctxVersion >= 30) { + GLint numExts = 0; + if(GL.glGetIntegerv) + GL.glGetIntegerv(eGL_NUM_EXTENSIONS, &numExts); + for(int i = 0; i < numExts; i++) { const char *ext = (const char *)GL.glGetStringi(eGL_EXTENSIONS, (GLuint)i); @@ -428,7 +445,7 @@ void FetchEnabledExtensions() CheckExtFromString(ext); } } - else if(GL.glGetString && IsGLES && GLCoreVersion < 30) + else if(GL.glGetString) { std::string extstr = (const char *)GL.glGetString(eGL_EXTENSIONS); diff --git a/renderdoc/driver/gl/gl_common.h b/renderdoc/driver/gl/gl_common.h index da8b1d4a8..28927863d 100644 --- a/renderdoc/driver/gl/gl_common.h +++ b/renderdoc/driver/gl/gl_common.h @@ -827,6 +827,7 @@ extern bool VendorCheck[VendorCheck_Count]; // fills out the extension supported array and the version-specific checks above void DoVendorChecks(GLPlatform &platform, GLWindowingData context); +void GetContextVersion(bool &ctxGLES, int &ctxVersion); void FetchEnabledExtensions(); // verify that we got a replay context that we can work with diff --git a/renderdoc/driver/gl/gl_driver.cpp b/renderdoc/driver/gl/gl_driver.cpp index b907caf9c..ad71cc3f5 100644 --- a/renderdoc/driver/gl/gl_driver.cpp +++ b/renderdoc/driver/gl/gl_driver.cpp @@ -1197,7 +1197,13 @@ void WrappedOpenGL::ActivateContext(GLWindowingData winData) vector implExts; - if(GL.glGetIntegerv && GL.glGetStringi) + int ctxVersion = 0; + bool ctxGLES = false; + GetContextVersion(ctxGLES, ctxVersion); + + // only use glGetStringi on 3.0 contexts and above (ES and GL), even if we have the function + // pointer + if(GL.glGetIntegerv && GL.glGetStringi && ctxVersion >= 30) { GLuint numExts = 0; GL.glGetIntegerv(eGL_NUM_EXTENSIONS, (GLint *)&numExts);