Refactored the Texture3D extension setup in osg::Texture3D and gluBuild3DMipmaps and gluBuild3DMipmapLevels.

This commit is contained in:
Robert Osfield 2010-10-08 11:20:56 +00:00
parent d23ce985a1
commit 9984281553
4 changed files with 60 additions and 207 deletions

View File

@ -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

View File

@ -160,17 +160,21 @@ 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; }
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 isCompressedTexSubImage3DSupported() const { return glCompressedTexSubImage3D!=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;
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 );
void gluBuild3DMipmaps( GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *data) const;
GLTexImage3DProc glTexImage3D;
GLTexSubImage3DProc glTexSubImage3D;
CompressedTexImage3DArbProc glCompressedTexImage3D;
CompressedTexSubImage3DArbProc glCompressedTexSubImage3D;
GLCopyTexSubImageProc glCopyTexSubImage3D;
protected:
@ -179,21 +183,6 @@ class OSG_EXPORT Texture3D : public Texture
bool _isTexture3DSupported;
bool _isTexture3DFast;
GLint _maxTexture3DSize;
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;
};
/** Encapsulates queries of extension availability, obtains extension

View File

@ -427,7 +427,8 @@ void Texture3D::applyTexImage3D(GLenum target, Image* image, State& state, GLsiz
numMipmapLevels = 1;
extensions->gluBuild3DMipmaps( target, _internalFormat,
gluBuild3DMipmaps( extensions->glTexImage3D,
target, _internalFormat,
image->s(),image->t(),image->r(),
(GLenum)image->getPixelFormat(), (GLenum)image->getDataType(),
image->data() );
@ -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"<<std::endl;
}
}
void Texture3D::Extensions::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
{
// ::glTexSubImage3D( target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
if (_glTexSubImage3D)
{
_glTexSubImage3D( target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
}
else
{
OSG_WARN<<"Error: glTexSubImage3D not supported by OpenGL driver"<<std::endl;
}
}
void Texture3D::Extensions::glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data) const
{
if (_glCompressedTexImage3D)
{
_glCompressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize, data);
}
else
{
OSG_WARN<<"Error: glCompressedTexImage3D not supported by OpenGL driver"<<std::endl;
}
}
void Texture3D::Extensions::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
{
if (_glCompressedTexSubImage3D)
{
_glCompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
}
else
{
OSG_WARN<<"Error: glCompressedTexImage2D not supported by OpenGL driver"<<std::endl;
}
}
void Texture3D::Extensions::glCopyTexSubImage3D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height ) const
{
// ::glCopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height);
if (_glCopyTexSubImage3D)
{
_glCopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height);
}
else
{
OSG_WARN<<"Error: glCopyTexSubImage3D not supported by OpenGL driver"<<std::endl;
}
}
void Texture3D::Extensions::gluBuild3DMipmaps( GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *data) const
{
// ::gluBuild3DMipmaps(target, internalFormat, width, height, depth, format, type, data);
if (_gluBuild3DMipmaps)
{
_gluBuild3DMipmaps(target, internalFormat, width, height, depth, format, type, data);
}
else
{
OSG_WARN<<"Error: gluBuild3DMipmaps not supported by OpenGL driver"<<std::endl;
}
}

View File

@ -73,7 +73,7 @@ static int gluBuild2DMipmapLevelsCore(GLenum, GLint,
GLsizei, GLsizei,
GLenum, GLenum, GLint, GLint, GLint,
const void *);
static int gluBuild3DMipmapLevelsCore(GLenum, GLint,
static int gluBuild3DMipmapLevelsCore(GLTexImage3DProc gluTexImage3D, GLenum, GLint,
GLsizei, GLsizei, GLsizei,
GLsizei, GLsizei, GLsizei,
GLenum, GLenum, GLint, GLint, GLint,
@ -6635,74 +6635,6 @@ static void halve1DimagePackedPixel(int components,
}
} /* halve1DimagePackedPixel() */
/*===========================================================================*/
// Note from Robert Osfield, follows is a quick hack to windows compiling, will need to
// reactor code to properly manage extension checking platforms/GL targets.
#if defined(_WIN32) || defined(__WIN32__)
#define RESOLVE_3D_TEXTURE_SUPPORT
#endif
#ifdef RESOLVE_3D_TEXTURE_SUPPORT
/*
* This section ensures that GLU 1.3 will load and run on
* a GL 1.1 implementation. It dynamically resolves the
* call to glTexImage3D() which might not be available.
* Or is it might be supported as an extension.
* Contributed by Gerk Huisma <gerk@five-d.demon.nl>.
*/
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 <dlfcn.h>
# include <sys/types.h>
#else
#include <windows.h>
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,8 +8409,8 @@ static int gluBuild3DMipmapLevelsCore(GLenum target, GLint internalFormat,
return 0;
} /* gluBuild3DMipmapLevelsCore() */
GLint GLAPIENTRY
gluBuild3DMipmapLevels(GLenum target, GLint internalFormat,
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,
@ -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,8 +8447,8 @@ gluBuild3DMipmapLevels(GLenum target, GLint internalFormat,
data);
} /* gluBuild3DMipmapLevels() */
GLint GLAPIENTRY
gluBuild3DMipmaps(GLenum target, GLint internalFormat,
GLint GLAPIENTRY gluBuild3DMipmaps(GLTexImage3DProc gluTexImage3D,
GLenum target, GLint internalFormat,
GLsizei width, GLsizei height, GLsizei depth,
GLenum format, GLenum type, const void *data)
{
@ -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,