From 3b192f51197435010a1d456130fc275c9be244e2 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 8 Jan 2009 11:19:21 +0000 Subject: [PATCH] Added checked from the ARG version of glDraw*Instanced(). --- include/osg/GLExtensions | 32 ++++++++++++++++++++++++++++++++ src/osg/State.cpp | 4 ++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/include/osg/GLExtensions b/include/osg/GLExtensions index 350a4a87e..fb3e4fd37 100644 --- a/include/osg/GLExtensions +++ b/include/osg/GLExtensions @@ -78,6 +78,22 @@ inline void* getGLExtensionFuncPtr(const char *funcName,const char *fallbackFunc return getGLExtensionFuncPtr(fallbackFuncName); } +/** Return the address of the specified OpenGL function. If not found then + * check a second function name, if this fails then return NULL as function is + * 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 *funcName1, const char *funcName2, const char *funcName3) +{ + void* ptr = getGLExtensionFuncPtr(funcName1); + if (ptr) return ptr; + + ptr = getGLExtensionFuncPtr(funcName2); + if (ptr) return ptr; + + return getGLExtensionFuncPtr(funcName3); +} + template T convertPointerType(R src) { @@ -118,6 +134,22 @@ bool setGLExtensionFuncPtr(T& t, const char* str1, const char* 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 true if OpenGL "extension" is supported. * Note: Must only be called within a valid OpenGL context, diff --git a/src/osg/State.cpp b/src/osg/State.cpp index cf6d0a826..99f4434cd 100644 --- a/src/osg/State.cpp +++ b/src/osg/State.cpp @@ -756,8 +756,8 @@ void State::initializeExtensionProcs() setGLExtensionFuncPtr(_glDisableVertexAttribArray, "glDisableVertexAttribArray","glDisableVertexAttribArrayARB"); setGLExtensionFuncPtr(_glBindBuffer, "glBindBuffer","glBindBufferARB"); - setGLExtensionFuncPtr(_glDrawArraysInstanced, "glDrawArraysInstanced","glDrawArraysInstancedEXT"); - setGLExtensionFuncPtr(_glDrawElementsInstanced, "glDrawElementsInstanced","glDrawElementsInstancedEXT"); + setGLExtensionFuncPtr(_glDrawArraysInstanced, "glDrawArraysInstanced","glDrawArraysInstancedARB","glDrawArraysInstancedEXT"); + setGLExtensionFuncPtr(_glDrawElementsInstanced, "glDrawElementsInstanced","glDrawElementsInstancedARB","glDrawElementsInstancedEXT"); if ( osg::getGLVersionNumber() >= 2.0 || osg::isGLExtensionSupported(_contextID,"GL_ARB_vertex_shader") ) {