PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llwindow/GL/glh_extensions.h

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