PageRenderTime 29ms CodeModel.GetById 18ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #ifndef GLH_EXTENSIONS
  16. #define GLH_EXTENSIONS
  17. #include <string.h>
  18. #include <stdio.h>
  19. #ifdef _WIN32
  20. # include <windows.h>
  21. #endif
  22. #ifndef __APPLE__
  23. #include <GL/gl.h>
  24. #endif
  25. #ifdef _WIN32
  26. # include "GL/wglext.h"
  27. #endif
  28. #define CHECK_MEMORY(ptr) \
  29. if (NULL == ptr) { \
  30. printf("Error allocating memory in file %s, line %d\n", __FILE__, __LINE__); \
  31. exit(-1); \
  32. }
  33. #ifdef GLH_EXT_SINGLE_FILE
  34. # define GLH_EXTENSIONS_SINGLE_FILE // have to do this because glh_genext.h unsets GLH_EXT_SINGLE_FILE
  35. #endif
  36. #include "glh_genext.h"
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. #ifdef GLH_EXTENSIONS_SINGLE_FILE
  41. class GLHExts
  42. {
  43. public:
  44. GLHExts()
  45. {
  46. mSysExts = NULL;
  47. // mUnsupportedExts = NULL;
  48. }
  49. ~GLHExts()
  50. {
  51. if (mSysExts)
  52. {
  53. free(mSysExts);
  54. }
  55. // if (mUnsupportedExts)
  56. // {
  57. // free(mUnsupportedExts);
  58. // }
  59. }
  60. char *mSysExts;
  61. // char *mUnsupportedExts;
  62. };
  63. GLHExts gGLHExts;
  64. static int ExtensionExists(const char* extName, const char* sysExts)
  65. {
  66. char *padExtName = (char*)malloc(strlen(extName) + 2);
  67. strcat(strcpy(padExtName, extName), " ");
  68. if (0 == strcmp(extName, "GL_VERSION_1_2")) {
  69. const char *version = (const char*)glGetString(GL_VERSION);
  70. if (strstr(version, "1.0") == version || strstr(version, "1.1") == version) {
  71. return FALSE;
  72. } else {
  73. return TRUE;
  74. }
  75. }
  76. if (strstr(sysExts, padExtName)) {
  77. free(padExtName);
  78. return TRUE;
  79. } else {
  80. free(padExtName);
  81. return FALSE;
  82. }
  83. }
  84. static const char* EatWhiteSpace(const char *str)
  85. {
  86. for (; *str && (' ' == *str || '\t' == *str || '\n' == *str); str++);
  87. return str;
  88. }
  89. static const char* EatNonWhiteSpace(const char *str)
  90. {
  91. for (; *str && (' ' != *str && '\t' != *str && '\n' != *str); str++);
  92. return str;
  93. }
  94. int glh_init_extensions(const char *origReqExts)
  95. {
  96. // Length of requested extensions string
  97. unsigned reqExtsLen;
  98. char *reqExts;
  99. // Ptr for individual extensions within reqExts
  100. char *reqExt;
  101. int success = TRUE;
  102. // build space-padded extension string
  103. if (NULL == gGLHExts.mSysExts) {
  104. const char *extensions = (const char*)glGetString(GL_EXTENSIONS);
  105. int sysExtsLen = (int)strlen(extensions);
  106. const char *winsys_extensions = 0;
  107. int winsysExtsLen = 0;
  108. #ifdef _WIN32
  109. {
  110. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  111. wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
  112. if(wglGetExtensionsStringARB)
  113. {
  114. winsys_extensions = wglGetExtensionsStringARB(wglGetCurrentDC());
  115. winsysExtsLen = (S32)strlen(winsys_extensions);
  116. }
  117. }
  118. #endif
  119. // Add 2 bytes, one for padding space, one for terminating NULL
  120. gGLHExts.mSysExts = (char*)malloc(sysExtsLen + winsysExtsLen + 3);
  121. CHECK_MEMORY(gGLHExts.mSysExts);
  122. strcpy(gGLHExts.mSysExts, extensions);
  123. gGLHExts.mSysExts[sysExtsLen] = ' ';
  124. gGLHExts.mSysExts[sysExtsLen + 1] = 0;
  125. if (winsysExtsLen)
  126. {
  127. strcat(gGLHExts.mSysExts, winsys_extensions);
  128. }
  129. gGLHExts.mSysExts[sysExtsLen + 1 + winsysExtsLen] = ' ';
  130. gGLHExts.mSysExts[sysExtsLen + 1 + winsysExtsLen + 1] = 0;
  131. }
  132. if (NULL == origReqExts)
  133. {
  134. return TRUE;
  135. }
  136. reqExts = strdup(origReqExts);
  137. reqExtsLen = (S32)strlen(reqExts);
  138. /*
  139. if (NULL == gGLHExts.mUnsupportedExts)
  140. {
  141. gGLHExts.mUnsupportedExts = (char*)malloc(reqExtsLen + 1);
  142. }
  143. else if (reqExtsLen > strlen(gGLHExts.mUnsupportedExts))
  144. {
  145. gGLHExts.mUnsupportedExts = (char*)realloc(gGLHExts.mUnsupportedExts, reqExtsLen + 1);
  146. }
  147. CHECK_MEMORY(gGLHExts.mUnsupportedExts);
  148. *gGLHExts.mUnsupportedExts = 0;
  149. */
  150. // Parse requested extension list
  151. for (reqExt = reqExts;
  152. (reqExt = (char*)EatWhiteSpace(reqExt)) && *reqExt;
  153. reqExt = (char*)EatNonWhiteSpace(reqExt))
  154. {
  155. char *extEnd = (char*)EatNonWhiteSpace(reqExt);
  156. char saveChar = *extEnd;
  157. *extEnd = (char)0;
  158. if (!ExtensionExists(reqExt, gGLHExts.mSysExts) ||
  159. !glh_init_extension(reqExt)) {
  160. /*
  161. // add reqExt to end of unsupportedExts
  162. strcat(gGLHExts.mUnsupportedExts, reqExt);
  163. strcat(gGLHExts.mUnsupportedExts, " ");
  164. */
  165. success = FALSE;
  166. }
  167. *extEnd = saveChar;
  168. }
  169. free(reqExts);
  170. return success;
  171. }
  172. const char* glh_get_unsupported_extensions()
  173. {
  174. return "";
  175. // return (const char*)gGLHExts.mUnsupportedExts;
  176. }
  177. #else
  178. int glh_init_extensions(const char *origReqExts);
  179. const char* glh_get_unsupported_extensions();
  180. #endif /* GLH_EXT_SINGLE_FILE */
  181. #ifdef __cplusplus
  182. }
  183. #endif
  184. #endif /* GLH_EXTENSIONS */