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:05:34 2010 +1000 (10 years ago)
permissions -rw-r--r--
last change Add undocumented option --gl-info to dump out the GL identification and extension list
file annotate diff log raw
nkeynes@635
     1
/**
nkeynes@636
     2
 * $Id$
nkeynes@635
     3
 *
nkeynes@635
     4
 * GL-based support functions 
nkeynes@635
     5
 *
nkeynes@635
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@635
     7
 *
nkeynes@635
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@635
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@635
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@635
    11
 * (at your option) any later version.
nkeynes@635
    12
 *
nkeynes@635
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@635
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@635
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@635
    16
 * GNU General Public License for more details.
nkeynes@635
    17
 */
nkeynes@736
    18
nkeynes@645
    19
#include <string.h>
nkeynes@1129
    20
#include <stdlib.h>
nkeynes@687
    21
#include <glib/gstrfuncs.h>
nkeynes@635
    22
#include "pvr2/glutil.h"
nkeynes@635
    23
nkeynes@667
    24
gboolean isGLSecondaryColorSupported()
nkeynes@667
    25
{
nkeynes@736
    26
    return isGLExtensionSupported("GL_EXT_secondary_color");
nkeynes@667
    27
}
nkeynes@667
    28
nkeynes@667
    29
gboolean isGLVertexBufferSupported()
nkeynes@667
    30
{
nkeynes@736
    31
    return isGLExtensionSupported("GL_ARB_vertex_buffer_object");
nkeynes@667
    32
}
nkeynes@667
    33
nkeynes@667
    34
gboolean isGLPixelBufferSupported()
nkeynes@667
    35
{
nkeynes@736
    36
    return isGLExtensionSupported("GL_ARB_pixel_buffer_object");
nkeynes@667
    37
}
nkeynes@667
    38
nkeynes@667
    39
gboolean isGLMirroredTextureSupported()
nkeynes@667
    40
{
nkeynes@736
    41
    return isGLExtensionSupported("GL_ARB_texture_mirrored_repeat");
nkeynes@667
    42
}
nkeynes@667
    43
nkeynes@635
    44
/**
nkeynes@635
    45
 * Test if a specific extension is supported. From opengl.org
nkeynes@635
    46
 * @param extension extension name to check for
nkeynes@635
    47
 * @return TRUE if supported, otherwise FALSE.
nkeynes@635
    48
 */
nkeynes@635
    49
gboolean isGLExtensionSupported( const char *extension )
nkeynes@635
    50
{
nkeynes@635
    51
    const GLubyte *extensions = NULL;
nkeynes@635
    52
    const GLubyte *start;
nkeynes@635
    53
    GLubyte *where, *terminator;
nkeynes@635
    54
nkeynes@635
    55
    /* Extension names should not have spaces. */
nkeynes@635
    56
    where = (GLubyte *) strchr(extension, ' ');
nkeynes@635
    57
    if (where || *extension == '\0')
nkeynes@736
    58
        return 0;
nkeynes@635
    59
    extensions = glGetString(GL_EXTENSIONS);
nkeynes@645
    60
    if( extensions == NULL ) {
nkeynes@736
    61
        /* No GL available, so we're pretty sure the extension isn't
nkeynes@736
    62
         * available either. */
nkeynes@736
    63
        return FALSE;
nkeynes@645
    64
    }
nkeynes@635
    65
    /* It takes a bit of care to be fool-proof about parsing the
nkeynes@635
    66
       OpenGL extensions string. Don't be fooled by sub-strings,
nkeynes@635
    67
       etc. */
nkeynes@635
    68
    start = extensions;
nkeynes@635
    69
    for (;;) {
nkeynes@736
    70
        where = (GLubyte *) strstr((const char *) start, extension);
nkeynes@736
    71
        if (!where)
nkeynes@736
    72
            break;
nkeynes@736
    73
        terminator = where + strlen(extension);
nkeynes@736
    74
        if (where == start || *(where - 1) == ' ')
nkeynes@736
    75
            if (*terminator == ' ' || *terminator == '\0')
nkeynes@736
    76
                return TRUE;
nkeynes@736
    77
        start = terminator;
nkeynes@635
    78
    }
nkeynes@635
    79
    return FALSE;
nkeynes@635
    80
}
nkeynes@687
    81
nkeynes@1129
    82
int compare_charp( const void *a, const void *b )
nkeynes@1129
    83
{
nkeynes@1129
    84
    const char **ca = (const char **)a;
nkeynes@1129
    85
    const char **cb = (const char **)b;
nkeynes@1129
    86
    return strcmp(*ca, *cb);
nkeynes@1129
    87
}
nkeynes@1129
    88
nkeynes@687
    89
void glPrintInfo( FILE *out )
nkeynes@687
    90
{
nkeynes@700
    91
    const gchar *extensions = (const gchar *)glGetString(GL_EXTENSIONS);
nkeynes@687
    92
    gchar **ext_split = g_strsplit(extensions, " ", 0);
nkeynes@1129
    93
    unsigned int i, count;
nkeynes@1129
    94
nkeynes@1129
    95
    for( count = 0; ext_split[count] != NULL; count++ );
nkeynes@1129
    96
nkeynes@1129
    97
    qsort(ext_split, count, sizeof(gchar *), compare_charp);
nkeynes@736
    98
nkeynes@687
    99
    fprintf( out, "GL Vendor: %s\n", glGetString(GL_VENDOR) );
nkeynes@687
   100
    fprintf( out, "GL Renderer: %s\n", glGetString(GL_RENDERER) );
nkeynes@687
   101
    fprintf( out, "GL Version: %s\n", glGetString(GL_VERSION) );
nkeynes@736
   102
nkeynes@687
   103
    fprintf( out, "Supported GL Extensions:\n" );
nkeynes@687
   104
    for( i=0; ext_split[i] != NULL; i++ ) {
nkeynes@687
   105
        fprintf( out, "  %s\n", ext_split[i] );
nkeynes@687
   106
    }
nkeynes@687
   107
    g_strfreev(ext_split);
nkeynes@687
   108
}
.