From db70c95d247fd62f764b30f4c05ce2f5d90be439 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 26 Aug 2002 10:24:01 +0000 Subject: [PATCH] Updated Texture3D to use extension checking to get the relevant 3d texturing extensions. --- NEWS | 2 ++ include/osg/GLExtensions | 32 ++++++++++++++++++++++++ src/osg/GLExtensions.cpp | 41 ++++++++++++++++++++++++++++++ src/osg/Texture3D.cpp | 54 ++++++++++++++++++++++++++++++++-------- 4 files changed, 118 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index 863ba3f24..ba8555d9f 100644 --- a/NEWS +++ b/NEWS @@ -30,6 +30,8 @@ OSG News (most significant items from ChangeLog) osg::DOFTransformNode implemented. osg::AnimationPath improved. + + Support for writing osg::Image's to .rgb format added. July 2002 - OpenSceneGraph-0.9.0.tar.gz diff --git a/include/osg/GLExtensions b/include/osg/GLExtensions index 486649b2f..ec6ca42c8 100644 --- a/include/osg/GLExtensions +++ b/include/osg/GLExtensions @@ -70,6 +70,38 @@ inline void* getGLExtensionFuncPtr(const char *funcName,const char *fallbackFunc return getGLExtensionFuncPtr(fallbackFuncName); } +/** return true if OpenGL "extension" is supported. + * note: Must only called within a valid OpenGL context, + * undefined behavior may occur otherwise. + */ +SG_EXPORT extern const bool isGLUExtensionSupported(const char *extension); + +inline void* getGLUExtensionFuncPtr(const char *funcName) +{ +#if defined(WIN32) + return wglGetProcAddress(funcName); +#elif defined(__DARWIN_OSX__) + std::string temp( "_" ); + temp += funcName; // Mac OS X prepends an underscore on function names + if ( NSIsSymbolNameDefined( temp.c_str() ) ) + { + NSSymbol symbol = NSLookupAndBindSymbol( temp.c_str() ); + return NSAddressOfSymbol( symbol ); + } else + return NULL; +#else // all other unixes + // Note: although we use shl_load() etc. for Plugins on HP-UX, it's + // not neccessary here since we only used them because library + // intialization was not taking place with dlopen() which renders + // Plugins useless on HP-UX. + static void *lib = dlopen("libGLU.so", RTLD_LAZY); + if (lib) + return dlsym(lib, funcName); + else + return NULL; +#endif +} + } #endif diff --git a/src/osg/GLExtensions.cpp b/src/osg/GLExtensions.cpp index 2546c3f71..e863ed9ca 100644 --- a/src/osg/GLExtensions.cpp +++ b/src/osg/GLExtensions.cpp @@ -1,5 +1,6 @@ #include +#include #include #include @@ -51,3 +52,43 @@ const bool osg::isGLExtensionSupported(const char *extension) return result; } + +const bool osg::isGLUExtensionSupported(const char *extension) +{ + typedef std::set ExtensionSet; + static ExtensionSet s_extensionSet; + static const char* s_extensions = NULL; + if (s_extensions==NULL) + { + // get the extension list from OpenGL. + s_extensions = (const char*)gluGetString(GL_EXTENSIONS); + if (s_extensions==NULL) return false; + + // insert the ' ' delimiated extensions words into the extensionSet. + const char *startOfWord = s_extensions; + const char *endOfWord; + while ((endOfWord = strchr(startOfWord,' '))!=NULL) + { + s_extensionSet.insert(std::string(startOfWord,endOfWord)); + startOfWord = endOfWord+1; + } + if (*startOfWord!=0) s_extensionSet.insert(std::string(startOfWord)); + + osg::notify(INFO)<<"OpenGL extensions supported by installed OpenGL drivers are:"< #include -#define TEMPORARY_COMMENT_OUT_WHILE_ESTABLISHING_X_PLATFORM_SUPPORT_FOR_3D_TEXTURES +#include + +typedef void (APIENTRY * GLTexImage3DProc) ( GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRY * GLTexSubImage3DProc) ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRY * GLCopyTexSubImageProc) ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height ); +typedef void (APIENTRY * GLUBuild3DMipMapsProc) ( GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *data); + using namespace osg; @@ -92,6 +98,14 @@ void Texture3D::setImage(Image* image) void Texture3D::apply(State& state) const { + static bool s_texturing_supported = strncmp((const char*)glGetString(GL_VERSION),"1.2",3)>=0 || + isGLExtensionSupported("GL_EXT_texture3D"); + + if (s_texturing_supported) + { + notify(WARN)<<"Warning: Texture3D::apply(..) failed, 3D texturing is not support by your OpenGL drivers."<data()) return; + static GLTexImage3DProc s_glTexImage3D = (GLTexImage3DProc) getGLExtensionFuncPtr("glTexImage3D","glTexImage3DEXT"); + if (!s_glTexImage3D) + { + notify(WARN) << "Warning:: Texture3D::applyTexImage3D(..) failed, 3D texturing not supported by your OpenGL drivers."<ensureValidSizeForTexturing(); glPixelStorei(GL_UNPACK_ALIGNMENT,image->getPacking()); + + if( _min_filter == LINEAR || _min_filter == NEAREST ) { numMimpmapLevels = 1; - glTexImage3D( target, 0, _internalFormat, + s_glTexImage3D( target, 0, _internalFormat, image->s(), image->t(), image->r(), 0, (GLenum)image->getPixelFormat(), (GLenum)image->getDataType(), @@ -201,9 +222,16 @@ void Texture3D::applyTexImage3D(GLenum target, Image* image, State& state, GLsiz if(!image->isMipmap()) { + static GLUBuild3DMipMapsProc s_gluBuild3DMipmaps = (GLUBuild3DMipMapsProc) getGLUExtensionFuncPtr("gluBuild3DMipmaps"); + if (!s_gluBuild3DMipmaps) + { + notify(WARN) << "Warning:: Texture3D::applyTexImage3D(..) failed, gluBuild3DMipmaps not supported by your OpenGL drivers."<s(),image->t(),image->r(), (GLenum)image->getPixelFormat(), (GLenum)image->getDataType(), image->data() ); @@ -227,7 +255,7 @@ void Texture3D::applyTexImage3D(GLenum target, Image* image, State& state, GLsiz if (depth == 0) depth = 1; - glTexImage3D( target, k, _internalFormat, + s_glTexImage3D( target, k, _internalFormat, width, height, depth, 0, (GLenum)image->getPixelFormat(), (GLenum)image->getDataType(), @@ -244,14 +272,19 @@ void Texture3D::applyTexImage3D(GLenum target, Image* image, State& state, GLsiz inwidth = image->s(); inheight = image->t(); indepth = image->r(); - -#endif // TEMPORARY_COMMENT_OUT_WHILE_ESTABLISHING_X_PLATFORM_SUPPORT_FOR_3D_TEXTURES } void Texture3D::copyTexSubImage3D(State& state, int xoffset, int yoffset, int zoffset, int x, int y, int width, int height ) { -#ifndef TEMPORARY_COMMENT_OUT_WHILE_ESTABLISHING_X_PLATFORM_SUPPORT_FOR_3D_TEXTURES + static GLCopyTexSubImageProc s_glCopyTexSubImage3D = (GLCopyTexSubImageProc) getGLExtensionFuncPtr("glCopyTexSubImage3D","glCopyTexSubImage3DEXT"); + if (!s_glCopyTexSubImage3D) + { + notify(WARN) << "Warning:: Texture3D::copyTexSubImage3D(..) failed, 3D texture copy sub image not supported by your OpenGL drivers."<