aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llwindow/GL/glh_extensions.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-09-06 18:24:57 -0500
committerJacek Antonelli2008-09-06 18:25:07 -0500
commit798d367d54a6c6379ad355bd8345fa40e31e7fe9 (patch)
tree1921f1708cd0240648c97bc02df2c2ab5f2fc41e /linden/indra/llwindow/GL/glh_extensions.h
parentSecond Life viewer sources 1.20.15 (diff)
downloadmeta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.zip
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.gz
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.bz2
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.xz
Second Life viewer sources 1.21.0-RC
Diffstat (limited to 'linden/indra/llwindow/GL/glh_extensions.h')
-rw-r--r--linden/indra/llwindow/GL/glh_extensions.h207
1 files changed, 207 insertions, 0 deletions
diff --git a/linden/indra/llwindow/GL/glh_extensions.h b/linden/indra/llwindow/GL/glh_extensions.h
new file mode 100644
index 0000000..b936b5d
--- /dev/null
+++ b/linden/indra/llwindow/GL/glh_extensions.h
@@ -0,0 +1,207 @@
1/*
2 * glh_extensions.h
3 * From nVidia Corporation, downloaded 2006-12-18 from:
4 * http://developer.nvidia.com/attach/8196
5 * ("NVParse Library with Source (.zip) (2390 KB)")
6 *
7 * License (quoted from license_info.txt in aforementioned file):
8 * "The files bison.exe, bison.simple, and flex.exe are covered by
9 * the GPL. All other files in this distribution can be used however
10 * you want."
11 */
12
13#ifndef GLH_EXTENSIONS
14#define GLH_EXTENSIONS
15
16#include <string.h>
17#include <stdio.h>
18
19#ifdef _WIN32
20# include <windows.h>
21#endif
22
23#ifndef __APPLE__
24#include <GL/gl.h>
25#endif
26
27#ifdef _WIN32
28# include "GL/wglext.h"
29#endif
30
31#define CHECK_MEMORY(ptr) \
32 if (NULL == ptr) { \
33 printf("Error allocating memory in file %s, line %d\n", __FILE__, __LINE__); \
34 exit(-1); \
35 }
36
37#ifdef GLH_EXT_SINGLE_FILE
38# define GLH_EXTENSIONS_SINGLE_FILE // have to do this because glh_genext.h unsets GLH_EXT_SINGLE_FILE
39#endif
40
41#include "glh_genext.h"
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47#ifdef GLH_EXTENSIONS_SINGLE_FILE
48
49class GLHExts
50{
51public:
52 GLHExts()
53 {
54 mSysExts = NULL;
55// mUnsupportedExts = NULL;
56 }
57 ~GLHExts()
58 {
59 if (mSysExts)
60 {
61 free(mSysExts);
62 }
63// if (mUnsupportedExts)
64// {
65// free(mUnsupportedExts);
66// }
67 }
68 char *mSysExts;
69// char *mUnsupportedExts;
70};
71
72GLHExts gGLHExts;
73
74static int ExtensionExists(const char* extName, const char* sysExts)
75{
76 char *padExtName = (char*)malloc(strlen(extName) + 2);
77 strcat(strcpy(padExtName, extName), " ");
78
79 if (0 == strcmp(extName, "GL_VERSION_1_2")) {
80 const char *version = (const char*)glGetString(GL_VERSION);
81 if (strstr(version, "1.0") == version || strstr(version, "1.1") == version) {
82 return FALSE;
83 } else {
84 return TRUE;
85 }
86 }
87 if (strstr(sysExts, padExtName)) {
88 free(padExtName);
89 return TRUE;
90 } else {
91 free(padExtName);
92 return FALSE;
93 }
94}
95
96static const char* EatWhiteSpace(const char *str)
97{
98 for (; *str && (' ' == *str || '\t' == *str || '\n' == *str); str++);
99 return str;
100}
101
102static const char* EatNonWhiteSpace(const char *str)
103{
104 for (; *str && (' ' != *str && '\t' != *str && '\n' != *str); str++);
105 return str;
106}
107
108
109int glh_init_extensions(const char *origReqExts)
110{
111 // Length of requested extensions string
112 unsigned reqExtsLen;
113 char *reqExts;
114 // Ptr for individual extensions within reqExts
115 char *reqExt;
116 int success = TRUE;
117
118 // build space-padded extension string
119 if (NULL == gGLHExts.mSysExts) {
120 const char *extensions = (const char*)glGetString(GL_EXTENSIONS);
121 int sysExtsLen = (int)strlen(extensions);
122 const char *winsys_extensions = 0;
123 int winsysExtsLen = 0;
124#ifdef _WIN32
125 {
126 PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
127 wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
128 if(wglGetExtensionsStringARB)
129 {
130 winsys_extensions = wglGetExtensionsStringARB(wglGetCurrentDC());
131 winsysExtsLen = (S32)strlen(winsys_extensions);
132 }
133 }
134#endif
135 // Add 2 bytes, one for padding space, one for terminating NULL
136 gGLHExts.mSysExts = (char*)malloc(sysExtsLen + winsysExtsLen + 3);
137 CHECK_MEMORY(gGLHExts.mSysExts);
138 strcpy(gGLHExts.mSysExts, extensions);
139 gGLHExts.mSysExts[sysExtsLen] = ' ';
140 gGLHExts.mSysExts[sysExtsLen + 1] = 0;
141 if (winsysExtsLen)
142 {
143 strcat(gGLHExts.mSysExts, winsys_extensions);
144 }
145 gGLHExts.mSysExts[sysExtsLen + 1 + winsysExtsLen] = ' ';
146 gGLHExts.mSysExts[sysExtsLen + 1 + winsysExtsLen + 1] = 0;
147 }
148
149 if (NULL == origReqExts)
150 {
151 return TRUE;
152 }
153 reqExts = strdup(origReqExts);
154 reqExtsLen = (S32)strlen(reqExts);
155 /*
156 if (NULL == gGLHExts.mUnsupportedExts)
157 {
158 gGLHExts.mUnsupportedExts = (char*)malloc(reqExtsLen + 1);
159 }
160 else if (reqExtsLen > strlen(gGLHExts.mUnsupportedExts))
161 {
162 gGLHExts.mUnsupportedExts = (char*)realloc(gGLHExts.mUnsupportedExts, reqExtsLen + 1);
163 }
164 CHECK_MEMORY(gGLHExts.mUnsupportedExts);
165 *gGLHExts.mUnsupportedExts = 0;
166 */
167
168 // Parse requested extension list
169 for (reqExt = reqExts;
170 (reqExt = (char*)EatWhiteSpace(reqExt)) && *reqExt;
171 reqExt = (char*)EatNonWhiteSpace(reqExt))
172 {
173 char *extEnd = (char*)EatNonWhiteSpace(reqExt);
174 char saveChar = *extEnd;
175 *extEnd = (char)0;
176
177 if (!ExtensionExists(reqExt, gGLHExts.mSysExts) ||
178 !glh_init_extension(reqExt)) {
179 /*
180 // add reqExt to end of unsupportedExts
181 strcat(gGLHExts.mUnsupportedExts, reqExt);
182 strcat(gGLHExts.mUnsupportedExts, " ");
183 */
184 success = FALSE;
185 }
186 *extEnd = saveChar;
187 }
188 free(reqExts);
189 return success;
190}
191
192const char* glh_get_unsupported_extensions()
193{
194 return "";
195// return (const char*)gGLHExts.mUnsupportedExts;
196}
197
198#else
199int glh_init_extensions(const char *origReqExts);
200const char* glh_get_unsupported_extensions();
201#endif /* GLH_EXT_SINGLE_FILE */
202
203#ifdef __cplusplus
204}
205#endif
206
207#endif /* GLH_EXTENSIONS */