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