4 * GL-based support functions
6 * Copyright (c) 2005 Nathan Keynes.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
21 #include <glib/gstrfuncs.h>
22 #include "pvr2/glutil.h"
24 gboolean isGLSecondaryColorSupported()
26 return isGLExtensionSupported("GL_EXT_secondary_color");
29 gboolean isGLVertexBufferSupported()
31 return isGLExtensionSupported("GL_ARB_vertex_buffer_object");
34 gboolean isGLPixelBufferSupported()
36 return isGLExtensionSupported("GL_ARB_pixel_buffer_object");
39 gboolean isGLMirroredTextureSupported()
41 return isGLExtensionSupported("GL_ARB_texture_mirrored_repeat");
45 * Test if a specific extension is supported. From opengl.org
46 * @param extension extension name to check for
47 * @return TRUE if supported, otherwise FALSE.
49 gboolean isGLExtensionSupported( const char *extension )
51 const GLubyte *extensions = NULL;
53 GLubyte *where, *terminator;
55 /* Extension names should not have spaces. */
56 where = (GLubyte *) strchr(extension, ' ');
57 if (where || *extension == '\0')
59 extensions = glGetString(GL_EXTENSIONS);
60 if( extensions == NULL ) {
61 /* No GL available, so we're pretty sure the extension isn't
62 * available either. */
65 /* It takes a bit of care to be fool-proof about parsing the
66 OpenGL extensions string. Don't be fooled by sub-strings,
70 where = (GLubyte *) strstr((const char *) start, extension);
73 terminator = where + strlen(extension);
74 if (where == start || *(where - 1) == ' ')
75 if (*terminator == ' ' || *terminator == '\0')
82 int compare_charp( const void *a, const void *b )
84 const char **ca = (const char **)a;
85 const char **cb = (const char **)b;
86 return strcmp(*ca, *cb);
89 void glPrintInfo( FILE *out )
91 const gchar *extensions = (const gchar *)glGetString(GL_EXTENSIONS);
92 gchar **ext_split = g_strsplit(extensions, " ", 0);
93 unsigned int i, count;
95 for( count = 0; ext_split[count] != NULL; count++ );
97 qsort(ext_split, count, sizeof(gchar *), compare_charp);
99 fprintf( out, "GL Vendor: %s\n", glGetString(GL_VENDOR) );
100 fprintf( out, "GL Renderer: %s\n", glGetString(GL_RENDERER) );
101 fprintf( out, "GL Version: %s\n", glGetString(GL_VERSION) );
103 fprintf( out, "Supported GL Extensions:\n" );
104 for( i=0; ext_split[i] != NULL; i++ ) {
105 fprintf( out, " %s\n", ext_split[i] );
107 g_strfreev(ext_split);
.