File: opengl.cpp

package info (click to toggle)
glest 3.2.2-2
  • links: PTS, VCS
  • area: contrib
  • in suites: squeeze
  • size: 2,800 kB
  • ctags: 6,581
  • sloc: cpp: 32,575; sh: 8,341; makefile: 63
file content (150 lines) | stat: -rw-r--r-- 3,187 bytes parent folder | download | duplicates (2)
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
// ==============================================================
//	This file is part of Glest Shared Library (www.glest.org)
//
//	Copyright (C) 2001-2008 Martio 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 "leak_dumper.h"

using namespace Shared::Platform; 
using namespace std;

namespace Shared{ namespace Graphics{ namespace Gl{

// =====================================================
//	class Globals
// =====================================================

bool isGlExtensionSupported(const char *extensionName){
    const char *s;
	GLint len;
	const GLubyte *extensionStr= glGetString(GL_EXTENSIONS);

	s= reinterpret_cast<const char *>(extensionStr);
	len= strlen(extensionName);

	while ((s = strstr (s, extensionName)) != NULL) {
		s+= len;

		if((*s == ' ') || (*s == '\0')) {
			return true;
		}
	}

	return false;
}

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, &i);
	return i;
}

int getGlMaxTextureSize(){
	int i;
	glGetIntegerv(GL_MAX_TEXTURE_SIZE, &i);
	return i;	
}

int getGlMaxTextureUnits(){
	int i;
	glGetIntegerv(GL_MAX_TEXTURE_UNITS, &i);
	return i;	
}

int getGlModelviewMatrixStackDepth(){
	int i;
	glGetIntegerv(GL_MAX_MODELVIEW_STACK_DEPTH, &i);
	return i;
}

int getGlProjectionMatrixStackDepth(){
	int i;
	glGetIntegerv(GL_MAX_PROJECTION_STACK_DEPTH, &i);
	return i;	
}

void checkGlExtension(const char *extensionName){
	if(!isGlExtensionSupported(extensionName)){
		throw runtime_error("OpenGL extension not supported: " + string(extensionName));
	}
}

}}}// end namespace