2013-05-22 20:49:46 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2013 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// -*-c++-*-
|
|
|
|
|
|
|
|
#ifndef OSG_TEXTUREBUFFEROBJECT
|
|
|
|
#define OSG_TEXTUREBUFFEROBJECT 1
|
|
|
|
|
|
|
|
#include <osg/Texture>
|
|
|
|
#include <osg/BufferObject>
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
2016-06-16 02:05:35 +08:00
|
|
|
/** Encapsulates OpenGL texture buffer functionality in a Texture delegating its content to attached BufferObject
|
2013-05-22 20:49:46 +08:00
|
|
|
*/
|
|
|
|
class OSG_EXPORT TextureBuffer : public Texture
|
|
|
|
{
|
|
|
|
|
|
|
|
public :
|
|
|
|
|
|
|
|
TextureBuffer();
|
|
|
|
|
2016-06-16 02:05:35 +08:00
|
|
|
TextureBuffer(BufferData* image);
|
2013-05-22 20:49:46 +08:00
|
|
|
|
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
|
|
|
TextureBuffer(const TextureBuffer& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
|
|
|
|
|
|
|
META_StateAttribute(osg, TextureBuffer, TEXTURE);
|
|
|
|
|
|
|
|
/** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
|
|
|
|
virtual int compare(const StateAttribute& rhs) const;
|
|
|
|
|
2015-01-07 01:23:26 +08:00
|
|
|
virtual GLenum getTextureTarget() const { return GL_TEXTURE_BUFFER; }
|
2013-05-22 20:49:46 +08:00
|
|
|
|
|
|
|
/** Sets the texture image. */
|
|
|
|
void setImage(Image* image);
|
|
|
|
|
|
|
|
/** Gets the texture image. */
|
2016-06-16 02:05:35 +08:00
|
|
|
Image* getImage() { return dynamic_cast<Image*>(_bufferData.get() ); }
|
2013-05-22 20:49:46 +08:00
|
|
|
|
|
|
|
/** Gets the const texture image. */
|
2016-06-16 02:05:35 +08:00
|
|
|
inline const Image* getImage() const { return dynamic_cast<Image*>(_bufferData.get() ); }
|
2013-05-22 20:49:46 +08:00
|
|
|
|
2016-06-16 02:05:35 +08:00
|
|
|
inline unsigned int & getModifiedCount(unsigned int contextID) const
|
2013-05-22 20:49:46 +08:00
|
|
|
{
|
|
|
|
// get the modified count for the current contextID.
|
|
|
|
return _modifiedCount[contextID];
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Sets the texture image, ignoring face. */
|
|
|
|
virtual void setImage(unsigned int, Image* image) { setImage(image); }
|
|
|
|
|
|
|
|
/** Gets the texture image, ignoring face. */
|
2016-06-16 02:05:35 +08:00
|
|
|
virtual Image* getImage(unsigned int) { return getImage(); }
|
2013-05-22 20:49:46 +08:00
|
|
|
|
|
|
|
/** Gets the const texture image, ignoring face. */
|
2016-06-16 02:05:35 +08:00
|
|
|
virtual const Image* getImage(unsigned int) const { return getImage(); }
|
2013-05-22 20:49:46 +08:00
|
|
|
|
|
|
|
/** Gets the number of images that can be assigned to the Texture. */
|
|
|
|
virtual unsigned int getNumImages() const { return 1; }
|
|
|
|
|
|
|
|
|
|
|
|
/** Sets the texture width. If width is zero, calculate the value
|
|
|
|
* from the source image width. */
|
|
|
|
inline void setTextureWidth(int width) { _textureWidth = width; }
|
|
|
|
|
|
|
|
/** Gets the texture width. */
|
|
|
|
virtual int getTextureWidth() const { return _textureWidth; }
|
|
|
|
virtual int getTextureHeight() const { return 1; }
|
|
|
|
virtual int getTextureDepth() const { return 1; }
|
2013-06-28 20:00:43 +08:00
|
|
|
|
|
|
|
virtual void allocateMipmap(State& /*state*/) const {};
|
2013-05-22 20:49:46 +08:00
|
|
|
|
|
|
|
/** Bind the texture buffer.*/
|
|
|
|
virtual void apply(State& state) const;
|
2013-06-28 20:00:43 +08:00
|
|
|
|
2018-02-02 17:54:31 +08:00
|
|
|
/** Set setBufferData attached */
|
2016-06-16 02:05:35 +08:00
|
|
|
void setBufferData(BufferData *bo);
|
2013-05-22 20:49:46 +08:00
|
|
|
|
2018-02-02 17:54:31 +08:00
|
|
|
/** Set setBufferData attached */
|
|
|
|
const BufferData * getBufferData()const {return _bufferData.get();}
|
2013-05-22 20:49:46 +08:00
|
|
|
protected :
|
|
|
|
|
|
|
|
virtual ~TextureBuffer();
|
|
|
|
|
|
|
|
virtual void computeInternalFormat() const;
|
|
|
|
|
2016-06-16 02:05:35 +08:00
|
|
|
ref_ptr< BufferData > _bufferData;
|
2013-05-22 20:49:46 +08:00
|
|
|
|
2016-06-16 02:05:35 +08:00
|
|
|
GLsizei _textureWidth;
|
2013-05-22 20:49:46 +08:00
|
|
|
|
2016-06-16 02:05:35 +08:00
|
|
|
typedef buffered_value< unsigned int > BufferDataModifiedCount;
|
|
|
|
mutable BufferDataModifiedCount _modifiedCount;
|
2013-06-28 20:00:43 +08:00
|
|
|
|
2016-06-16 02:05:35 +08:00
|
|
|
|
|
|
|
};
|
2013-05-22 20:49:46 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|