From c30be2355b9cf5f0968d8335422c08c1a4eeadd1 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 10 Mar 2015 18:15:02 +0000 Subject: [PATCH] Work in progress to allow osg::Texture2DArray to be set up with a single osg::Image containing 3D image data. git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14773 16af8721-9629-0410-8352-f15c8da7e697 --- include/osg/Texture2DArray | 8 +-- src/osg/Texture2DArray.cpp | 69 +++++++++---------- .../serializers/osg/Texture2DArray.cpp | 1 - 3 files changed, 36 insertions(+), 42 deletions(-) diff --git a/include/osg/Texture2DArray b/include/osg/Texture2DArray index 1e4e58c8c..436e9ffa6 100644 --- a/include/osg/Texture2DArray +++ b/include/osg/Texture2DArray @@ -59,7 +59,7 @@ class OSG_EXPORT Texture2DArray : public Texture * image/layer count, you have to use the extension subclass, since it provides * graphic context dependent information. */ - virtual unsigned int getNumImages() const { return getTextureDepth(); } + virtual unsigned int getNumImages() const { return _images.size(); } /** Check how often was a certain layer in the given context modified */ inline unsigned int& getModifiedCount(unsigned int layer, unsigned int contextID) const @@ -131,10 +131,8 @@ class OSG_EXPORT Texture2DArray : public Texture void applyTexImage2DArray_subload(State& state, Image* image, GLsizei inwidth, GLsizei inheight, GLsizei indepth, GLint inInternalFormat, GLsizei& numMipmapLevels) const; - /** - * Use std::vector to encapsulate referenced pointers to images of different layers. - * Vectors gives us a random access iterator. The overhead of non-used elements is negligible */ - std::vector > _images; + typedef std::vector< ref_ptr > Images; + Images _images; // subloaded images can have different texture and image sizes. mutable GLsizei _textureWidth, _textureHeight, _textureDepth; diff --git a/src/osg/Texture2DArray.cpp b/src/osg/Texture2DArray.cpp index 65a01f841..ccb62f474 100644 --- a/src/osg/Texture2DArray.cpp +++ b/src/osg/Texture2DArray.cpp @@ -107,15 +107,17 @@ int Texture2DArray::compare(const StateAttribute& sa) const void Texture2DArray::setImage(unsigned int layer, Image* image) { - // check if the layer exceeds the texture depth - if (static_cast(layer) >= _textureDepth) + if (layer>= static_cast(_images.size())) { - // print warning and do nothing - OSG_WARN<<"Warning: Texture2DArray::setImage(..) failed, the given layer number is bigger then the size of the texture array."<(_images.size())) ? _images[layer].get() : 0; +} + +const Image* Texture2DArray::getImage(unsigned int layer) const +{ + return (layer(_images.size())) ? _images[layer].get() : 0; +} + +bool Texture2DArray::imagesValid() const +{ + if (_images.empty()) return false; + + for(Images::const_iterator itr = _images.begin(); + itr != _images.end(); + ++itr) + { + if (!(itr->valid()) || !((*itr)->valid())) return false; + } + return true; +} + void Texture2DArray::setTextureSize(int width, int height, int depth) { // set dimensions @@ -170,44 +195,16 @@ void Texture2DArray::setTextureSize(int width, int height, int depth) void Texture2DArray::setTextureDepth(int depth) { // if we decrease the number of layers, then delete non-used - if (depth < _textureDepth) + if (depth < static_cast(_images.size())) { _images.resize(depth); _modifiedCount.resize(depth); } - // if we increase the array, then add new empty elements - if (depth > _textureDepth) - { - _images.resize(depth, ref_ptr(0)); - _modifiedCount.resize(depth, ImageModifiedCount()); - } - // resize the texture array _textureDepth = depth; } -Image* Texture2DArray::getImage(unsigned int layer) -{ - return _images[layer].get(); -} - -const Image* Texture2DArray::getImage(unsigned int layer) const -{ - return _images[layer].get(); -} - -bool Texture2DArray::imagesValid() const -{ - if (_textureDepth < 1) return false; - for (int n=0; n < _textureDepth; n++) - { - if (!_images[n].valid() || !_images[n]->data()) - return false; - } - return true; -} - void Texture2DArray::computeInternalFormat() const { if (imagesValid()) computeInternalFormatWithImage(*_images[0]); diff --git a/src/osgWrappers/serializers/osg/Texture2DArray.cpp b/src/osgWrappers/serializers/osg/Texture2DArray.cpp index 5d818024c..e351aff94 100644 --- a/src/osgWrappers/serializers/osg/Texture2DArray.cpp +++ b/src/osgWrappers/serializers/osg/Texture2DArray.cpp @@ -11,7 +11,6 @@ static bool checkImages( const osg::Texture2DArray& tex ) static bool readImages( osgDB::InputStream& is, osg::Texture2DArray& tex ) { unsigned int size = 0; is >> size >> is.BEGIN_BRACKET; - tex.setTextureDepth(size); for ( unsigned int i=0; i