1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 MartiƱo Figueroa
//
// 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"
#include <map>
#include "util.h"
#include "leak_dumper.h"
using namespace Shared::Platform;
using namespace Shared::Util;
using namespace std;
namespace Shared { namespace Graphics { namespace Gl {
std::map<string,bool> cacheExtensionCheckList;
static int vboEnabled = 0;
// =====================================================
// class Globals
// =====================================================
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];
}
const GLubyte *extensionStr= glGetString(GL_EXTENSIONS);
const char *s= reinterpret_cast<const char *>(extensionStr);
size_t len= strlen(extensionName);
cacheExtensionCheckList[extensionName]=false;
if(s != NULL) {
while ((s = strstr (s, extensionName)) != NULL) {
s+= len;
if((*s == ' ') || (*s == '\0')) {
cacheExtensionCheckList[extensionName] = true;
break;
}
}
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("OpenGL Extension [%s] supported status = %d\n",extensionName,cacheExtensionCheckList[extensionName]);
return cacheExtensionCheckList[extensionName];
}
//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;
//}
const char *getGlVersion() {
return reinterpret_cast<const char *>(glGetString(GL_VERSION));
}
const char *getGlRenderer() {
return reinterpret_cast<const char *>(glGetString(GL_RENDERER));
}
const char *getGlVendor() {
return reinterpret_cast<const char *>(glGetString(GL_VENDOR));
}
const char *getGlExtensions() {
return reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS));
}
const char *getGlPlatformExtensions() {
Context *c= GraphicsInterface::getInstance().getCurrentContext();
return getPlatformExtensions(static_cast<ContextGl*>(c)->getPlatformContextGl());
}
int getGlMaxLights() {
int i;
glGetIntegerv(GL_MAX_LIGHTS, (GLint*)&i);
return i;
}
int getGlMaxTextureSize() {
int i;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&i);
return i;
}
int getGlMaxTextureUnits() {
int i;
glGetIntegerv(GL_MAX_TEXTURE_UNITS, (GLint*)&i);
return i;
}
int getGlModelviewMatrixStackDepth() {
int i;
glGetIntegerv(GL_MAX_MODELVIEW_STACK_DEPTH, (GLint*)&i);
return i;
}
int getGlProjectionMatrixStackDepth() {
int i;
glGetIntegerv(GL_MAX_PROJECTION_STACK_DEPTH, (GLint*)&i);
return i;
}
void checkGlExtension(const char *extensionName) {
if(!isGlExtensionSupported(extensionName)){
throw megaglest_runtime_error("OpenGL extension not supported: " + string(extensionName));
}
}
}}}// end namespace
|