2010-03-13 21:10:45 +00:00
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
2011-12-14 07:40:48 +00:00
// Copyright (C) 2001-2008 Martiño Figueroa
2010-03-13 21:10:45 +00:00
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
# include "opengl.h"
# include <stdexcept>
# include "graphics_interface.h"
# include "context_gl.h"
# include "gl_wrap.h"
2011-02-04 01:24:26 +00:00
# include <map>
# include "util.h"
2010-03-13 21:10:45 +00:00
# include "leak_dumper.h"
using namespace Shared : : Platform ;
2011-02-04 01:24:26 +00:00
using namespace Shared : : Util ;
2010-03-13 21:10:45 +00:00
using namespace std ;
2011-02-04 01:24:26 +00:00
namespace Shared { namespace Graphics { namespace Gl {
std : : map < string , bool > cacheExtensionCheckList ;
static int vboEnabled = 0 ;
2010-03-13 21:10:45 +00:00
// =====================================================
// class Globals
// =====================================================
2011-02-04 01:24:26 +00:00
bool getVBOSupported ( ) {
if ( vboEnabled = = 0 ) {
bool value = isGlExtensionSupported ( " GL_ARB_vertex_buffer_object " ) ;
vboEnabled = ( value = = true ? 1 : - 1 ) ;
}
return ( vboEnabled = = 1 ) ;
}
void setVBOSupported ( bool value ) {
vboEnabled = ( value = = true ? 1 : - 1 ) ;
} ;
void overrideGlExtensionSupport ( const char * extensionName , bool value ) {
cacheExtensionCheckList [ extensionName ] = value ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " OpenGL Extension [%s] supported status FORCED TO = %d \n " , extensionName , cacheExtensionCheckList [ extensionName ] ) ;
}
bool isGlExtensionSupported ( const char * extensionName ) {
if ( cacheExtensionCheckList . find ( extensionName ) ! = cacheExtensionCheckList . end ( ) ) {
return cacheExtensionCheckList [ extensionName ] ;
}
2010-03-13 21:10:45 +00:00
const GLubyte * extensionStr = glGetString ( GL_EXTENSIONS ) ;
2010-10-21 07:20:17 +00:00
const char * s = reinterpret_cast < const char * > ( extensionStr ) ;
size_t len = strlen ( extensionName ) ;
2010-03-13 21:10:45 +00:00
2011-02-04 01:24:26 +00:00
cacheExtensionCheckList [ extensionName ] = false ;
2010-03-13 21:10:45 +00:00
if ( s ! = NULL ) {
while ( ( s = strstr ( s , extensionName ) ) ! = NULL ) {
s + = len ;
if ( ( * s = = ' ' ) | | ( * s = = ' \0 ' ) ) {
2011-02-04 01:24:26 +00:00
cacheExtensionCheckList [ extensionName ] = true ;
break ;
2010-03-13 21:10:45 +00:00
}
}
}
2011-02-04 01:24:26 +00:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " OpenGL Extension [%s] supported status = %d \n " , extensionName , cacheExtensionCheckList [ extensionName ] ) ;
return cacheExtensionCheckList [ extensionName ] ;
2010-03-13 21:10:45 +00:00
}
2011-12-06 01:34:51 +00:00
//bool isGlVersionSupported(int major, int minor, int release) {
//
// const char *strVersion= getGlVersion();
//
// //major
// const char *majorTok= strVersion;
// int majorSupported= atoi(majorTok);
//
// if(majorSupported<major) {
// return false;
// }
// else if(majorSupported>major) {
// return true;
// }
//
// //minor
// int i=0;
// while(strVersion[i]!='.') {
// ++i;
// }
// const char *minorTok= &strVersion[i]+1;
// int minorSupported= atoi(minorTok);
//
// if(minorSupported<minor) {
// return false;
// }
// else if(minorSupported>minor) {
// return true;
// }
//
// //release
// ++i;
// while(strVersion[i]!='.') {
// ++i;
// }
// const char *releaseTok= &strVersion[i]+1;
//
// if(atoi(releaseTok) < release) {
// return false;
// }
//
// return true;
//}
2010-03-13 21:10:45 +00:00
2011-02-04 01:24:26 +00:00
const char * getGlVersion ( ) {
2010-03-13 21:10:45 +00:00
return reinterpret_cast < const char * > ( glGetString ( GL_VERSION ) ) ;
}
2011-02-04 01:24:26 +00:00
const char * getGlRenderer ( ) {
2010-03-13 21:10:45 +00:00
return reinterpret_cast < const char * > ( glGetString ( GL_RENDERER ) ) ;
}
2011-02-04 01:24:26 +00:00
const char * getGlVendor ( ) {
2010-03-13 21:10:45 +00:00
return reinterpret_cast < const char * > ( glGetString ( GL_VENDOR ) ) ;
}
2011-02-04 01:24:26 +00:00
const char * getGlExtensions ( ) {
2010-03-13 21:10:45 +00:00
return reinterpret_cast < const char * > ( glGetString ( GL_EXTENSIONS ) ) ;
}
2011-02-04 01:24:26 +00:00
const char * getGlPlatformExtensions ( ) {
2010-03-13 21:10:45 +00:00
Context * c = GraphicsInterface : : getInstance ( ) . getCurrentContext ( ) ;
return getPlatformExtensions ( static_cast < ContextGl * > ( c ) - > getPlatformContextGl ( ) ) ;
}
2011-02-04 01:24:26 +00:00
int getGlMaxLights ( ) {
2010-03-13 21:10:45 +00:00
int i ;
2011-10-18 01:13:38 +00:00
glGetIntegerv ( GL_MAX_LIGHTS , ( GLint * ) & i ) ;
2010-03-13 21:10:45 +00:00
return i ;
}
2011-02-04 01:24:26 +00:00
int getGlMaxTextureSize ( ) {
2010-03-13 21:10:45 +00:00
int i ;
2011-10-18 01:13:38 +00:00
glGetIntegerv ( GL_MAX_TEXTURE_SIZE , ( GLint * ) & i ) ;
2010-03-13 21:10:45 +00:00
return i ;
}
2011-02-04 01:24:26 +00:00
int getGlMaxTextureUnits ( ) {
2010-03-13 21:10:45 +00:00
int i ;
2011-10-18 01:13:38 +00:00
glGetIntegerv ( GL_MAX_TEXTURE_UNITS , ( GLint * ) & i ) ;
2010-03-13 21:10:45 +00:00
return i ;
}
2011-02-04 01:24:26 +00:00
int getGlModelviewMatrixStackDepth ( ) {
2010-03-13 21:10:45 +00:00
int i ;
2011-10-18 01:13:38 +00:00
glGetIntegerv ( GL_MAX_MODELVIEW_STACK_DEPTH , ( GLint * ) & i ) ;
2010-03-13 21:10:45 +00:00
return i ;
}
2011-02-04 01:24:26 +00:00
int getGlProjectionMatrixStackDepth ( ) {
2010-03-13 21:10:45 +00:00
int i ;
2011-10-18 01:13:38 +00:00
glGetIntegerv ( GL_MAX_PROJECTION_STACK_DEPTH , ( GLint * ) & i ) ;
2010-03-13 21:10:45 +00:00
return i ;
}
2011-02-04 01:24:26 +00:00
void checkGlExtension ( const char * extensionName ) {
2010-03-13 21:10:45 +00:00
if ( ! isGlExtensionSupported ( extensionName ) ) {
2012-04-14 21:21:09 +00:00
throw megaglest_runtime_error ( " OpenGL extension not supported: " + string ( extensionName ) ) ;
2010-03-13 21:10:45 +00:00
}
}
} } } // end namespace