Search
lxdream.org :: lxdream/src/pvr2/glutil.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/glutil.c
changeset 1129:7b16bbd6209c
prev1066:ddffe9d2b332
next1134:f502f3d32f90
author nkeynes
date Fri Sep 17 20:08:50 2010 +1000 (13 years ago)
permissions -rw-r--r--
last change Refactor shader management to support multiple programs, which are all
defined in the shaders.glsl, rather than split up into one file per
fragment.
view annotate diff log raw
     1 /**
     2  * $Id$
     3  *
     4  * GL-based support functions 
     5  *
     6  * Copyright (c) 2005 Nathan Keynes.
     7  *
     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.
    12  *
    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.
    17  */
    19 #include <string.h>
    20 #include <stdlib.h>
    21 #include <glib/gstrfuncs.h>
    22 #include "pvr2/glutil.h"
    24 gboolean isGLSecondaryColorSupported()
    25 {
    26     return isGLExtensionSupported("GL_EXT_secondary_color");
    27 }
    29 gboolean isGLVertexBufferSupported()
    30 {
    31     return isGLExtensionSupported("GL_ARB_vertex_buffer_object");
    32 }
    34 gboolean isGLPixelBufferSupported()
    35 {
    36     return isGLExtensionSupported("GL_ARB_pixel_buffer_object");
    37 }
    39 gboolean isGLMirroredTextureSupported()
    40 {
    41     return isGLExtensionSupported("GL_ARB_texture_mirrored_repeat");
    42 }
    44 /**
    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.
    48  */
    49 gboolean isGLExtensionSupported( const char *extension )
    50 {
    51     const GLubyte *extensions = NULL;
    52     const GLubyte *start;
    53     GLubyte *where, *terminator;
    55     /* Extension names should not have spaces. */
    56     where = (GLubyte *) strchr(extension, ' ');
    57     if (where || *extension == '\0')
    58         return 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. */
    63         return FALSE;
    64     }
    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,
    67        etc. */
    68     start = extensions;
    69     for (;;) {
    70         where = (GLubyte *) strstr((const char *) start, extension);
    71         if (!where)
    72             break;
    73         terminator = where + strlen(extension);
    74         if (where == start || *(where - 1) == ' ')
    75             if (*terminator == ' ' || *terminator == '\0')
    76                 return TRUE;
    77         start = terminator;
    78     }
    79     return FALSE;
    80 }
    82 int compare_charp( const void *a, const void *b )
    83 {
    84     const char **ca = (const char **)a;
    85     const char **cb = (const char **)b;
    86     return strcmp(*ca, *cb);
    87 }
    89 void glPrintInfo( FILE *out )
    90 {
    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] );
   106     }
   107     g_strfreev(ext_split);
   108 }
.