1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2013 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
16#ifndef OSG_TEXTUREBUFFEROBJECT
17#define OSG_TEXTUREBUFFEROBJECT 1
20#include <osg/BufferObject>
24/** Encapsulates OpenGL texture buffer functionality in a Texture delegating its content to attached BufferObject
26class OSG_EXPORT TextureBuffer : public Texture
33 TextureBuffer(BufferData* image);
35 /** Copy constructor using CopyOp to manage deep vs shallow copy. */
36 TextureBuffer(const TextureBuffer& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
38 META_StateAttribute(osg, TextureBuffer, TEXTURE);
40 /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
41 virtual int compare(const StateAttribute& rhs) const;
43 virtual GLenum getTextureTarget() const { return GL_TEXTURE_BUFFER; }
45 /** Sets the texture image. */
46 void setImage(Image* image);
48 /** Gets the texture image. */
49 Image* getImage() { return dynamic_cast<Image*>(_bufferData.get() ); }
51 /** Gets the const texture image. */
52 inline const Image* getImage() const { return dynamic_cast<Image*>(_bufferData.get() ); }
54 /** return true if the texture image data has been modified and the associated GL texture object needs to be updated.*/
55 virtual bool isDirty(unsigned int contextID) const { return (_bufferData.valid() && _bufferData->getModifiedCount()!=_modifiedCount[contextID]); }
57 inline unsigned int & getModifiedCount(unsigned int contextID) const
59 // get the modified count for the current contextID.
60 return _modifiedCount[contextID];
63 /** Sets the texture image, ignoring face. */
64 virtual void setImage(unsigned int, Image* image) { setImage(image); }
66 /** Gets the texture image, ignoring face. */
67 virtual Image* getImage(unsigned int) { return getImage(); }
69 /** Gets the const texture image, ignoring face. */
70 virtual const Image* getImage(unsigned int) const { return getImage(); }
72 /** Gets the number of images that can be assigned to the Texture. */
73 virtual unsigned int getNumImages() const { return 1; }
76 /** Sets the texture width. If width is zero, calculate the value
77 * from the source image width. */
78 inline void setTextureWidth(int width) { _textureWidth = width; }
80 /** Gets the texture width. */
81 virtual int getTextureWidth() const { return _textureWidth; }
82 virtual int getTextureHeight() const { return 1; }
83 virtual int getTextureDepth() const { return 1; }
85 virtual void allocateMipmap(State& /*state*/) const {};
87 /** Bind the texture buffer.*/
88 virtual void apply(State& state) const;
90 /** Set setBufferData attached */
91 void setBufferData(BufferData *bo);
93 /** Set setBufferData attached */
94 const BufferData * getBufferData()const {return _bufferData.get();}
97 virtual ~TextureBuffer();
99 virtual void computeInternalFormat() const;
101 ref_ptr< BufferData > _bufferData;
103 GLsizei _textureWidth;
105 typedef buffered_value< unsigned int > BufferDataModifiedCount;
106 mutable BufferDataModifiedCount _modifiedCount;