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
This commit is contained in:
Robert Osfield 2015-03-10 18:15:02 +00:00
parent d97e01c520
commit c30be2355b
3 changed files with 36 additions and 42 deletions

View File

@ -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<ref_ptr<Image> > _images;
typedef std::vector< ref_ptr<Image> > Images;
Images _images;
// subloaded images can have different texture and image sizes.
mutable GLsizei _textureWidth, _textureHeight, _textureDepth;

View File

@ -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<int>(layer) >= _textureDepth)
if (layer>= static_cast<unsigned int>(_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."<<std::endl;
return;
// _images vector not large enough to contain layer so expand it.
_images.resize(layer+1);
_modifiedCount.resize(layer+1);
}
else
{
// do not need to replace already assigned images
if (_images[layer] == image) return;
}
unsigned numImageRequireUpdateBefore = 0;
for (unsigned int i=0; i<getNumImages(); ++i)
@ -159,6 +161,29 @@ void Texture2DArray::setImage(unsigned int layer, Image* image)
}
}
Image* Texture2DArray::getImage(unsigned int layer)
{
return (layer<static_cast<unsigned int>(_images.size())) ? _images[layer].get() : 0;
}
const Image* Texture2DArray::getImage(unsigned int layer) const
{
return (layer<static_cast<unsigned int>(_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<int>(_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<Image>(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]);

View File

@ -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<size; ++i )
{
osg::Image* image = is.readImage();