| 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield |
|---|
| 2 | * |
|---|
| 3 | * This library is open source and may be redistributed and/or modified under |
|---|
| 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
|---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
|---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
|---|
| 7 | * |
|---|
| 8 | * This library is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * OpenSceneGraph Public License for more details. |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | #ifndef OSG_GLEXTENSIONS |
|---|
| 15 | #define OSG_GLEXTENSIONS 1 |
|---|
| 16 | |
|---|
| 17 | #include <osg/Export> |
|---|
| 18 | #include <stdlib.h> |
|---|
| 19 | #include <string.h> |
|---|
| 20 | #include <string> |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | namespace osg { |
|---|
| 24 | |
|---|
| 25 | /** Return floating-point OpenGL version number. |
|---|
| 26 | * Note: Must only be called within a valid OpenGL context, |
|---|
| 27 | * undefined behavior may occur otherwise. |
|---|
| 28 | */ |
|---|
| 29 | extern OSG_EXPORT float getGLVersionNumber(); |
|---|
| 30 | |
|---|
| 31 | /** Return true if "extension" is contained in "extensionString". |
|---|
| 32 | */ |
|---|
| 33 | extern OSG_EXPORT bool isExtensionInExtensionString(const char *extension, const char *extensionString); |
|---|
| 34 | |
|---|
| 35 | /** Return true if OpenGL "extension" is supported. |
|---|
| 36 | * Note: Must only be called within a valid OpenGL context, |
|---|
| 37 | * undefined behavior may occur otherwise. |
|---|
| 38 | */ |
|---|
| 39 | extern OSG_EXPORT bool isGLExtensionSupported(unsigned int contextID, const char *extension); |
|---|
| 40 | |
|---|
| 41 | /** Return true if OpenGL "extension" or minimum OpenGL version number is supported. |
|---|
| 42 | * Note: Must only be called within a valid OpenGL context, |
|---|
| 43 | * undefined behavior may occur otherwise. |
|---|
| 44 | */ |
|---|
| 45 | extern OSG_EXPORT bool isGLExtensionOrVersionSupported(unsigned int contextID, const char *extension, float requiredGlVersion); |
|---|
| 46 | |
|---|
| 47 | /** Return the address of the specified OpenGL function. |
|---|
| 48 | * Return NULL if function not supported by OpenGL library. |
|---|
| 49 | * Note, glGLExtensionFuncPtr is declared inline so that the code |
|---|
| 50 | * is compiled locally to the calling code. This should get by Windows' |
|---|
| 51 | * dumb implementation of having different GL function ptr's for each |
|---|
| 52 | * library when linked to it. |
|---|
| 53 | */ |
|---|
| 54 | extern OSG_EXPORT void* getGLExtensionFuncPtr(const char *funcName); |
|---|
| 55 | |
|---|
| 56 | /** Set a list of extensions to disable for different OpenGL renderers. This allows |
|---|
| 57 | * OSG applications to work around OpenGL drivers' bugs which are due to problematic extension support. |
|---|
| 58 | * The format of the string is: |
|---|
| 59 | * "GLRendererString : ExtensionName, ExtensionName; GLRenderString2 : ExtensionName;" |
|---|
| 60 | * An example of is : "SUN_XVR1000:GL_EXT_texture_filter_anisotropic" |
|---|
| 61 | * The default setting of GLExtensionDisableString is obtained from the OSG_GL_EXTENSION_DISABLE |
|---|
| 62 | * environmental variable. |
|---|
| 63 | */ |
|---|
| 64 | extern OSG_EXPORT void setGLExtensionDisableString(const std::string& disableString); |
|---|
| 65 | |
|---|
| 66 | /** Get the list of extensions that are disabled for various OpenGL renderers. */ |
|---|
| 67 | extern OSG_EXPORT std::string& getGLExtensionDisableString(); |
|---|
| 68 | |
|---|
| 69 | /** Return the address of the specified OpenGL function. If not found then |
|---|
| 70 | * check a second function name, if this fails then return NULL as function is |
|---|
| 71 | * not supported by OpenGL library. This is used for checking something |
|---|
| 72 | * like glActiveTexture (which is in OGL1.3) or glActiveTextureARB. |
|---|
| 73 | */ |
|---|
| 74 | inline void* getGLExtensionFuncPtr(const char *funcName,const char *fallbackFuncName) |
|---|
| 75 | { |
|---|
| 76 | void* ptr = getGLExtensionFuncPtr(funcName); |
|---|
| 77 | if (ptr) return ptr; |
|---|
| 78 | return getGLExtensionFuncPtr(fallbackFuncName); |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | /** Return the address of the specified OpenGL function. If not found then |
|---|
| 82 | * check a second function name, if this fails then return NULL as function is |
|---|
| 83 | * not supported by OpenGL library. This is used for checking something |
|---|
| 84 | * like glActiveTexture (which is in OGL1.3) or glActiveTextureARB. |
|---|
| 85 | */ |
|---|
| 86 | inline void* getGLExtensionFuncPtr(const char *funcName1, const char *funcName2, const char *funcName3) |
|---|
| 87 | { |
|---|
| 88 | void* ptr = getGLExtensionFuncPtr(funcName1); |
|---|
| 89 | if (ptr) return ptr; |
|---|
| 90 | |
|---|
| 91 | ptr = getGLExtensionFuncPtr(funcName2); |
|---|
| 92 | if (ptr) return ptr; |
|---|
| 93 | |
|---|
| 94 | return getGLExtensionFuncPtr(funcName3); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | template<typename T, typename R> |
|---|
| 98 | T convertPointerType(R src) |
|---|
| 99 | { |
|---|
| 100 | T dest; |
|---|
| 101 | memcpy(&dest, &src, sizeof(src)); |
|---|
| 102 | return dest; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | template<typename T> |
|---|
| 106 | bool setGLExtensionFuncPtr(T& t, const char* str1) |
|---|
| 107 | { |
|---|
| 108 | void* data = osg::getGLExtensionFuncPtr(str1); |
|---|
| 109 | if (data) |
|---|
| 110 | { |
|---|
| 111 | memcpy(&t, &data, sizeof(T)); |
|---|
| 112 | return true; |
|---|
| 113 | } |
|---|
| 114 | else |
|---|
| 115 | { |
|---|
| 116 | t = 0; |
|---|
| 117 | return false; |
|---|
| 118 | } |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | template<typename T> |
|---|
| 122 | bool setGLExtensionFuncPtr(T& t, const char* str1, const char* str2) |
|---|
| 123 | { |
|---|
| 124 | void* data = osg::getGLExtensionFuncPtr(str1,str2); |
|---|
| 125 | if (data) |
|---|
| 126 | { |
|---|
| 127 | memcpy(&t, &data, sizeof(T)); |
|---|
| 128 | return true; |
|---|
| 129 | } |
|---|
| 130 | else |
|---|
| 131 | { |
|---|
| 132 | t = 0; |
|---|
| 133 | return false; |
|---|
| 134 | } |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | template<typename T> |
|---|
| 138 | bool setGLExtensionFuncPtr(T& t, const char* str1, const char* str2, const char* str3) |
|---|
| 139 | { |
|---|
| 140 | void* data = osg::getGLExtensionFuncPtr(str1,str2,str3); |
|---|
| 141 | if (data) |
|---|
| 142 | { |
|---|
| 143 | memcpy(&t, &data, sizeof(T)); |
|---|
| 144 | return true; |
|---|
| 145 | } |
|---|
| 146 | else |
|---|
| 147 | { |
|---|
| 148 | t = 0; |
|---|
| 149 | return false; |
|---|
| 150 | } |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | #endif |
|---|