From 09205544b74551a3609182ceb5d77131efc3d42f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 10 Dec 2014 09:11:17 +0000 Subject: [PATCH] Streamlined the extension functions git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14592 16af8721-9629-0410-8352-f15c8da7e697 --- include/osg/GLExtensions | 53 +++++++++------------------------------- 1 file changed, 12 insertions(+), 41 deletions(-) diff --git a/include/osg/GLExtensions b/include/osg/GLExtensions index cac563a93..fbba8d524 100644 --- a/include/osg/GLExtensions +++ b/include/osg/GLExtensions @@ -71,11 +71,10 @@ extern OSG_EXPORT std::string& getGLExtensionDisableString(); * not supported by OpenGL library. This is used for checking something * like glActiveTexture (which is in OGL1.3) or glActiveTextureARB. */ -inline void* getGLExtensionFuncPtr(const char *funcName,const char *fallbackFuncName) +inline void* getGLExtensionFuncPtr(const char *funcName, const char *fallbackFuncName) { void* ptr = getGLExtensionFuncPtr(funcName); - if (ptr) return ptr; - return getGLExtensionFuncPtr(fallbackFuncName); + return (ptr!=0) ? ptr : getGLExtensionFuncPtr(fallbackFuncName); } /** Return the address of the specified OpenGL function. If not found then @@ -86,12 +85,14 @@ inline void* getGLExtensionFuncPtr(const char *funcName,const char *fallbackFunc inline void* getGLExtensionFuncPtr(const char *funcName1, const char *funcName2, const char *funcName3) { void* ptr = getGLExtensionFuncPtr(funcName1); - if (ptr) return ptr; + return (ptr!=0) ? ptr : getGLExtensionFuncPtr(funcName2, funcName3); +} - ptr = getGLExtensionFuncPtr(funcName2); - if (ptr) return ptr; - - return getGLExtensionFuncPtr(funcName3); +template +bool convertPointer(T& dest, R src) +{ + memcpy(&dest, &src, sizeof(src)); + return src!=0; } template @@ -105,49 +106,19 @@ T convertPointerType(R src) template bool setGLExtensionFuncPtr(T& t, const char* str1) { - void* data = osg::getGLExtensionFuncPtr(str1); - if (data) - { - memcpy(&t, &data, sizeof(T)); - return true; - } - else - { - t = 0; - return false; - } + return convertPointer(t, osg::getGLExtensionFuncPtr(str1)); } template bool setGLExtensionFuncPtr(T& t, const char* str1, const char* str2) { - void* data = osg::getGLExtensionFuncPtr(str1,str2); - if (data) - { - memcpy(&t, &data, sizeof(T)); - return true; - } - else - { - t = 0; - return false; - } + return convertPointer(t, osg::getGLExtensionFuncPtr(str1, str2)); } template bool setGLExtensionFuncPtr(T& t, const char* str1, const char* str2, const char* str3) { - void* data = osg::getGLExtensionFuncPtr(str1,str2,str3); - if (data) - { - memcpy(&t, &data, sizeof(T)); - return true; - } - else - { - t = 0; - return false; - } + return convertPointer(t, osg::getGLExtensionFuncPtr(str1, str2, str3)); } }