From bb5576bef86d5ef2729de7253e50ab9aae3a9583 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 27 Jul 2004 10:11:45 +0000 Subject: [PATCH] Added support s/getImage(uint i) and getNumImages(). --- include/osg/Referenced | 2 +- include/osg/Texture | 14 ++++++++++++++ include/osg/Texture1D | 13 +++++++++++++ include/osg/Texture2D | 14 ++++++++++++++ include/osg/Texture3D | 13 +++++++++++++ include/osg/TextureCubeMap | 11 +++++++---- include/osg/TextureRectangle | 14 ++++++++++++++ src/osg/Image.cpp | 2 ++ src/osg/ImageStream.cpp | 1 + src/osg/Texture1D.cpp | 8 +------- src/osg/Texture2D.cpp | 2 +- src/osg/Texture3D.cpp | 8 +------- src/osg/TextureCubeMap.cpp | 14 ++++---------- src/osg/TextureRectangle.cpp | 10 +++++----- 14 files changed, 91 insertions(+), 35 deletions(-) diff --git a/include/osg/Referenced b/include/osg/Referenced index d4593a6e8..70f0439f6 100644 --- a/include/osg/Referenced +++ b/include/osg/Referenced @@ -19,7 +19,7 @@ #include -#define USE_REF_MUTEX 1 +// #define USE_REF_MUTEX 1 namespace osg { diff --git a/include/osg/Texture b/include/osg/Texture index 50399629d..34f87b267 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -315,6 +315,20 @@ class SG_EXPORT Texture : public osg::StateAttribute void setShadowAmbient(float shadow_ambient) { _shadow_ambient = shadow_ambient; } float getShadowAmbient() { return _shadow_ambient; } + + /** Set the texture image for specified face. */ + virtual void setImage(unsigned int face, Image* image) = 0; + + /** Get the texture image for specified face. */ + virtual Image* getImage(unsigned int face) = 0; + + /** Get the const texture image for specified face. */ + virtual const Image* getImage(unsigned int face) const = 0; + + /** Get the number of images that can be assigned to the Texture. */ + virtual unsigned int getNumImages() const = 0; + + /** Texture is pure virtual base class, apply must be overriden. */ virtual void apply(State& state) const = 0; diff --git a/include/osg/Texture1D b/include/osg/Texture1D index 761260c9b..1a3c76366 100644 --- a/include/osg/Texture1D +++ b/include/osg/Texture1D @@ -58,6 +58,19 @@ class SG_EXPORT Texture1D : public Texture } + /** Set the texture image, ignoring face. as there is only one image*/ + virtual void setImage(unsigned int, Image* image) { setImage(image); } + + /** Get the texture image, ignoring face value as there is only one image. */ + virtual Image* getImage(unsigned int) { return _image.get(); } + + /** Get the const texture image , ignoring face value as there is only one image. */ + virtual const Image* getImage(unsigned int) const { return _image.get(); } + + /** Get the number of images that can be assigned to the Texture. */ + virtual unsigned int getNumImages() const { return 1; } + + /** Set the texture width and height. If width or height are zero then * the repsective size value is calculated from the source image sizes. */ inline void setTextureSize(int width) const diff --git a/include/osg/Texture2D b/include/osg/Texture2D index d1d5bea32..f5afb31fc 100644 --- a/include/osg/Texture2D +++ b/include/osg/Texture2D @@ -57,6 +57,20 @@ class SG_EXPORT Texture2D : public Texture return _modifiedTag[contextID]; } + + /** Set the texture image, ignoring face. as there is only one image*/ + virtual void setImage(unsigned int, Image* image) { setImage(image); } + + /** Get the texture image, ignoring face value as there is only one image. */ + virtual Image* getImage(unsigned int) { return _image.get(); } + + /** Get the const texture image , ignoring face value as there is only one image. */ + virtual const Image* getImage(unsigned int) const { return _image.get(); } + + /** Get the number of images that can be assigned to the Texture. */ + virtual unsigned int getNumImages() const { return 1; } + + /** Set the texture width and height. If width or height are zero then * the repsective size value is calculated from the source image sizes. */ inline void setTextureSize(int width, int height) const diff --git a/include/osg/Texture3D b/include/osg/Texture3D index 6fd21833c..1e2494187 100644 --- a/include/osg/Texture3D +++ b/include/osg/Texture3D @@ -55,6 +55,19 @@ class SG_EXPORT Texture3D : public Texture return _modifiedTag[contextID]; } + /** Set the texture image, ignoring face. as there is only one image*/ + virtual void setImage(unsigned int, Image* image) { setImage(image); } + + /** Get the texture image, ignoring face value as there is only one image. */ + virtual Image* getImage(unsigned int) { return _image.get(); } + + /** Get the const texture image , ignoring face value as there is only one image. */ + virtual const Image* getImage(unsigned int) const { return _image.get(); } + + /** Get the number of images that can be assigned to the Texture. */ + virtual unsigned int getNumImages() const { return 1; } + + /** Set the texture width and height. If width or height are zero then * the repsective size value is calculated from the source image sizes. */ inline void setTextureSize(int width, int height, int depth) const diff --git a/include/osg/TextureCubeMap b/include/osg/TextureCubeMap index e62689882..62cc049ef 100644 --- a/include/osg/TextureCubeMap +++ b/include/osg/TextureCubeMap @@ -54,15 +54,18 @@ class SG_EXPORT TextureCubeMap : public Texture }; /** Set the texture image for specified face. */ - void setImage(Face, Image* image); + virtual void setImage(unsigned int face, Image* image); /** Get the texture image for specified face. */ - Image* getImage(Face); + virtual Image* getImage(unsigned int face); /** Get the const texture image for specified face. */ - const Image* getImage(Face) const; + virtual const Image* getImage(unsigned int face) const; - inline unsigned int& getModifiedTag(Face face,unsigned int contextID) const + /** Get the number of images that can be assigned to the Texture. */ + virtual unsigned int getNumImages() const { return 6; } + + inline unsigned int& getModifiedTag(unsigned int face,unsigned int contextID) const { // get the modified tag for the current contextID. return _modifiedTag[face][contextID]; diff --git a/include/osg/TextureRectangle b/include/osg/TextureRectangle index c0fb26914..670dd4fcd 100644 --- a/include/osg/TextureRectangle +++ b/include/osg/TextureRectangle @@ -65,6 +65,20 @@ class SG_EXPORT TextureRectangle : public Texture return _modifiedTag[contextID]; } + + /** Set the texture image, ignoring face. as there is only one image*/ + virtual void setImage(unsigned int, Image* image) { setImage(image); } + + /** Get the texture image, ignoring face value as there is only one image. */ + virtual Image* getImage(unsigned int) { return _image.get(); } + + /** Get the const texture image , ignoring face value as there is only one image. */ + virtual const Image* getImage(unsigned int) const { return _image.get(); } + + /** Get the number of images that can be assigned to the Texture. */ + virtual unsigned int getNumImages() const { return 1; } + + /** Set the texture width and height. If width or height are zero then * the repsective size value is calculated from the source image sizes. */ inline void setTextureSize(int width, int height) const diff --git a/src/osg/Image.cpp b/src/osg/Image.cpp index 0e4bae030..951467847 100644 --- a/src/osg/Image.cpp +++ b/src/osg/Image.cpp @@ -27,6 +27,8 @@ using namespace std; Image::Image() { + setDataVariance(STATIC); + _fileName = ""; _s = _t = _r = 0; _internalTextureFormat = 0; diff --git a/src/osg/ImageStream.cpp b/src/osg/ImageStream.cpp index b1bf4e1db..63a1c4eca 100644 --- a/src/osg/ImageStream.cpp +++ b/src/osg/ImageStream.cpp @@ -18,6 +18,7 @@ using namespace osg; ImageStream::ImageStream(): _status(PAUSED) { + setDataVariance(DYNAMIC); } ImageStream::ImageStream(const ImageStream& image,const CopyOp& copyop): diff --git a/src/osg/Texture1D.cpp b/src/osg/Texture1D.cpp index 4113b79d7..675761476 100644 --- a/src/osg/Texture1D.cpp +++ b/src/osg/Texture1D.cpp @@ -152,17 +152,11 @@ void Texture1D::apply(State& state) const // update the modified tag to show that it is upto date. getModifiedTag(contextID) = _image->getModifiedTag(); - if (_unrefImageDataAfterApply && areAllTextureObjectsLoaded()) + if (_unrefImageDataAfterApply && areAllTextureObjectsLoaded() && getDataVariance()==STATIC) { Texture1D* non_const_this = const_cast(this); non_const_this->_image = 0; } - - // in theory the following line is redundent, but in practice - // have found that the first frame drawn doesn't apply the textures - // unless a second bind is called?!! - // perhaps it is the first glBind which is not required... - //glBindTexture( GL_TEXTURE_1D, handle ); } else diff --git a/src/osg/Texture2D.cpp b/src/osg/Texture2D.cpp index fd560edf5..303cbb69d 100644 --- a/src/osg/Texture2D.cpp +++ b/src/osg/Texture2D.cpp @@ -188,7 +188,7 @@ void Texture2D::apply(State& state) const getModifiedTag(contextID) = _image->getModifiedTag(); - if (_unrefImageDataAfterApply && areAllTextureObjectsLoaded()) + if (_unrefImageDataAfterApply && areAllTextureObjectsLoaded() && getDataVariance()==STATIC) { Texture2D* non_const_this = const_cast(this); non_const_this->_image = 0; diff --git a/src/osg/Texture3D.cpp b/src/osg/Texture3D.cpp index 9af1990c9..3752bc591 100644 --- a/src/osg/Texture3D.cpp +++ b/src/osg/Texture3D.cpp @@ -168,18 +168,12 @@ void Texture3D::apply(State& state) const // update the modified tag to show that it is upto date. getModifiedTag(contextID) = _image->getModifiedTag(); - if (_unrefImageDataAfterApply && areAllTextureObjectsLoaded()) + if (_unrefImageDataAfterApply && areAllTextureObjectsLoaded() && getDataVariance()==STATIC) { Texture3D* non_const_this = const_cast(this); non_const_this->_image = 0; } - // in theory the following line is redundent, but in practice - // have found that the first frame drawn doesn't apply the textures - // unless a second bind is called?!! - // perhaps it is the first glBind which is not required... - //glBindTexture( GL_TEXTURE_3D, handle ); - } else { diff --git a/src/osg/TextureCubeMap.cpp b/src/osg/TextureCubeMap.cpp index da06007c8..75c5b2f34 100644 --- a/src/osg/TextureCubeMap.cpp +++ b/src/osg/TextureCubeMap.cpp @@ -164,18 +164,18 @@ int TextureCubeMap::compare(const StateAttribute& sa) const } -void TextureCubeMap::setImage( Face face, Image* image) +void TextureCubeMap::setImage( unsigned int face, Image* image) { _images[face] = image; _modifiedTag[face].setAllElementsTo(0); } -Image* TextureCubeMap::getImage(Face face) +Image* TextureCubeMap::getImage(unsigned int face) { return _images[face].get(); } -const Image* TextureCubeMap::getImage(Face face) const +const Image* TextureCubeMap::getImage(unsigned int face) const { return _images[face].get(); } @@ -284,7 +284,7 @@ void TextureCubeMap::apply(State& state) const } - if (_unrefImageDataAfterApply && areAllTextureObjectsLoaded()) + if (_unrefImageDataAfterApply && areAllTextureObjectsLoaded() && getDataVariance()==STATIC) { TextureCubeMap* non_const_this = const_cast(this); for (int n=0; n<6; n++) @@ -292,12 +292,6 @@ void TextureCubeMap::apply(State& state) const non_const_this->_images[n] = 0; } } - - // in theory the following line is redundent, but in practice - // have found that the first frame drawn doesn't apply the textures - // unless a second bind is called?!! - // perhaps it is the first glBind which is not required... - //glBindTexture( GL_TEXTURE_CUBE_MAP, handle ); } else diff --git a/src/osg/TextureRectangle.cpp b/src/osg/TextureRectangle.cpp index f1d8a0d8d..ca352ff30 100644 --- a/src/osg/TextureRectangle.cpp +++ b/src/osg/TextureRectangle.cpp @@ -182,11 +182,11 @@ void TextureRectangle::apply(State& state) const textureObject->setAllocated(1,_internalFormat,_textureWidth,_textureHeight,1,0); - // in theory the following line is redundant, but in practice - // have found that the first frame drawn doesn't apply the textures - // unless a second bind is called?!! - // perhaps it is the first glBind which is not required... - //glBindTexture(GL_TEXTURE_RECTANGLE, handle); + if (_unrefImageDataAfterApply && areAllTextureObjectsLoaded() && getDataVariance()==STATIC) + { + TextureRectangle* non_const_this = const_cast(this); + non_const_this->_image = 0; + } } else {