From 11a38e12f20d077d86964f8825d8fba212f1a483 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 31 Mar 2003 12:48:33 +0000 Subject: [PATCH] Made the default transparent bin be bin number 10 rather than 1 to allow more bins between it and the default opaque bin of 0. Added a check for compressed image format in osg::Texture. --- src/osg/StateSet.cpp | 2 +- src/osg/Texture.cpp | 83 ++++++++++++++++++++++++++++++++------------ 2 files changed, 61 insertions(+), 24 deletions(-) diff --git a/src/osg/StateSet.cpp b/src/osg/StateSet.cpp index 7053ebe98..3dfb35b0e 100644 --- a/src/osg/StateSet.cpp +++ b/src/osg/StateSet.cpp @@ -792,7 +792,7 @@ void StateSet::setRenderingHint(int hint) case(TRANSPARENT_BIN): { _binMode = USE_RENDERBIN_DETAILS; - _binNum = 1; + _binNum = 10; _binName = "DepthSortedBin"; break; } diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index 61856d336..b79da9244 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -382,7 +382,8 @@ void Texture::applyTexImage2D(GLenum target, Image* image, State& state, GLsizei computeInternalFormat(); // select the internalFormat required for the texture. - bool compressed = isCompressedInternalFormat(_internalFormat); + bool compressed_internal = isCompressedInternalFormat(_internalFormat); + bool compressed_image = isCompressedInternalFormat((GLenum)image->getPixelFormat()); image->ensureValidSizeForTexturing(extensions->maxTextureSize()); @@ -390,7 +391,7 @@ void Texture::applyTexImage2D(GLenum target, Image* image, State& state, GLsizei if( _min_filter == LINEAR || _min_filter == NEAREST ) { - if ( !compressed ) + if ( !compressed_internal) { numMimpmapLevels = 1; glTexImage2D( target, 0, _internalFormat, @@ -402,14 +403,26 @@ void Texture::applyTexImage2D(GLenum target, Image* image, State& state, GLsizei } else if (extensions->isCompressedTexImage2DSupported()) { - numMimpmapLevels = 1; - GLint blockSize = ( _internalFormat == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ? 8 : 16 ); - GLint size = ((image->s()+3)/4)*((image->t()+3)/4)*blockSize; - extensions->glCompressedTexImage2D(target, 0, _internalFormat, - image->s(), image->t(),0, - size, - image->data()); - + + if (compressed_image) + { + numMimpmapLevels = 1; + GLint blockSize = ( _internalFormat == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ? 8 : 16 ); + GLint size = ((image->s()+3)/4)*((image->t()+3)/4)*blockSize; + extensions->glCompressedTexImage2D(target, 0, _internalFormat, + image->s(), image->t(),0, + size, + image->data()); + } + else + { + numMimpmapLevels = 1; + glTexImage2D( target, 0, _internalFormat, + image->s(), image->t(), 0, + (GLenum)image->getPixelFormat(), + (GLenum)image->getDataType(), + image->data() ); + } } } @@ -433,7 +446,7 @@ void Texture::applyTexImage2D(GLenum target, Image* image, State& state, GLsizei int width = image->s(); int height = image->t(); - if( !compressed ) + if( !compressed_internal ) { for( GLsizei k = 0 ; k < numMimpmapLevels && (width || height) ;k++) { @@ -455,21 +468,45 @@ void Texture::applyTexImage2D(GLenum target, Image* image, State& state, GLsizei } else if (extensions->isCompressedTexImage2DSupported()) { - GLint blockSize = ( _internalFormat == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ? 8 : 16 ); - GLint size = 0; - for( GLsizei k = 0 ; k < numMimpmapLevels && (width || height) ;k++) + if ( compressed_image ) { - if (width == 0) - width = 1; - if (height == 0) - height = 1; - size = ((width+3)/4)*((height+3)/4)*blockSize; - extensions->glCompressedTexImage2D(target, k, _internalFormat, - width, height, 0, size, image->getMipmapData(k)); + GLint blockSize = ( _internalFormat == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ? 8 : 16 ); + GLint size = 0; + for( GLsizei k = 0 ; k < numMimpmapLevels && (width || height) ;k++) + { + if (width == 0) + width = 1; + if (height == 0) + height = 1; - width >>= 1; - height >>= 1; + size = ((width+3)/4)*((height+3)/4)*blockSize; + extensions->glCompressedTexImage2D(target, k, _internalFormat, + width, height, 0, size, image->getMipmapData(k)); + + width >>= 1; + height >>= 1; + } + } + else + { + for( GLsizei k = 0 ; k < numMimpmapLevels && (width || height) ;k++) + { + + if (width == 0) + width = 1; + if (height == 0) + height = 1; + + glTexImage2D( target, k, _internalFormat, + width, height, 0, + (GLenum)image->getPixelFormat(), + (GLenum)image->getDataType(), + image->getMipmapData(k)); + + width >>= 1; + height >>= 1; + } } } }