Texture2D
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_TEXTURE2D
#define OSG_TEXTURE2D 1
#include <osg/Texture>
namespace osg {
class OSG_EXPORT Texture2D : public Texture
{
public :
Texture2D();
Texture2D(Image* image);
template<class T> Texture2D(const osg::ref_ptr<T>& image):
_textureWidth(0),
_textureHeight(0),
_numMipmapLevels(0)
{
setUseHardwareMipMapGeneration(true);
setImage(image.get());
}
Texture2D(const Texture2D& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_StateAttribute(osg, Texture2D,TEXTURE);
virtual int compare(const StateAttribute& rhs) const;
virtual GLenum getTextureTarget() const { return GL_TEXTURE_2D; }
void setImage(Image* image);
template<class T> void setImage(const ref_ptr<T>& image) { setImage(image.get()); }
Image* getImage() { return _image.get(); }
inline const Image* getImage() const { return _image.get(); }
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.
return _modifiedCount[contextID];
}
virtual void setImage(unsigned int, Image* image) { setImage(image); }
template<class T> void setImage(unsigned int, const ref_ptr<T>& image) { setImage(image.get()); }
virtual Image* getImage(unsigned int) { return _image.get(); }
virtual const Image* getImage(unsigned int) const { return _image.get(); }
virtual unsigned int getNumImages() const { return 1; }
inline void setTextureSize(int width, int height) const
{
_textureWidth = width;
_textureHeight = height;
}
void setTextureWidth(int width) { _textureWidth=width; }
void setTextureHeight(int height) { _textureHeight=height; }
virtual int getTextureWidth() const { return _textureWidth; }
virtual int getTextureHeight() const { return _textureHeight; }
virtual int getTextureDepth() const { return 1; }
class OSG_EXPORT SubloadCallback : public Referenced
{
public:
virtual bool textureObjectValid(const Texture2D& texture, State& state) const
{
return texture.textureObjectValid(state);
}
virtual osg::ref_ptr<TextureObject> generateTextureObject(const Texture2D& texture, State& state) const
{
return osg::Texture::generateTextureObject(&texture, state.getContextID(), GL_TEXTURE_2D);
}
virtual void load(const Texture2D& texture,State& state) const = 0;
virtual void subload(const Texture2D& 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 copyTexImage2D(State& state, int x, int y, int width, int height );
void copyTexSubImage2D(State& state, int xoffset, int yoffset, int x, int y, int width, int height );
virtual void apply(State& state) const;
protected :
virtual ~Texture2D();
virtual void computeInternalFormat() const;
void allocateMipmap(State& state) const;
bool textureObjectValid(State& state) const;
friend class SubloadCallback;
ref_ptr<Image> _image;
mutable GLsizei _textureWidth, _textureHeight;
mutable GLsizei _numMipmapLevels;
ref_ptr<SubloadCallback> _subloadCallback;
typedef buffered_value<unsigned int> ImageModifiedCount;
mutable ImageModifiedCount _modifiedCount;
};
}
#endif
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::State::getContextID
unsigned int getContextID() const
Definition State:114
osg::Texture2D::SubloadCallback
Definition Texture2D:104
osg::Texture2D::SubloadCallback::generateTextureObject
virtual osg::ref_ptr< TextureObject > generateTextureObject(const Texture2D &texture, State &state) const
Definition Texture2D:112
osg::Texture2D::SubloadCallback::load
virtual void load(const Texture2D &texture, State &state) const =0
osg::Texture2D::SubloadCallback::subload
virtual void subload(const Texture2D &texture, State &state) const =0
osg::Texture2D::SubloadCallback::textureObjectValid
virtual bool textureObjectValid(const Texture2D &texture, State &state) const
Definition Texture2D:107
osg::Texture2D::getNumImages
virtual unsigned int getNumImages() const
Definition Texture2D:85
osg::Texture2D::setImage
void setImage(unsigned int, const ref_ptr< T > &image)
Definition Texture2D:76
osg::Texture2D::setTextureSize
void setTextureSize(int width, int height) const
Definition Texture2D:90
osg::Texture2D::getTextureWidth
virtual int getTextureWidth() const
Definition Texture2D:99
osg::Texture2D::getNumMipmapLevels
unsigned int getNumMipmapLevels() const
Definition Texture2D:134
osg::Texture2D::getTextureDepth
virtual int getTextureDepth() const
Definition Texture2D:101
osg::Texture2D::getModifiedCount
unsigned int & getModifiedCount(unsigned int contextID) const
Definition Texture2D:66
osg::Texture2D::getImage
virtual const Image * getImage(unsigned int) const
Definition Texture2D:82
osg::Texture2D::setTextureHeight
void setTextureHeight(int height)
Definition Texture2D:97
osg::Texture2D::setImage
virtual void setImage(unsigned int, Image *image)
Definition Texture2D:74
osg::Texture2D::_image
ref_ptr< Image > _image
Definition Texture2D:171
osg::Texture2D::Texture2D
Texture2D(const osg::ref_ptr< T > &image)
Definition Texture2D:33
osg::Texture2D::setTextureWidth
void setTextureWidth(int width)
Definition Texture2D:96
osg::Texture2D::getImage
virtual Image * getImage(unsigned int)
Definition Texture2D:79
osg::Texture2D::allocateMipmap
void allocateMipmap(State &state) const
osg::Texture2D::_textureHeight
GLsizei _textureHeight
Definition Texture2D:174
osg::Texture2D::Texture2D
Texture2D()
osg::Texture2D::ImageModifiedCount
buffered_value< unsigned int > ImageModifiedCount
Definition Texture2D:181
osg::Texture2D::_textureWidth
GLsizei _textureWidth
Definition Texture2D:174
osg::Texture2D::compare
virtual int compare(const StateAttribute &rhs) const
osg::Texture2D::getTextureTarget
virtual GLenum getTextureTarget() const
Definition Texture2D:50
osg::Texture2D::copyTexImage2D
void copyTexImage2D(State &state, int x, int y, int width, int height)
osg::Texture2D::Texture2D
Texture2D(const Texture2D &text, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
osg::Texture2D::META_StateAttribute
META_StateAttribute(osg, Texture2D, TEXTURE)
osg::Texture2D::setImage
void setImage(Image *image)
osg::Texture2D::_modifiedCount
ImageModifiedCount _modifiedCount
Definition Texture2D:182
osg::Texture2D::copyTexSubImage2D
void copyTexSubImage2D(State &state, int xoffset, int yoffset, int x, int y, int width, int height)
osg::Texture2D::getTextureHeight
virtual int getTextureHeight() const
Definition Texture2D:100
osg::Texture2D::Texture2D
Texture2D(Image *image)
osg::Texture2D::setImage
void setImage(const ref_ptr< T > &image)
Definition Texture2D:55
osg::Texture2D::~Texture2D
virtual ~Texture2D()
osg::Texture2D::getImage
Image * getImage()
Definition Texture2D:58
osg::Texture2D::_subloadCallback
ref_ptr< SubloadCallback > _subloadCallback
Definition Texture2D:179
osg::Texture2D::isDirty
virtual bool isDirty(unsigned int contextID) const
Definition Texture2D:64
osg::Texture2D::setNumMipmapLevels
void setNumMipmapLevels(unsigned int num) const
Definition Texture2D:131
osg::Texture2D::textureObjectValid
bool textureObjectValid(State &state) const
osg::Texture2D::_numMipmapLevels
GLsizei _numMipmapLevels
Definition Texture2D:177
osg::Texture2D::setSubloadCallback
void setSubloadCallback(SubloadCallback *cb)
Definition Texture2D:121
osg::Texture2D::getImage
const Image * getImage() const
Definition Texture2D:61
osg::Texture2D::apply
virtual void apply(State &state) const
osg::Texture2D::computeInternalFormat
virtual void computeInternalFormat() const
osg::Texture2D::getSubloadCallback
const SubloadCallback * getSubloadCallback() const
Definition Texture2D:125
osg::Texture2D::getSubloadCallback
SubloadCallback * getSubloadCallback()
Definition Texture2D:123
osg::Texture::Texture
Texture()
osg::Texture::generateTextureObject
static osg::ref_ptr< TextureObject > generateTextureObject(const Texture *texture, unsigned int contextID, GLenum target)
osg::Texture::setUseHardwareMipMapGeneration
void setUseHardwareMipMapGeneration(bool useHardwareMipMapGeneration)
Definition Texture:550
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