From 635f302a2a492c7ddb461f91c39b5402c52be7b6 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 27 Jan 2004 21:29:58 +0000 Subject: [PATCH] Added support for osg::Texture::setBorderWidth(). --- Make/makedirdefs | 1 + include/osg/Texture | 10 ++++++++-- src/osg/Texture.cpp | 12 +++++++----- src/osg/Texture1D.cpp | 8 ++++---- src/osg/Texture3D.cpp | 4 ++-- src/osgPlugins/osg/Texture.cpp | 24 ++++++++++++++++++++++++ 6 files changed, 46 insertions(+), 13 deletions(-) diff --git a/Make/makedirdefs b/Make/makedirdefs index 2fa67ff3f..eaa61d5a3 100644 --- a/Make/makedirdefs +++ b/Make/makedirdefs @@ -182,6 +182,7 @@ EXAMPLE_DIRS = \ osgversion\ osgvertexprogram\ osgviewer\ + osgmovie\ osgwindows\ # osgpagedlod\ diff --git a/include/osg/Texture b/include/osg/Texture index 493f1f950..6c63b9138 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -126,12 +126,17 @@ class SG_EXPORT Texture : public osg::StateAttribute WrapMode getWrap(WrapParameter which) const; - /** Sets the border color for this texture. Makes difference only if + /** Set the border color for this texture. Makes difference only if * wrap mode is CLAMP_TO_BORDER */ void setBorderColor(const Vec4& color) { _borderColor = color; dirtyTextureParameters(); } + /** Get the border color for this texture.*/ const Vec4& getBorderColor() const { return _borderColor; } + /** Set the border width.*/ + void setBorderWidth(GLint width) { _borderWidth = width; dirtyTextureParameters(); } + + GLint getBorderWidth() const { return _borderWidth; } enum FilterParameter { MIN_FILTER, @@ -401,7 +406,8 @@ class SG_EXPORT Texture : public osg::StateAttribute bool _useHardwareMipMapGeneration; bool _unrefImageDataAfterApply; - Vec4 _borderColor; + Vec4 _borderColor; + GLint _borderWidth; InternalFormatMode _internalFormatMode; mutable GLint _internalFormat; diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index 063f68a5c..6d512c389 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -173,6 +173,7 @@ Texture::Texture(): _useHardwareMipMapGeneration(true), _unrefImageDataAfterApply(false), _borderColor(0.0, 0.0, 0.0, 0.0), + _borderWidth(0), _internalFormatMode(USE_IMAGE_DATA_FORMAT), _internalFormat(0), _use_shadow_comparison(false), @@ -192,6 +193,7 @@ Texture::Texture(const Texture& text,const CopyOp& copyop): _useHardwareMipMapGeneration(text._useHardwareMipMapGeneration), _unrefImageDataAfterApply(text._unrefImageDataAfterApply), _borderColor(text._borderColor), + _borderWidth(text._borderWidth), _internalFormatMode(text._internalFormatMode), _internalFormat(text._internalFormat), _use_shadow_comparison(text._use_shadow_comparison), @@ -508,8 +510,8 @@ void Texture::computeRequiredTextureDimensions(State& state, const osg::Image& i const unsigned int contextID = state.getContextID(); const Extensions* extensions = getExtensions(contextID,true); - int width = Image::computeNearestPowerOfTwo(image.s()); - int height = Image::computeNearestPowerOfTwo(image.t()); + int width = Image::computeNearestPowerOfTwo(image.s()-2*_borderWidth)+2*_borderWidth; + int height = Image::computeNearestPowerOfTwo(image.t()-2*_borderWidth)+2*_borderWidth; // cap the size to what the graphics hardware can handle. if (width>extensions->maxTextureSize()) width = extensions->maxTextureSize(); @@ -628,7 +630,7 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima numMipmapLevels = 1; glTexImage2D( target, 0, _internalFormat, - inwidth, inheight, 0, + inwidth, inheight, _borderWidth, (GLenum)image->getPixelFormat(), (GLenum)image->getDataType(), data ); @@ -672,7 +674,7 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima height = 1; glTexImage2D( target, k, _internalFormat, - width, height, 0, + width, height, _borderWidth, (GLenum)image->getPixelFormat(), (GLenum)image->getDataType(), image->getMipmapData(k)); @@ -694,7 +696,7 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima size = ((width+3)/4)*((height+3)/4)*blockSize; extensions->glCompressedTexImage2D(target, k, _internalFormat, - width, height, 0, + width, height, _borderWidth, size, image->getMipmapData(k)); width >>= 1; diff --git a/src/osg/Texture1D.cpp b/src/osg/Texture1D.cpp index c0c51083e..b1a412f95 100644 --- a/src/osg/Texture1D.cpp +++ b/src/osg/Texture1D.cpp @@ -207,7 +207,7 @@ void Texture1D::applyTexImage1D(GLenum target, Image* image, State& state, GLsiz { numMipmapLevels = 1; glTexImage1D( target, 0, _internalFormat, - image->s(), 0, + image->s(), _borderWidth, (GLenum)image->getPixelFormat(), (GLenum)image->getDataType(), image->data() ); @@ -219,7 +219,7 @@ void Texture1D::applyTexImage1D(GLenum target, Image* image, State& state, GLsiz GLint blockSize = ( _internalFormat == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ? 8 : 16 ); GLint size = ((image->s()+3)/4)*((image->t()+3)/4)*blockSize; glCompressedTexImage1D_ptr(target, 0, _internalFormat, - image->s(), 0, + image->s(), _borderWidth, size, image->data()); @@ -251,7 +251,7 @@ void Texture1D::applyTexImage1D(GLenum target, Image* image, State& state, GLsiz { glTexImage1D( target, k, _internalFormat, - width,0, + width,_borderWidth, (GLenum)image->getPixelFormat(), (GLenum)image->getDataType(), image->getMipmapData(k)); @@ -268,7 +268,7 @@ void Texture1D::applyTexImage1D(GLenum target, Image* image, State& state, GLsiz size = ((width+3)/4)*blockSize; glCompressedTexImage1D_ptr(target, k, _internalFormat, - width, 0, size, image->getMipmapData(k)); + width, _borderWidth, size, image->getMipmapData(k)); width >>= 1; } diff --git a/src/osg/Texture3D.cpp b/src/osg/Texture3D.cpp index d837939c7..9ce6164a5 100644 --- a/src/osg/Texture3D.cpp +++ b/src/osg/Texture3D.cpp @@ -223,7 +223,7 @@ void Texture3D::applyTexImage3D(GLenum target, Image* image, State& state, GLsiz { numMipmapLevels = 1; extensions->glTexImage3D( target, 0, _internalFormat, - image->s(), image->t(), image->r(), 0, + image->s(), image->t(), image->r(), _borderWidth, (GLenum)image->getPixelFormat(), (GLenum)image->getDataType(), image->data() ); @@ -260,7 +260,7 @@ void Texture3D::applyTexImage3D(GLenum target, Image* image, State& state, GLsiz depth = 1; extensions->glTexImage3D( target, k, _internalFormat, - width, height, depth, 0, + width, height, depth, _borderWidth, (GLenum)image->getPixelFormat(), (GLenum)image->getDataType(), image->getMipmapData(k)); diff --git a/src/osgPlugins/osg/Texture.cpp b/src/osgPlugins/osg/Texture.cpp index 4529c0f7e..b3e45f059 100644 --- a/src/osgPlugins/osg/Texture.cpp +++ b/src/osgPlugins/osg/Texture.cpp @@ -83,6 +83,27 @@ bool Texture_readLocalData(Object& obj, Input& fr) iteratorAdvanced = true; } + if (fr.matchSequence("borderWidth %f %f %f %f")) + { + Vec4 color; + fr[1].getFloat(color[0]); + fr[2].getFloat(color[1]); + fr[3].getFloat(color[2]); + fr[4].getFloat(color[3]); + texture.setBorderColor(color); + fr +=5 ; + iteratorAdvanced = true; + } + + if (fr.matchSequence("borderWidth %i")) + { + int width=0; + fr[1].getInt(width); + texture.setBorderWidth(width); + fr +=2 ; + iteratorAdvanced = true; + } + if (fr[0].matchWord("useHardwareMipMapGeneration")) { if (fr[1].matchWord("TRUE")) @@ -151,6 +172,9 @@ bool Texture_writeLocalData(const Object& obj, Output& fw) fw.indent() << "mag_filter " << Texture_getFilterStr(texture.getFilter(Texture::MAG_FILTER)) << std::endl; fw.indent() << "maxAnisotropy " << texture.getMaxAnisotropy() << std::endl; + fw.indent() << "borderColor " << texture.getBorderColor() << std::endl; + fw.indent() << "borderWidth " << texture.getBorderWidth() << std::endl; + fw.indent() << "useHardwareMipMapGeneration "<< (texture.getUseHardwareMipMapGeneration()?"TRUE":"FALSE") << std::endl; fw.indent() << "unRefImageDataAfterApply "<< (texture.getUnRefImageDataAfterApply()?"TRUE":"FALSE") << std::endl;