Search
lxdream.org :: lxdream/src/pvr2/glutil.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/glutil.c
changeset 1134:f502f3d32f90
prev1129:7b16bbd6209c
next1140:7dc1c71ece76
author nkeynes
date Fri Oct 22 20:55:32 2010 +1000 (13 years ago)
permissions -rw-r--r--
last change Dump more information with --gl-info, and print it a little more nicely
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 gboolean isGLVertexRangeSupported()
    45 {
    46     return isGLExtensionSupported("GL_APPLE_vertex_array_range") ||
    47             isGLExtensionSupported("GL_NV_vertex_array_range");
    48 }
    50 /**
    51  * Test if a specific extension is supported. From opengl.org
    52  * @param extension extension name to check for
    53  * @return TRUE if supported, otherwise FALSE.
    54  */
    55 gboolean isGLExtensionSupported( const char *extension )
    56 {
    57     const GLubyte *extensions = NULL;
    58     const GLubyte *start;
    59     GLubyte *where, *terminator;
    61     /* Extension names should not have spaces. */
    62     where = (GLubyte *) strchr(extension, ' ');
    63     if (where || *extension == '\0')
    64         return 0;
    65     extensions = glGetString(GL_EXTENSIONS);
    66     if( extensions == NULL ) {
    67         /* No GL available, so we're pretty sure the extension isn't
    68          * available either. */
    69         return FALSE;
    70     }
    71     /* It takes a bit of care to be fool-proof about parsing the
    72        OpenGL extensions string. Don't be fooled by sub-strings,
    73        etc. */
    74     start = extensions;
    75     for (;;) {
    76         where = (GLubyte *) strstr((const char *) start, extension);
    77         if (!where)
    78             break;
    79         terminator = where + strlen(extension);
    80         if (where == start || *(where - 1) == ' ')
    81             if (*terminator == ' ' || *terminator == '\0')
    82                 return TRUE;
    83         start = terminator;
    84     }
    85     return FALSE;
    86 }
    88 int compare_charp( const void *a, const void *b )
    89 {
    90     const char **ca = (const char **)a;
    91     const char **cb = (const char **)b;
    92     return strcmp(*ca, *cb);
    93 }
    95 #define DEFAULT_TERMINAL_COLUMNS 80
    96 #define DEFAULT_COLUMN_WIDTH 34
    98 /**
    99  * Format a GL extension list (or other space-separated string) nicely, and
   100  * print to the given output stream.
   101  */
   103 void fprint_extensions( FILE *out, const char *extensions )
   104 {
   105     unsigned int i, j, count, maxlen = DEFAULT_COLUMN_WIDTH, columns, per_column, terminal_columns;
   106     const char *terminal_columns_str = getenv("COLUMNS");
   107     if( terminal_columns_str == NULL || (terminal_columns = strtol(terminal_columns_str,0,10)) == 0 )
   108         terminal_columns = DEFAULT_TERMINAL_COLUMNS;
   110     if( extensions == NULL || extensions[0] == '\0' )
   111         return;
   113     gchar *ext_dup = g_strdup(extensions);
   114     gchar **ext_split = g_strsplit(g_strstrip(extensions), " ", 0);
   115     for( count = 0; ext_split[count] != NULL; count++ ) {
   116         unsigned len = strlen(ext_split[count]);
   117         if( len > maxlen )
   118             maxlen = len;
   119     }
   121     columns = terminal_columns / (maxlen+2);
   122     if( columns == 0 )
   123         columns = 1;
   124     per_column = (count+columns-1) / columns;
   126     qsort(ext_split, count, sizeof(gchar *), compare_charp);
   128     for( i=0; i<per_column; i++ ) {
   129         for( j=0; j<columns; j++ ) {
   130             unsigned idx = i + (j*per_column);
   131             if( idx < count )
   132                 fprintf( out, "  %-*s", maxlen, ext_split[idx] );
   133         }
   134         fprintf( out, "\n" );
   135     }
   136     g_strfreev(ext_split);
   137     g_free(ext_dup);
   138 }
   140 void glPrintInfo( FILE *out )
   141 {
   142     fprintf( out, "GL Vendor: %s\n", glGetString(GL_VENDOR) );
   143     fprintf( out, "GL Renderer: %s\n", glGetString(GL_RENDERER) );
   144     fprintf( out, "GL Version: %s\n", glGetString(GL_VERSION) );
   145     if( glsl_is_supported() ) {
   146          const char * version = glsl_get_version();
   147          fprintf( out, "SL Version: %s\n", version );
   148     }
   150     fprintf( out, "GL Extensions:\n" );
   152     fprint_extensions( out, (const gchar *)glGetString(GL_EXTENSIONS) );
   153     if( display_driver && display_driver->print_info ) {
   154         fprintf( out, "\n");
   155         display_driver->print_info(out);
   156     }
   157 }
.