diff --git a/gfx/gl_common.h b/gfx/gl_common.h index 0576ca4fe5..cc52df5996 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -5,6 +5,9 @@ #if defined(IOS) #include #include + +// I guess we can soon add ES 3.0 here too + #else // Support OpenGL ES 3.0 @@ -21,6 +24,9 @@ #endif #else // OpenGL +// Now that glew is upgraded beyond 4.3, we can define MAY_HAVE_GLES3 on all platforms +// that include glew. +#define MAY_HAVE_GLES3 #include #if defined(__APPLE__) #include diff --git a/gfx_es2/gl_state.cpp b/gfx_es2/gl_state.cpp index 2fb4b8d49f..e31ab85a59 100644 --- a/gfx_es2/gl_state.cpp +++ b/gfx_es2/gl_state.cpp @@ -99,8 +99,26 @@ void CheckGLExtensions() { memset(&gl_extensions, 0, sizeof(gl_extensions)); const char *renderer = (const char *)glGetString(GL_RENDERER); + const char *versionStr = (const char *)glGetString(GL_VERSION); -#if defined(USING_GLES2) && defined(MAY_HAVE_GLES3) + char buffer[64]; + strcpy(buffer, versionStr); + const char *lastNumStart = buffer; + int numVer = 0; + int len = (int)strlen(buffer); + for (int i = 0; i < len && numVer < 3; i++) { + if (buffer[i] == '.') { + buffer[i] = 0; + gl_extensions.ver[numVer++] = atoi(lastNumStart); + i++; + lastNumStart = buffer + i; + } + } + if (numVer < 3) + gl_extensions.ver[numVer++] = atoi(lastNumStart); + +#if defined(USING_GLES2) +#if defined(MAY_HAVE_GLES3) // Try to load GLES 3.0 if (GL_TRUE == gl3stubInit()) { gl_extensions.GLES3 = true; @@ -111,6 +129,14 @@ void CheckGLExtensions() { } } #endif +#else + // If the GL version >= 4.3, we know it's a true superset of OpenGL ES 3.0 and can thus enable + // modern paths. + // Most of it could be enabled on lower GPUs as well, but let's start this way. + if ((gl_extensions.ver[0] == 4 && gl_extensions.ver[1] >= 3) || gl_extensions.ver[0] > 4) { + gl_extensions.GLES3 = true; + } +#endif const char *extString = (const char *)glGetString(GL_EXTENSIONS); if (extString) { diff --git a/gfx_es2/gl_state.h b/gfx_es2/gl_state.h index 6d35b5931d..a2e974cabe 100644 --- a/gfx_es2/gl_state.h +++ b/gfx_es2/gl_state.h @@ -314,6 +314,7 @@ extern OpenGLState glstate; // WARNING: This gets memset-d - so no strings please struct GLExtensions { + int ver[3]; bool GLES3; // true if the full OpenGL ES 3.0 is supported bool OES_depth24; bool OES_packed_depth_stencil;