Support OpenGL 3.0 and later.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 21 Feb 2014 12:41:39 -0500
changeset 1135 780e3e4b1d4a
parent 1134 be31bd0ee0a2
child 1136 0255ec8d7775
Support OpenGL 3.0 and later.
utils/glcaps.c
--- a/utils/glcaps.c	Fri Feb 21 12:41:25 2014 -0500
+++ b/utils/glcaps.c	Fri Feb 21 12:41:39 2014 -0500
@@ -29,6 +29,12 @@
 #define GL_MAX_BINDABLE_UNIFORM_SIZE_EXT 0x8DED
 #endif
 
+static int is_atleast_gl3(const char *str)
+{
+    int maj, min;
+    sscanf(str, "%d.%d", &maj, &min);
+    return ( ((maj << 16) | min) >= ((3 << 16) | 0) );
+}
 
 int main(int argc, char **argv)
 {
@@ -57,6 +63,7 @@
     PFNGLGETSTRINGPROC pglGetString = (PFNGLGETSTRINGPROC) SDL_GL_GetProcAddress("glGetString");
     PFNGLGETINTEGERVPROC pglGetIntegerv = (PFNGLGETINTEGERVPROC) SDL_GL_GetProcAddress("glGetIntegerv");
     PFNGLGETPROGRAMIVARBPROC pglGetProgramivARB = (PFNGLGETPROGRAMIVARBPROC) SDL_GL_GetProcAddress("glGetProgramivARB");
+    PFNGLGETSTRINGIPROC pglGetStringi = (PFNGLGETSTRINGIPROC) SDL_GL_GetProcAddress("glGetStringi");
 
     printf("Basic strings...\n\n");
 
@@ -70,16 +77,27 @@
 
     printf("\nExtensions...\n\n");
 
-    const GLubyte *ext = pglGetString(GL_EXTENSIONS);
-    while (*ext)
+    if (is_atleast_gl3((const char *) pglGetString(GL_VERSION)))
+    {
+        GLint i;
+        GLint num_exts = 0;
+        pglGetIntegerv(GL_NUM_EXTENSIONS, &num_exts);
+        for (i = 0; i < num_exts; i++)
+            printf("%s\n", (const char *) pglGetStringi(GL_EXTENSIONS, i));
+    }
+    else
     {
-        fputc((*ext == ' ') ? '\n' : ((int) *ext), stdout);
-        ext++;
-    } // while
+        const GLubyte *ext = pglGetString(GL_EXTENSIONS);
+        while (*ext)
+        {
+            fputc((*ext == ' ') ? '\n' : ((int) *ext), stdout);
+            ext++;
+        } // while
 
-    ext--;
-    if (*ext != ' ')
-        printf("\n");
+        ext--;
+        if (*ext != ' ')
+            printf("\n");
+    }
 
     printf("\nARB1 values...\n\n");