diff --git a/src/gl/system/gl_interface.cpp b/src/gl/system/gl_interface.cpp index c09038bf8f..a5dbf0533e 100644 --- a/src/gl/system/gl_interface.cpp +++ b/src/gl/system/gl_interface.cpp @@ -66,10 +66,35 @@ static void CollectExtensions() int max = 0; glGetIntegerv(GL_NUM_EXTENSIONS, &max); - for(int i = 0; i < max; i++) + if (0 == max) { - extension = (const char*)glGetStringi(GL_EXTENSIONS, i); - m_Extensions.Push(FString(extension)); + // Try old method to collect extensions + const char *supported = (char *)glGetString(GL_EXTENSIONS); + + if (nullptr != supported) + { + char *extensions = new char[strlen(supported) + 1]; + strcpy(extensions, supported); + + char *extension = strtok(extensions, " "); + + while (extension) + { + m_Extensions.Push(FString(extension)); + extension = strtok(nullptr, " "); + } + + delete [] extensions; + } + } + else + { + // Use modern method to collect extensions + for (int i = 0; i < max; i++) + { + extension = (const char*)glGetStringi(GL_EXTENSIONS, i); + m_Extensions.Push(FString(extension)); + } } } diff --git a/src/gl/system/gl_load.c b/src/gl/system/gl_load.c index a6b7df013e..d3de767c3d 100644 --- a/src/gl/system/gl_load.c +++ b/src/gl/system/gl_load.c @@ -2375,8 +2375,41 @@ static void LoadExtByName(const char *extensionName) } } +static void ProcExtsFromExtString(const char *strExtList) +{ + size_t iExtListLen = strlen(strExtList); + const char *strExtListEnd = strExtList + iExtListLen; + const char *strCurrPos = strExtList; + char strWorkBuff[256]; -static void ProcExtsFromExtList(void) + while(*strCurrPos) + { + /*Get the extension at our position.*/ + int iStrLen = 0; + const char *strEndStr = strchr(strCurrPos, ' '); + int iStop = 0; + if(strEndStr == NULL) + { + strEndStr = strExtListEnd; + iStop = 1; + } + + iStrLen = (int)((ptrdiff_t)strEndStr - (ptrdiff_t)strCurrPos); + + if(iStrLen > 255) + return; + + strncpy(strWorkBuff, strCurrPos, iStrLen); + strWorkBuff[iStrLen] = '\0'; + + LoadExtByName(strWorkBuff); + + strCurrPos = strEndStr + 1; + if(iStop) break; + } +} + +static int ProcExtsFromExtList(void) { GLint iLoop; GLint iNumExtensions = 0; @@ -2387,6 +2420,8 @@ static void ProcExtsFromExtList(void) const char *strExtensionName = (const char *)_ptrc_glGetStringi(GL_EXTENSIONS, iLoop); LoadExtByName(strExtensionName); } + + return iNumExtensions; } int ogl_LoadFunctions() @@ -2398,8 +2433,15 @@ int ogl_LoadFunctions() if(!_ptrc_glGetIntegerv) return ogl_LOAD_FAILED; _ptrc_glGetStringi = (const GLubyte * (CODEGEN_FUNCPTR *)(GLenum, GLuint))IntGetProcAddress("glGetStringi"); if(!_ptrc_glGetStringi) return ogl_LOAD_FAILED; - - ProcExtsFromExtList(); + + if (0 == ProcExtsFromExtList()) + { + _ptrc_glGetString = (const GLubyte * (CODEGEN_FUNCPTR *)(GLenum))IntGetProcAddress("glGetString"); + if(!_ptrc_glGetString) return ogl_LOAD_FAILED; + + ProcExtsFromExtString((const char *)_ptrc_glGetString(GL_EXTENSIONS)); + } + numFailed = Load_Version_3_3(); if(numFailed == 0)