From 011bbfd451ef9df13ee66490a3b2760e77536016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Tue, 5 Jan 2016 21:06:42 -0800 Subject: [PATCH] GL: Added different code path when glGetString(GL_EXTENSIONS) returns NULL. --- src/glimports.h | 2 ++ src/renderer_gl.cpp | 77 +++++++++++++++++++++++++++------------------ 2 files changed, 49 insertions(+), 30 deletions(-) diff --git a/src/glimports.h b/src/glimports.h index 5891bd55..bcc114d1 100644 --- a/src/glimports.h +++ b/src/glimports.h @@ -149,6 +149,7 @@ typedef void (GL_APIENTRYP PFNGLGETQUERYOBJECTUI64VPROC) (GLuint id, G typedef void (GL_APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); typedef void (GL_APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params); typedef const GLubyte* (GL_APIENTRYP PFNGLGETSTRINGPROC) (GLenum name); +typedef const GLubyte* (GL_APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index); typedef GLint (GL_APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name); typedef void (GL_APIENTRYP PFNGLINVALIDATEFRAMEBUFFERPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments); typedef void (GL_APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program); @@ -332,6 +333,7 @@ GL_IMPORT______(true, PFNGLGETQUERYOBJECTUI64VPROC, glGetQueryObj GL_IMPORT______(false, PFNGLGETSHADERIVPROC, glGetShaderiv); GL_IMPORT______(false, PFNGLGETSHADERINFOLOGPROC, glGetShaderInfoLog); GL_IMPORT______(false, PFNGLGETSTRINGPROC, glGetString); +GL_IMPORT______(true, PFNGLGETSTRINGIPROC, glGetStringi); GL_IMPORT______(false, PFNGLGETUNIFORMLOCATIONPROC, glGetUniformLocation); #if BGFX_CONFIG_RENDERER_OPENGL || !(BGFX_CONFIG_RENDERER_OPENGLES < 30) GL_IMPORT______(true, PFNGLINVALIDATEFRAMEBUFFERPROC, glInvalidateFramebuffer); diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 24d36261..9738a713 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -1209,6 +1209,34 @@ namespace bgfx { namespace gl _minFilter = s_textureFilterMin[min][_hasMips ? mip+1 : 0]; } + void updateExtension(const char* _name) + { + bool supported = false; + for (uint32_t ii = 0; ii < Extension::Count; ++ii) + { + Extension& extension = s_extension[ii]; + if (!extension.m_supported + && extension.m_initialize) + { + const char* ext = _name; + if (0 == strncmp(ext, "GL_", 3) ) // skip GL_ + { + ext += 3; + } + + if (0 == strcmp(ext, extension.m_name) ) + { + extension.m_supported = true; + supported = true; + break; + } + } + } + + BX_TRACE("GL_EXTENSION %3d%s: %s", index, supported ? " (supported)" : "", _name); + BX_UNUSED(supported); + } + struct RendererContextGL : public RendererContextI { RendererContextGL() @@ -1365,42 +1393,31 @@ namespace bgfx { namespace gl strncpy(name, pos, len); name[len] = '\0'; - bool supported = false; - for (uint32_t ii = 0; ii < Extension::Count; ++ii) - { - Extension& extension = s_extension[ii]; - if (!extension.m_supported - && extension.m_initialize) - { - const char* ext = name; - if (0 == strncmp(ext, "GL_", 3) ) // skip GL_ - { - ext += 3; - } - - if (0 == strcmp(ext, extension.m_name) ) - { - extension.m_supported = true; - supported = true; - break; - } - } - } - - BX_TRACE("GL_EXTENSION %3d%s: %s", index, supported ? " (supported)" : "", name); - BX_UNUSED(supported); + updateExtension(name); pos += len+1; ++index; } + } + else if (NULL != glGetStringi) + { + GLint numExtensions = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); + glGetError(); // ignore error if glGetString returns NULL. - BX_TRACE("Supported extensions:"); - for (uint32_t ii = 0; ii < Extension::Count; ++ii) + for (GLint index = 0; index < numExtensions; ++index) { - if (s_extension[ii].m_supported) - { - BX_TRACE("\t%2d: %s", ii, s_extension[ii].m_name); - } + const char* name = (const char*)glGetStringi(GL_EXTENSIONS, index); + updateExtension(name); + } + } + + BX_TRACE("Supported extensions:"); + for (uint32_t ii = 0; ii < Extension::Count; ++ii) + { + if (s_extension[ii].m_supported) + { + BX_TRACE("\t%2d: %s", ii, s_extension[ii].m_name); } } }