Updated Texture3D to use extension checking to get the relevant 3d texturing
extensions.
This commit is contained in:
parent
0f0b32f43b
commit
db70c95d24
2
NEWS
2
NEWS
@ -31,6 +31,8 @@ OSG News (most significant items from ChangeLog)
|
||||
|
||||
osg::AnimationPath improved.
|
||||
|
||||
Support for writing osg::Image's to .rgb format added.
|
||||
|
||||
July 2002 - OpenSceneGraph-0.9.0.tar.gz
|
||||
|
||||
>>> OpenSceneGraph goes beta - Multitexturing, Occlusion Culling, Particles and much more added!
|
||||
|
@ -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
|
||||
|
@ -1,5 +1,6 @@
|
||||
|
||||
#include <osg/GL>
|
||||
#include <osg/GLU>
|
||||
#include <osg/GLExtensions>
|
||||
#include <osg/Notify>
|
||||
|
||||
@ -51,3 +52,43 @@ const bool osg::isGLExtensionSupported(const char *extension)
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const bool osg::isGLUExtensionSupported(const char *extension)
|
||||
{
|
||||
typedef std::set<std::string> 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:"<<std::endl;
|
||||
for(ExtensionSet::iterator itr=s_extensionSet.begin();
|
||||
itr!=s_extensionSet.end();
|
||||
++itr)
|
||||
{
|
||||
osg::notify(INFO)<<" "<<*itr<<std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// true if extension found in extensionSet.
|
||||
bool result = s_extensionSet.find(extension)!=s_extensionSet.end();
|
||||
|
||||
if (result) osg::notify(INFO)<<"OpenGL utility library extension '"<<extension<<"' is supported."<<std::endl;
|
||||
else osg::notify(INFO)<<"OpenGL utility library extension '"<<extension<<"' is not supported."<<std::endl;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -4,7 +4,13 @@
|
||||
#include <osg/GLU>
|
||||
#include <osg/Notify>
|
||||
|
||||
#define TEMPORARY_COMMENT_OUT_WHILE_ESTABLISHING_X_PLATFORM_SUPPORT_FOR_3D_TEXTURES
|
||||
#include <string.h>
|
||||
|
||||
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."<<std::endl;
|
||||
}
|
||||
|
||||
// get the contextID (user defined ID of 0 upwards) for the
|
||||
// current OpenGL context.
|
||||
const uint contextID = state.getContextID();
|
||||
@ -158,12 +172,17 @@ void Texture3D::computeInternalFormat() const
|
||||
|
||||
void Texture3D::applyTexImage3D(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight, GLsizei& indepth, GLsizei& numMimpmapLevels) const
|
||||
{
|
||||
#ifndef TEMPORARY_COMMENT_OUT_WHILE_ESTABLISHING_X_PLATFORM_SUPPORT_FOR_3D_TEXTURES
|
||||
|
||||
// if we don't have a valid image we can't create a texture!
|
||||
if (!image || !image->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."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// get the contextID (user defined ID of 0 upwards) for the
|
||||
// current OpenGL context.
|
||||
const uint contextID = state.getContextID();
|
||||
@ -187,10 +206,12 @@ void Texture3D::applyTexImage3D(GLenum target, Image* image, State& state, GLsiz
|
||||
|
||||
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."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
numMimpmapLevels = 1;
|
||||
|
||||
gluBuild3DMipmaps( target, _internalFormat,
|
||||
s_gluBuild3DMipmaps( target, _internalFormat,
|
||||
image->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(),
|
||||
@ -245,13 +273,18 @@ void Texture3D::applyTexImage3D(GLenum target, Image* image, State& state, GLsiz
|
||||
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."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const uint contextID = state.getContextID();
|
||||
|
||||
// get the globj for the current contextID.
|
||||
@ -263,7 +296,7 @@ void Texture3D::copyTexSubImage3D(State& state, int xoffset, int yoffset, int zo
|
||||
// we have a valid image
|
||||
glBindTexture( GL_TEXTURE_3D, handle );
|
||||
applyTexParameters(GL_TEXTURE_3D,state);
|
||||
glCopyTexSubImage3D( GL_TEXTURE_3D, 0, xoffset,yoffset,zoffset, x, y, width, height);
|
||||
s_glCopyTexSubImage3D( GL_TEXTURE_3D, 0, xoffset,yoffset,zoffset, x, y, width, height);
|
||||
|
||||
/* Redundant, delete later */
|
||||
glBindTexture( GL_TEXTURE_3D, handle );
|
||||
@ -276,5 +309,4 @@ void Texture3D::copyTexSubImage3D(State& state, int xoffset, int yoffset, int zo
|
||||
{
|
||||
notify(WARN)<<"Warning: Texture3D::copyTexSubImage3D(..) failed, cannot not copy to a non existant texture."<<std::endl;
|
||||
}
|
||||
#endif // TEMPORARY_COMMENT_OUT_WHILE_ESTABLISHING_X_PLATFORM_SUPPORT_FOR_3D_TEXTURES
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user