From 5c0fedf190b58493402a5a74687e1662bc90d6c6 Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Sun, 11 May 2014 12:19:10 +0200 Subject: [PATCH] Patched GLEW to get the extensions with OpenGL >= 3.2 for the case that glGetString(GL_EXTENSIONS) fails --- neo/libs/glew/src/glew.c | 94 ++++++++++++++++++++++++++---- neo/renderer/RenderSystem_init.cpp | 2 +- neo/sys/win32/win_glimp.cpp | 4 +- 3 files changed, 85 insertions(+), 15 deletions(-) diff --git a/neo/libs/glew/src/glew.c b/neo/libs/glew/src/glew.c index d075b524..9d2ead70 100644 --- a/neo/libs/glew/src/glew.c +++ b/neo/libs/glew/src/glew.c @@ -9468,15 +9468,75 @@ static GLboolean _glewInit_GL_WIN_swap_hint (GLEW_CONTEXT_ARG_DEF_INIT) /* ------------------------------------------------------------------------- */ +// RB: use this instead of glGetString(GL_EXTENSIONS) for OpenGL >= 3.0 +static const GLubyte* _glewGetExtensions(void) { + static int s_init = 0; + static GLubyte s_array[16384]; + static const GLubyte* s_ret = 0; + + if (s_init == 0) { + PFNGLGETSTRINGIPROC localGetStringi = 0; + + s_init = 1; + + localGetStringi = (PFNGLGETSTRINGIPROC)glewGetProcAddress((const GLubyte*)"glGetStringi"); + + if (localGetStringi) { + GLint num_extensions = 0; + GLint extension_idx = 0; + GLuint arr_idx = 0; + + glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions); + + for ( ; extension_idx < num_extensions; ++extension_idx) { + const GLubyte* extension = localGetStringi(GL_EXTENSIONS, extension_idx); + + if (!extension) { + return 0; + } + + while (arr_idx < sizeof(s_array) && *extension != '\0') { + s_array[arr_idx++] = *extension++; + } + + if (arr_idx < sizeof(s_array)) { + s_array[arr_idx++] = ' '; + } + } + + if (arr_idx < sizeof(s_array)) { + s_array[arr_idx++] = '\0'; + s_ret = s_array; + } + } else { + s_ret = glGetString(GL_EXTENSIONS); + } + } + + return s_ret; +} +// RB end + GLboolean GLEWAPIENTRY glewGetExtension (const char* name) { - const GLubyte* start; - const GLubyte* end; - start = (const GLubyte*)glGetString(GL_EXTENSIONS); - if (start == 0) - return GL_FALSE; - end = start + _glewStrLen(start); - return _glewSearchExtension(name, start, end); + const GLubyte* start; + const GLubyte* end; + start = (const GLubyte*)glGetString(GL_EXTENSIONS); + // RB begin + if( start == 0 ) + { + // clear previously generated error + glGetError(); + + start = _glewGetExtensions(); + if( start == 0 ) + { + return GL_FALSE; + } + } + // RB end + end = start + _glewStrLen(start); + return _glewSearchExtension(name, start, end); } /* ------------------------------------------------------------------------- */ @@ -9531,10 +9591,22 @@ GLenum GLEWAPIENTRY glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST) CONST_CAST(GLEW_VERSION_1_1) = GLEW_VERSION_1_2 == GL_TRUE || ( major == 1 && minor >= 1 ) ? GL_TRUE : GL_FALSE; } - /* query opengl extensions string */ - extStart = glGetString(GL_EXTENSIONS); - if (extStart == 0) - extStart = (const GLubyte*)""; + /* query opengl extensions string */ + // RB begin + extStart = glGetString(GL_EXTENSIONS); + if( extStart == 0 ) + { + // clear previously generated error + glGetError(); + + extStart = _glewGetExtensions(); + if( extStart == 0 ) + { + extStart = (const GLubyte*)""; + } + } + // RB end + extEnd = extStart + _glewStrLen(extStart); /* initialize extensions */ diff --git a/neo/renderer/RenderSystem_init.cpp b/neo/renderer/RenderSystem_init.cpp index 3983c569..4a9a3fca 100644 --- a/neo/renderer/RenderSystem_init.cpp +++ b/neo/renderer/RenderSystem_init.cpp @@ -328,7 +328,7 @@ static void R_CheckPortableExtensions() } // RB: Mesa support - //if( idStr::Icmpn( glConfig.renderer_string, "Mesa", 4 ) == 0 || idStr::Icmpn( glConfig.renderer_string, "X.org", 4 ) == 0 ) + if( idStr::Icmpn( glConfig.renderer_string, "Mesa", 4 ) == 0 || idStr::Icmpn( glConfig.renderer_string, "X.org", 4 ) == 0 ) { glConfig.driverType = GLDRV_OPENGL_MESA; } diff --git a/neo/sys/win32/win_glimp.cpp b/neo/sys/win32/win_glimp.cpp index 9d15cad5..c043f7a7 100644 --- a/neo/sys/win32/win_glimp.cpp +++ b/neo/sys/win32/win_glimp.cpp @@ -1352,8 +1352,7 @@ bool GLimp_Init( glimpParms_t parms ) glConfig.physicalScreenWidthInCentimeters = 0.1f * mmWide; } - // RB begin - /* + // RB: we probably have a new OpenGL 3.2 core context so reinitialize GLEW GLenum glewResult = glewInit(); if( GLEW_OK != glewResult ) { @@ -1364,7 +1363,6 @@ bool GLimp_Init( glimpParms_t parms ) { common->Printf( "Using GLEW %s\n", glewGetString( GLEW_VERSION ) ); } - */ // RB end // wglSwapinterval, etc