Texture2DArray
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_TEXTURE2DARRAY
#define OSG_TEXTURE2DARRAY 1
#include <osg/Texture>
#include <list>
namespace osg {
class OSG_EXPORT Texture2DArray : public Texture
{
public :
Texture2DArray();
Texture2DArray(const Texture2DArray& cm,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_StateAttribute(osg, Texture2DArray, TEXTURE);
virtual int compare(const StateAttribute& rhs) const;
virtual GLenum getTextureTarget() const { return GL_TEXTURE_2D_ARRAY; }
virtual bool getModeUsage(StateAttribute::ModeUsage&) const { return false; }
virtual void setImage(unsigned int layer, Image* image);
template<class T> void setImage(unsigned int layer, const ref_ptr<T>& image) { setImage(layer, image.get()); }
virtual Image* getImage(unsigned int layer);
virtual const Image* getImage(unsigned int layer) const;
virtual unsigned int getNumImages() const { return _images.size(); }
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;
}
inline unsigned int& getModifiedCount(unsigned int layer, unsigned int contextID) const
{
// get the modified count for the current contextID.
return _modifiedCount[layer][contextID];
}
void setTextureSize(int width, int height, int depth);
void setTextureWidth(int width) { _textureWidth=width; }
void setTextureHeight(int height) { _textureHeight=height; }
void setTextureDepth(int depth);
virtual int getTextureWidth() const { return _textureWidth; }
virtual int getTextureHeight() const { return _textureHeight; }
virtual int getTextureDepth() const { return _textureDepth; }
class OSG_EXPORT SubloadCallback : public Referenced
{
public:
virtual void load(const Texture2DArray& texture,State& state) const = 0;
virtual void subload(const Texture2DArray& texture,State& state) const = 0;
};
void setSubloadCallback(SubloadCallback* cb) { _subloadCallback = cb;; }
SubloadCallback* getSubloadCallback() { return _subloadCallback.get(); }
const SubloadCallback* getSubloadCallback() const { return _subloadCallback.get(); }
void setNumMipmapLevels(unsigned int num) const { _numMipmapLevels=num; }
unsigned int getNumMipmapLevels() const { return _numMipmapLevels; }
void copyTexSubImage2DArray(State& state, int xoffset, int yoffset, int zoffset, int x, int y, int width, int height );
virtual void apply(State& state) const;
protected :
virtual ~Texture2DArray();
bool imagesValid() const;
virtual void computeInternalFormat() const;
GLsizei computeTextureDepth() const;
void allocateMipmap(State& state) const;
void applyTexImage2DArray_subload(State& state, Image* image, GLsizei layer, GLsizei inwidth, GLsizei inheight, GLsizei indepth, GLint inInternalFormat, GLsizei& numMipmapLevels) const;
typedef std::vector< ref_ptr<Image> > Images;
Images _images;
// subloaded images can have different texture and image sizes.
mutable GLsizei _textureWidth, _textureHeight, _textureDepth;
// number of mip map levels the texture has been created with,
mutable GLsizei _numMipmapLevels;
ref_ptr<SubloadCallback> _subloadCallback;
typedef buffered_value<unsigned int> ImageModifiedCount;
mutable std::vector<ImageModifiedCount> _modifiedCount;
};
}
#endif
GL_TEXTURE_2D_ARRAY
#define GL_TEXTURE_2D_ARRAY
Definition GLDefines:634
Texture
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Image
Definition Image:179
osg::Referenced::Referenced
Referenced()
osg::StateAttribute
Definition StateAttribute:77
osg::StateAttribute::TEXTURE
@ TEXTURE
Definition StateAttribute:125
osg::State
Definition State:80
osg::Texture2DArray::SubloadCallback
Definition Texture2DArray:98
osg::Texture2DArray::SubloadCallback::load
virtual void load(const Texture2DArray &texture, State &state) const =0
osg::Texture2DArray::SubloadCallback::subload
virtual void subload(const Texture2DArray &texture, State &state) const =0
osg::Texture2DArray::Texture2DArray
Texture2DArray()
osg::Texture2DArray::getSubloadCallback
const SubloadCallback * getSubloadCallback() const
Definition Texture2DArray:109
osg::Texture2DArray::getModeUsage
virtual bool getModeUsage(StateAttribute::ModeUsage &) const
Definition Texture2DArray:46
osg::Texture2DArray::compare
virtual int compare(const StateAttribute &rhs) const
osg::Texture2DArray::setTextureWidth
void setTextureWidth(int width)
Definition Texture2DArray:89
osg::Texture2DArray::getTextureDepth
virtual int getTextureDepth() const
Definition Texture2DArray:95
osg::Texture2DArray::_textureWidth
GLsizei _textureWidth
Definition Texture2DArray:151
osg::Texture2DArray::isDirty
virtual bool isDirty(unsigned int contextID) const
Definition Texture2DArray:67
osg::Texture2DArray::~Texture2DArray
virtual ~Texture2DArray()
osg::Texture2DArray::setTextureSize
void setTextureSize(int width, int height, int depth)
osg::Texture2DArray::setImage
void setImage(unsigned int layer, const ref_ptr< T > &image)
Definition Texture2DArray:51
osg::Texture2DArray::apply
virtual void apply(State &state) const
osg::Texture2DArray::setImage
virtual void setImage(unsigned int layer, Image *image)
osg::Texture2DArray::setNumMipmapLevels
void setNumMipmapLevels(unsigned int num) const
Definition Texture2DArray:116
osg::Texture2DArray::getImage
virtual Image * getImage(unsigned int layer)
osg::Texture2DArray::imagesValid
bool imagesValid() const
osg::Texture2DArray::Texture2DArray
Texture2DArray(const Texture2DArray &cm, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
osg::Texture2DArray::computeInternalFormat
virtual void computeInternalFormat() const
osg::Texture2DArray::_modifiedCount
std::vector< ImageModifiedCount > _modifiedCount
Definition Texture2DArray:159
osg::Texture2DArray::copyTexSubImage2DArray
void copyTexSubImage2DArray(State &state, int xoffset, int yoffset, int zoffset, int x, int y, int width, int height)
osg::Texture2DArray::getNumImages
virtual unsigned int getNumImages() const
Definition Texture2DArray:64
osg::Texture2DArray::getTextureTarget
virtual GLenum getTextureTarget() const
Definition Texture2DArray:43
osg::Texture2DArray::setSubloadCallback
void setSubloadCallback(SubloadCallback *cb)
Definition Texture2DArray:105
osg::Texture2DArray::_textureHeight
GLsizei _textureHeight
Definition Texture2DArray:151
osg::Texture2DArray::Images
std::vector< ref_ptr< Image > > Images
Definition Texture2DArray:147
osg::Texture2DArray::applyTexImage2DArray_subload
void applyTexImage2DArray_subload(State &state, Image *image, GLsizei layer, GLsizei inwidth, GLsizei inheight, GLsizei indepth, GLint inInternalFormat, GLsizei &numMipmapLevels) const
osg::Texture2DArray::getModifiedCount
unsigned int & getModifiedCount(unsigned int layer, unsigned int contextID) const
Definition Texture2DArray:77
osg::Texture2DArray::getImage
virtual const Image * getImage(unsigned int layer) const
osg::Texture2DArray::allocateMipmap
void allocateMipmap(State &state) const
osg::Texture2DArray::getTextureHeight
virtual int getTextureHeight() const
Definition Texture2DArray:94
osg::Texture2DArray::_subloadCallback
ref_ptr< SubloadCallback > _subloadCallback
Definition Texture2DArray:156
osg::Texture2DArray::_images
Images _images
Definition Texture2DArray:148
osg::Texture2DArray::_textureDepth
GLsizei _textureDepth
Definition Texture2DArray:151
osg::Texture2DArray::getSubloadCallback
SubloadCallback * getSubloadCallback()
Definition Texture2DArray:107
osg::Texture2DArray::getTextureWidth
virtual int getTextureWidth() const
Definition Texture2DArray:93
osg::Texture2DArray::getNumMipmapLevels
unsigned int getNumMipmapLevels() const
Definition Texture2DArray:119
osg::Texture2DArray::META_StateAttribute
META_StateAttribute(osg, Texture2DArray, TEXTURE)
osg::Texture2DArray::setTextureDepth
void setTextureDepth(int depth)
osg::Texture2DArray::computeTextureDepth
GLsizei computeTextureDepth() const
osg::Texture2DArray::_numMipmapLevels
GLsizei _numMipmapLevels
Definition Texture2DArray:154
osg::Texture2DArray::setTextureHeight
void setTextureHeight(int height)
Definition Texture2DArray:90
osg::Texture2DArray::ImageModifiedCount
buffered_value< unsigned int > ImageModifiedCount
Definition Texture2DArray:158
osg::Texture::Texture
Texture()
osg::buffered_value
Definition buffered_value:27
osg::ref_ptr
Definition ref_ptr:32
osg::ref_ptr::get
T * get() const
Definition ref_ptr:117
osg
Definition AlphaFunc:19
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39
osg::StateAttribute::ModeUsage
Definition StateAttribute:308