TextureRectangle
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_TEXTURERECTANGLE
#define OSG_TEXTURERECTANGLE 1
#include <osg/Texture>
#ifndef GL_TEXTURE_RECTANGLE_NV
#define GL_TEXTURE_RECTANGLE_NV 0x84F5
#endif
#ifndef GL_TEXTURE_RECTANGLE
#define GL_TEXTURE_RECTANGLE GL_TEXTURE_RECTANGLE_NV
#endif
namespace osg {
class OSG_EXPORT TextureRectangle : public Texture
{
public :
TextureRectangle();
TextureRectangle(Image* image);
template<class T> TextureRectangle(const osg::ref_ptr<T>& image):
_textureWidth(0),
_textureHeight(0)
{
setWrap(WRAP_S, CLAMP);
setWrap(WRAP_T, CLAMP);
setFilter(MIN_FILTER, LINEAR);
setFilter(MAG_FILTER, LINEAR);
setImage(image.get());
}
TextureRectangle(const TextureRectangle& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_StateAttribute(osg, TextureRectangle, TEXTURE);
virtual int compare(const StateAttribute& rhs) const;
virtual GLenum getTextureTarget() const { return GL_TEXTURE_RECTANGLE; }
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); }
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 SubloadCallback : public Referenced
{
public:
virtual void load(const TextureRectangle&, State&) const = 0;
virtual void subload(const TextureRectangle&, State&) const = 0;
};
void setSubloadCallback(SubloadCallback* cb) { _subloadCallback = cb;; }
SubloadCallback* getSubloadCallback() { return _subloadCallback.get(); }
const SubloadCallback* getSubloadCallback() const { return _subloadCallback.get(); }
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 ~TextureRectangle();
virtual void computeInternalFormat() const;
void allocateMipmap(State& state) const;
void applyTexImage_load(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight) const;
void applyTexImage_subload(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight, GLint& inInternalFormat) const;
ref_ptr<Image> _image;
// subloaded images can have different texture and image sizes.
mutable GLsizei _textureWidth, _textureHeight;
ref_ptr<SubloadCallback> _subloadCallback;
typedef buffered_value<unsigned int> ImageModifiedCount;
mutable ImageModifiedCount _modifiedCount;
};
}
#endif
GL_TEXTURE_RECTANGLE
#define GL_TEXTURE_RECTANGLE
Definition GLDefines:406
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::TextureRectangle::SubloadCallback
Definition TextureRectangle:113
osg::TextureRectangle::SubloadCallback::load
virtual void load(const TextureRectangle &, State &) const =0
osg::TextureRectangle::SubloadCallback::subload
virtual void subload(const TextureRectangle &, State &) const =0
osg::TextureRectangle::getSubloadCallback
const SubloadCallback * getSubloadCallback() const
Definition TextureRectangle:121
osg::TextureRectangle::_textureWidth
GLsizei _textureWidth
Definition TextureRectangle:156
osg::TextureRectangle::setImage
void setImage(Image *image)
osg::TextureRectangle::compare
virtual int compare(const StateAttribute &rhs) const
osg::TextureRectangle::ImageModifiedCount
buffered_value< unsigned int > ImageModifiedCount
Definition TextureRectangle:160
osg::TextureRectangle::setSubloadCallback
void setSubloadCallback(SubloadCallback *cb)
Definition TextureRectangle:119
osg::TextureRectangle::TextureRectangle
TextureRectangle(Image *image)
osg::TextureRectangle::getModifiedCount
unsigned int & getModifiedCount(unsigned int contextID) const
Definition TextureRectangle:76
osg::TextureRectangle::setTextureWidth
void setTextureWidth(int width)
Definition TextureRectangle:105
osg::TextureRectangle::setTextureSize
void setTextureSize(int width, int height) const
Definition TextureRectangle:99
osg::TextureRectangle::setImage
virtual void setImage(unsigned int, Image *image)
Definition TextureRectangle:84
osg::TextureRectangle::getTextureWidth
virtual int getTextureWidth() const
Definition TextureRectangle:108
osg::TextureRectangle::_image
ref_ptr< Image > _image
Definition TextureRectangle:153
osg::TextureRectangle::getImage
Image * getImage()
Definition TextureRectangle:68
osg::TextureRectangle::applyTexImage_subload
void applyTexImage_subload(GLenum target, Image *image, State &state, GLsizei &inwidth, GLsizei &inheight, GLint &inInternalFormat) const
osg::TextureRectangle::isDirty
virtual bool isDirty(unsigned int contextID) const
Definition TextureRectangle:74
osg::TextureRectangle::_subloadCallback
ref_ptr< SubloadCallback > _subloadCallback
Definition TextureRectangle:158
osg::TextureRectangle::allocateMipmap
void allocateMipmap(State &state) const
osg::TextureRectangle::setImage
void setImage(const ref_ptr< T > &image)
Definition TextureRectangle:65
osg::TextureRectangle::_modifiedCount
ImageModifiedCount _modifiedCount
Definition TextureRectangle:161
osg::TextureRectangle::TextureRectangle
TextureRectangle(const TextureRectangle &text, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
osg::TextureRectangle::getImage
const Image * getImage() const
Definition TextureRectangle:71
osg::TextureRectangle::TextureRectangle
TextureRectangle(const osg::ref_ptr< T > &image)
Definition TextureRectangle:39
osg::TextureRectangle::setTextureHeight
void setTextureHeight(int height)
Definition TextureRectangle:106
osg::TextureRectangle::apply
virtual void apply(State &state) const
osg::TextureRectangle::applyTexImage_load
void applyTexImage_load(GLenum target, Image *image, State &state, GLsizei &inwidth, GLsizei &inheight) const
osg::TextureRectangle::getTextureDepth
virtual int getTextureDepth() const
Definition TextureRectangle:110
osg::TextureRectangle::copyTexImage2D
void copyTexImage2D(State &state, int x, int y, int width, int height)
osg::TextureRectangle::getImage
virtual Image * getImage(unsigned int)
Definition TextureRectangle:87
osg::TextureRectangle::getTextureTarget
virtual GLenum getTextureTarget() const
Definition TextureRectangle:60
osg::TextureRectangle::getTextureHeight
virtual int getTextureHeight() const
Definition TextureRectangle:109
osg::TextureRectangle::META_StateAttribute
META_StateAttribute(osg, TextureRectangle, TEXTURE)
osg::TextureRectangle::copyTexSubImage2D
void copyTexSubImage2D(State &state, int xoffset, int yoffset, int x, int y, int width, int height)
osg::TextureRectangle::getSubloadCallback
SubloadCallback * getSubloadCallback()
Definition TextureRectangle:120
osg::TextureRectangle::getImage
virtual const Image * getImage(unsigned int) const
Definition TextureRectangle:90
osg::TextureRectangle::computeInternalFormat
virtual void computeInternalFormat() const
osg::TextureRectangle::getNumImages
virtual unsigned int getNumImages() const
Definition TextureRectangle:93
osg::TextureRectangle::TextureRectangle
TextureRectangle()
osg::TextureRectangle::_textureHeight
GLsizei _textureHeight
Definition TextureRectangle:156
osg::TextureRectangle::~TextureRectangle
virtual ~TextureRectangle()
osg::Texture::setFilter
void setFilter(FilterParameter which, FilterMode filter)
osg::Texture::Texture
Texture()
osg::Texture::LINEAR
@ LINEAR
Definition Texture:500
osg::Texture::CLAMP
@ CLAMP
Definition Texture:468
osg::Texture::WRAP_S
@ WRAP_S
Definition Texture:462
osg::Texture::WRAP_T
@ WRAP_T
Definition Texture:463
osg::Texture::MAG_FILTER
@ MAG_FILTER
Definition Texture:496
osg::Texture::MIN_FILTER
@ MIN_FILTER
Definition Texture:495
osg::Texture::setWrap
void setWrap(WrapParameter which, WrapMode wrap)
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