From b8e5f22cb7ad2b24451e55e8e117b9e4a404104f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 13 Feb 2018 12:01:57 +0000 Subject: [PATCH] Added virtual bool Texture::isDirty(contextID) method to help determine whether a GL texture object is likely to be out of date and needs updating --- include/osg/Texture | 5 +++++ include/osg/Texture1D | 5 +++++ include/osg/Texture2D | 3 +++ include/osg/Texture2DArray | 10 ++++++++++ include/osg/Texture3D | 3 +++ include/osg/TextureBuffer | 5 ++++- include/osg/TextureCubeMap | 12 ++++++++++++ include/osg/TextureRectangle | 3 +++ 8 files changed, 45 insertions(+), 1 deletion(-) diff --git a/include/osg/Texture b/include/osg/Texture index a4f744f68..eb4131374 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -654,6 +654,11 @@ class OSG_EXPORT Texture : public osg::StateAttribute class TextureObject; + + /** return true if the texture image data has been modified and the associated GL texture object needs to be updated.*/ + virtual bool isDirty(unsigned int /*contextID*/) const { return false; } + + /** Returns a pointer to the TextureObject for the current context. */ inline TextureObject* getTextureObject(unsigned int contextID) const { diff --git a/include/osg/Texture1D b/include/osg/Texture1D index f70f5a1b6..a8d75ea97 100644 --- a/include/osg/Texture1D +++ b/include/osg/Texture1D @@ -64,6 +64,11 @@ class OSG_EXPORT Texture1D : public Texture /** Gets the const texture image. */ inline const Image* getImage() const { return _image.get(); } + + /** return true if the texture image data has been modified and the associated GL texture object needs to be updated.*/ + virtual bool isDirty(unsigned int contextID) const { return (_image.valid() && _image->getModifiedCount()!=_modifiedCount[contextID]); } + + inline unsigned int& getModifiedCount(unsigned int contextID) const { // get the modified count for the current contextID. diff --git a/include/osg/Texture2D b/include/osg/Texture2D index 5aa24301e..654c82be1 100644 --- a/include/osg/Texture2D +++ b/include/osg/Texture2D @@ -60,6 +60,9 @@ class OSG_EXPORT Texture2D : public Texture /** Gets the const texture image. */ inline const Image* getImage() const { return _image.get(); } + /** return true if the texture image data has been modified and the associated GL texture object needs to be updated.*/ + virtual bool isDirty(unsigned int contextID) const { return (_image.valid() && _image->getModifiedCount()!=_modifiedCount[contextID]); } + inline unsigned int& getModifiedCount(unsigned int contextID) const { // get the modified count for the current contextID. diff --git a/include/osg/Texture2DArray b/include/osg/Texture2DArray index e410cd8f1..5565d5e02 100644 --- a/include/osg/Texture2DArray +++ b/include/osg/Texture2DArray @@ -63,6 +63,16 @@ class OSG_EXPORT Texture2DArray : public Texture */ virtual unsigned int getNumImages() const { return _images.size(); } + /** return true if the texture image data has been modified and the associated GL texture object needs to be updated.*/ + virtual bool isDirty(unsigned int contextID) const + { + for(unsigned int i=0; i<_images.size(); ++i) + { + if (_images[i].valid() && _images[i]->getModifiedCount()!=_modifiedCount[i][contextID]) return true; + } + return false; + } + /** Check how often was a certain layer in the given context modified */ inline unsigned int& getModifiedCount(unsigned int layer, unsigned int contextID) const { diff --git a/include/osg/Texture3D b/include/osg/Texture3D index f1ebfda4e..0ee67db08 100644 --- a/include/osg/Texture3D +++ b/include/osg/Texture3D @@ -61,6 +61,9 @@ class OSG_EXPORT Texture3D : public Texture /** Gets the const texture image. */ inline const Image* getImage() const { return _image.get(); } + /** return true if the texture image data has been modified and the associated GL texture object needs to be updated.*/ + virtual bool isDirty(unsigned int contextID) const { return (_image.valid() && _image->getModifiedCount()!=_modifiedCount[contextID]); } + inline unsigned int& getModifiedCount(unsigned int contextID) const { // get the modified count for the current contextID. diff --git a/include/osg/TextureBuffer b/include/osg/TextureBuffer index 7a5c603c6..437e62c0b 100644 --- a/include/osg/TextureBuffer +++ b/include/osg/TextureBuffer @@ -51,7 +51,10 @@ class OSG_EXPORT TextureBuffer : public Texture /** Gets the const texture image. */ inline const Image* getImage() const { return dynamic_cast(_bufferData.get() ); } - inline unsigned int & getModifiedCount(unsigned int contextID) const + /** return true if the texture image data has been modified and the associated GL texture object needs to be updated.*/ + virtual bool isDirty(unsigned int contextID) const { return (_bufferData.valid() && _bufferData->getModifiedCount()!=_modifiedCount[contextID]); } + + inline unsigned int & getModifiedCount(unsigned int contextID) const { // get the modified count for the current contextID. return _modifiedCount[contextID]; diff --git a/include/osg/TextureCubeMap b/include/osg/TextureCubeMap index 3ab3f8929..c212d679f 100644 --- a/include/osg/TextureCubeMap +++ b/include/osg/TextureCubeMap @@ -60,6 +60,18 @@ class OSG_EXPORT TextureCubeMap : public Texture /** Get the number of images that can be assigned to the Texture. */ virtual unsigned int getNumImages() const { return 6; } + + /** return true if the texture image data has been modified and the associated GL texture object needs to be updated.*/ + virtual bool isDirty(unsigned int contextID) const + { + return (_images[0].valid() && _images[0]->getModifiedCount()!=_modifiedCount[0][contextID]) || + (_images[1].valid() && _images[1]->getModifiedCount()!=_modifiedCount[1][contextID]) || + (_images[2].valid() && _images[2]->getModifiedCount()!=_modifiedCount[2][contextID]) || + (_images[3].valid() && _images[3]->getModifiedCount()!=_modifiedCount[3][contextID]) || + (_images[4].valid() && _images[4]->getModifiedCount()!=_modifiedCount[4][contextID]) || + (_images[5].valid() && _images[5]->getModifiedCount()!=_modifiedCount[5][contextID]); + } + inline unsigned int& getModifiedCount(unsigned int face,unsigned int contextID) const { // get the modified count for the current contextID. diff --git a/include/osg/TextureRectangle b/include/osg/TextureRectangle index f389523e3..68b6f48e9 100644 --- a/include/osg/TextureRectangle +++ b/include/osg/TextureRectangle @@ -70,6 +70,9 @@ class OSG_EXPORT TextureRectangle : public Texture /** Get the const texture image. */ inline const Image* getImage() const { return _image.get(); } + /** return true if the texture image data has been modified and the associated GL texture object needs to be updated.*/ + virtual bool isDirty(unsigned int contextID) const { return (_image.valid() && _image->getModifiedCount()!=_modifiedCount[contextID]); } + inline unsigned int& getModifiedCount(unsigned int contextID) const { // get the modified count for the current contextID.