diff --git a/include/osg/GLU b/include/osg/GLU index 6a98f7f2b..27c513a95 100644 --- a/include/osg/GLU +++ b/include/osg/GLU @@ -67,8 +67,14 @@ extern OSG_EXPORT GLint gluBuild1DMipmapLevels (GLenum target, GLint internalFor extern OSG_EXPORT GLint gluBuild1DMipmaps (GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void *data); extern OSG_EXPORT GLint gluBuild2DMipmapLevels (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void *data); extern OSG_EXPORT GLint gluBuild2DMipmaps (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *data); -extern OSG_EXPORT GLint gluBuild3DMipmapLevels (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void *data); -extern OSG_EXPORT GLint gluBuild3DMipmaps (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *data); + +typedef void (GL_APIENTRY * GLTexImage3DProc) ( GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); + +/** Small variation on normal gluBuild3DMipmapLevels as we pass in the function pointer to glTexImage3D rather than rely on GLU style querry for this functon pointer.*/ +extern OSG_EXPORT GLint gluBuild3DMipmapLevels (GLTexImage3DProc glTextImage3DProc, GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void *data); + +/** Small variation on normal gluBuild3DMipmapLevels as we pass in the function pointer to glTexImage3D rather than rely on GLU style querry for this functon pointer.*/ +extern OSG_EXPORT GLint gluBuild3DMipmaps (GLTexImage3DProc glTextImage3DProc, GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *data); /* ErrorCode */ #define GLU_INVALID_ENUM 100900 diff --git a/include/osg/Texture3D b/include/osg/Texture3D index 4362636d8..c8c0c88f3 100644 --- a/include/osg/Texture3D +++ b/include/osg/Texture3D @@ -160,40 +160,29 @@ class OSG_EXPORT Texture3D : public Texture void setMaxTexture3DSize(GLint maxsize) { _maxTexture3DSize=maxsize; } GLint maxTexture3DSize() const { return _maxTexture3DSize; } - void glTexImage3D( GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels) const; - void glTexSubImage3D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels) const; - void glCopyTexSubImage3D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height ) const; - - bool isCompressedTexImage3DSupported() const { return _glCompressedTexImage3D!=0; } - void glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data) const; + bool isCompressedTexImage3DSupported() const { return glCompressedTexImage3D!=0; } - bool isCompressedTexSubImage3DSupported() const { return _glCompressedTexSubImage3D!=0; } - void glCompressedTexSubImage3D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data ) const; - - void gluBuild3DMipmaps( GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *data) const; - - protected: - - ~Extensions() {} - - bool _isTexture3DSupported; - bool _isTexture3DFast; - GLint _maxTexture3DSize; + bool isCompressedTexSubImage3DSupported() const { return glCompressedTexSubImage3D!=0; } typedef void (GL_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 (GL_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 (GL_APIENTRY * CompressedTexImage3DArbProc) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); typedef void (GL_APIENTRY * CompressedTexSubImage3DArbProc) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); typedef void (GL_APIENTRY * GLCopyTexSubImageProc) ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height ); - typedef void (GL_APIENTRY * GLUBuild3DMipMapsProc) ( GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *data); - GLTexImage3DProc _glTexImage3D; - GLTexSubImage3DProc _glTexSubImage3D; - CompressedTexImage3DArbProc _glCompressedTexImage3D; - CompressedTexSubImage3DArbProc _glCompressedTexSubImage3D; - GLCopyTexSubImageProc _glCopyTexSubImage3D; - GLUBuild3DMipMapsProc _gluBuild3DMipmaps; + GLTexImage3DProc glTexImage3D; + GLTexSubImage3DProc glTexSubImage3D; + CompressedTexImage3DArbProc glCompressedTexImage3D; + CompressedTexSubImage3DArbProc glCompressedTexSubImage3D; + GLCopyTexSubImageProc glCopyTexSubImage3D; + protected: + + ~Extensions() {} + + bool _isTexture3DSupported; + bool _isTexture3DFast; + GLint _maxTexture3DSize; }; /** Encapsulates queries of extension availability, obtains extension diff --git a/src/osg/Texture3D.cpp b/src/osg/Texture3D.cpp index 0cb55fed6..3d88bc034 100644 --- a/src/osg/Texture3D.cpp +++ b/src/osg/Texture3D.cpp @@ -427,10 +427,11 @@ void Texture3D::applyTexImage3D(GLenum target, Image* image, State& state, GLsiz numMipmapLevels = 1; - extensions->gluBuild3DMipmaps( target, _internalFormat, - image->s(),image->t(),image->r(), - (GLenum)image->getPixelFormat(), (GLenum)image->getDataType(), - image->data() ); + gluBuild3DMipmaps( extensions->glTexImage3D, + target, _internalFormat, + image->s(),image->t(),image->r(), + (GLenum)image->getPixelFormat(), (GLenum)image->getDataType(), + image->data() ); } else @@ -578,10 +579,11 @@ Texture3D::Extensions::Extensions(const Extensions& rhs): _isTexture3DFast = rhs._isTexture3DFast; _maxTexture3DSize = rhs._maxTexture3DSize; - _glTexImage3D = rhs._glTexImage3D; - _glTexSubImage3D = rhs._glTexSubImage3D; - _glCopyTexSubImage3D = rhs._glCopyTexSubImage3D; - _gluBuild3DMipmaps = rhs._gluBuild3DMipmaps; + glTexImage3D = rhs.glTexImage3D; + glTexSubImage3D = rhs.glTexSubImage3D; + glCompressedTexImage3D = rhs.glCompressedTexImage3D; + glCompressedTexSubImage3D = rhs.glCompressedTexSubImage3D; + glCopyTexSubImage3D = rhs.glCopyTexSubImage3D; } void Texture3D::Extensions::lowestCommonDenominator(const Extensions& rhs) @@ -590,12 +592,11 @@ void Texture3D::Extensions::lowestCommonDenominator(const Extensions& rhs) if (!rhs._isTexture3DFast) _isTexture3DFast = false; if (rhs._maxTexture3DSize<_maxTexture3DSize) _maxTexture3DSize = rhs._maxTexture3DSize; - if (!rhs._glTexImage3D) _glTexImage3D = 0; - if (!rhs._glTexSubImage3D) _glTexSubImage3D = 0; - if (!rhs._glCompressedTexImage3D) _glTexImage3D = 0; - if (!rhs._glCompressedTexSubImage3D) _glTexSubImage3D = 0; - if (!rhs._glCopyTexSubImage3D) _glCopyTexSubImage3D = 0; - if (!rhs._gluBuild3DMipmaps) _gluBuild3DMipmaps = 0; + if (!rhs.glTexImage3D) glTexImage3D = 0; + if (!rhs.glTexSubImage3D) glTexSubImage3D = 0; + if (!rhs.glCompressedTexImage3D) glCompressedTexImage3D = 0; + if (!rhs.glCompressedTexSubImage3D) glCompressedTexSubImage3D = 0; + if (!rhs.glCopyTexSubImage3D) glCopyTexSubImage3D = 0; } void Texture3D::Extensions::setupGLExtensions(unsigned int contextID) @@ -607,87 +608,10 @@ void Texture3D::Extensions::setupGLExtensions(unsigned int contextID) glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &_maxTexture3DSize); - setGLExtensionFuncPtr(_glTexImage3D,"glTexImage3D","glTexImage3DEXT"); - setGLExtensionFuncPtr(_glTexSubImage3D,"glTexSubImage3D","glTexSubImage3DEXT"); - setGLExtensionFuncPtr(_glCompressedTexImage3D,"glCompressedTexImage3D","glCompressedTexImage3DARB"); - setGLExtensionFuncPtr(_glCompressedTexSubImage3D,"glCompressedTexSubImage3D","glCompressedTexSubImage3DARB"); - setGLExtensionFuncPtr(_glCopyTexSubImage3D,"glCopyTexSubImage3D","glCopyTexSubImage3DEXT"); - setGLExtensionFuncPtr(_gluBuild3DMipmaps,"gluBuild3DMipmaps"); + setGLExtensionFuncPtr(glTexImage3D,"glTexImage3D","glTexImage3DEXT"); + setGLExtensionFuncPtr(glTexSubImage3D,"glTexSubImage3D","glTexSubImage3DEXT"); + setGLExtensionFuncPtr(glCompressedTexImage3D,"glCompressedTexImage3D","glCompressedTexImage3DARB"); + setGLExtensionFuncPtr(glCompressedTexSubImage3D,"glCompressedTexSubImage3D","glCompressedTexSubImage3DARB"); + setGLExtensionFuncPtr(glCopyTexSubImage3D,"glCopyTexSubImage3D","glCopyTexSubImage3DEXT"); } - -void Texture3D::Extensions::glTexImage3D( GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels) const -{ -// ::glTexImage3D( target, level, internalFormat, width, height, depth, border, format, type, pixels); - if (_glTexImage3D) - { - _glTexImage3D( target, level, internalFormat, width, height, depth, border, format, type, pixels); - } - else - { - OSG_WARN<<"Error: glTexImage3D not supported by OpenGL driver"<. - */ - -typedef void (GLAPIENTRY *TexImage3Dproc)( GLenum target, GLint level, - GLenum internalFormat, - GLsizei width, GLsizei height, - GLsizei depth, GLint border, - GLenum format, GLenum type, - const GLvoid *pixels ); - -static TexImage3Dproc pTexImage3D = 0; - -#if !defined(_WIN32) && !defined(__WIN32__) -# include -# include -#else - #include - WINGDIAPI PROC WINAPI wglGetProcAddress(LPCSTR); -#endif - -static void gluTexImage3D( GLenum target, GLint level, - GLenum internalFormat, - GLsizei width, GLsizei height, - GLsizei depth, GLint border, - GLenum format, GLenum type, - const GLvoid *pixels ) -{ - if (!pTexImage3D) { -#if defined(_WIN32) || defined(__WIN32__) - pTexImage3D = (TexImage3Dproc) wglGetProcAddress("glTexImage3D"); - if (!pTexImage3D) - pTexImage3D = (TexImage3Dproc) wglGetProcAddress("glTexImage3DEXT"); -#else - void *libHandle = dlopen("libgl.so", RTLD_LAZY); - pTexImage3D = TexImage3Dproc) dlsym(libHandle, "glTexImage3D" ); - if (!pTexImage3D) - pTexImage3D = (TexImage3Dproc) dlsym(libHandle,"glTexImage3DEXT"); - dlclose(libHandle); -#endif - } - - /* Now call glTexImage3D */ - if (pTexImage3D) - pTexImage3D(target, level, internalFormat, width, height, - depth, border, format, type, pixels); -} - -#else - -/* Only bind to a GL 1.2 implementation: */ -#define gluTexImage3D glTexImage3D - -#endif - static GLint imageSize3D(GLint width, GLint height, GLint depth, GLenum format, GLenum type) { @@ -7442,7 +7374,8 @@ int gluScaleImage3D(GLenum format, } /* gluScaleImage3D() */ -static void closestFit3D(GLenum target, GLint width, GLint height, GLint depth, +static void closestFit3D(GLTexImage3DProc gluTexImage3D, + GLenum target, GLint width, GLint height, GLint depth, GLint internalFormat, GLenum format, GLenum type, GLint *newWidth, GLint *newHeight, GLint *newDepth) { @@ -7752,7 +7685,8 @@ static void halveImagePackedPixel3D(int components, } /* halveImagePackedPixel3D() */ -static int gluBuild3DMipmapLevelsCore(GLenum target, GLint internalFormat, +static int gluBuild3DMipmapLevelsCore(GLTexImage3DProc gluTexImage3D, + GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, @@ -8475,12 +8409,12 @@ static int gluBuild3DMipmapLevelsCore(GLenum target, GLint internalFormat, return 0; } /* gluBuild3DMipmapLevelsCore() */ -GLint GLAPIENTRY -gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, - GLsizei width, GLsizei height, GLsizei depth, - GLenum format, GLenum type, - GLint userLevel, GLint baseLevel, GLint maxLevel, - const void *data) +GLint GLAPIENTRY gluBuild3DMipmapLevels(GLTexImage3DProc gluTexImage3D, + GLenum target, GLint internalFormat, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, + GLint userLevel, GLint baseLevel, GLint maxLevel, + const void *data) { int level, levels; @@ -8505,7 +8439,7 @@ gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, if (!isLegalLevels(userLevel,baseLevel,maxLevel,levels)) return GLU_INVALID_VALUE; - return gluBuild3DMipmapLevelsCore(target, internalFormat, + return gluBuild3DMipmapLevelsCore(gluTexImage3D, target, internalFormat, width, height, depth, width, height, depth, format, type, @@ -8513,10 +8447,10 @@ gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, data); } /* gluBuild3DMipmapLevels() */ -GLint GLAPIENTRY -gluBuild3DMipmaps(GLenum target, GLint internalFormat, - GLsizei width, GLsizei height, GLsizei depth, - GLenum format, GLenum type, const void *data) +GLint GLAPIENTRY gluBuild3DMipmaps(GLTexImage3DProc gluTexImage3D, + GLenum target, GLint internalFormat, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, const void *data) { GLint widthPowerOf2, heightPowerOf2, depthPowerOf2; int level, levels; @@ -8532,7 +8466,7 @@ gluBuild3DMipmaps(GLenum target, GLint internalFormat, return GLU_INVALID_ENUM; } - closestFit3D(target,width,height,depth,internalFormat,format,type, + closestFit3D(gluTexImage3D, target,width,height,depth,internalFormat,format,type, &widthPowerOf2,&heightPowerOf2,&depthPowerOf2); levels = computeLog(widthPowerOf2); @@ -8541,7 +8475,7 @@ gluBuild3DMipmaps(GLenum target, GLint internalFormat, level = computeLog(depthPowerOf2); if (level > levels) levels=level; - return gluBuild3DMipmapLevelsCore(target, internalFormat, + return gluBuild3DMipmapLevelsCore(gluTexImage3D, target, internalFormat, width, height, depth, widthPowerOf2, heightPowerOf2, depthPowerOf2,