openscenegraph
TextureBuffer
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2013 Robert Osfield
2 *
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.
7 *
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.
12*/
13
14// -*-c++-*-
15
16#ifndef OSG_TEXTUREBUFFEROBJECT
17#define OSG_TEXTUREBUFFEROBJECT 1
18
19#include <osg/Texture>
20#include <osg/BufferObject>
21
22namespace osg {
23
24/** Encapsulates OpenGL texture buffer functionality in a Texture delegating its content to attached BufferObject
25*/
26class OSG_EXPORT TextureBuffer : public Texture
27{
28
29 public :
30
31 TextureBuffer();
32
33 TextureBuffer(BufferData* image);
34
35 /** Copy constructor using CopyOp to manage deep vs shallow copy. */
36 TextureBuffer(const TextureBuffer& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
37
38 META_StateAttribute(osg, TextureBuffer, TEXTURE);
39
40 /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
41 virtual int compare(const StateAttribute& rhs) const;
42
43 virtual GLenum getTextureTarget() const { return GL_TEXTURE_BUFFER; }
44
45 /** Sets the texture image. */
46 void setImage(Image* image);
47
48 /** Gets the texture image. */
49 Image* getImage() { return dynamic_cast<Image*>(_bufferData.get() ); }
50
51 /** Gets the const texture image. */
52 inline const Image* getImage() const { return dynamic_cast<Image*>(_bufferData.get() ); }
53
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]); }
56
57 inline unsigned int & getModifiedCount(unsigned int contextID) const
58 {
59 // get the modified count for the current contextID.
60 return _modifiedCount[contextID];
61 }
62
63 /** Sets the texture image, ignoring face. */
64 virtual void setImage(unsigned int, Image* image) { setImage(image); }
65
66 /** Gets the texture image, ignoring face. */
67 virtual Image* getImage(unsigned int) { return getImage(); }
68
69 /** Gets the const texture image, ignoring face. */
70 virtual const Image* getImage(unsigned int) const { return getImage(); }
71
72 /** Gets the number of images that can be assigned to the Texture. */
73 virtual unsigned int getNumImages() const { return 1; }
74
75
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; }
79
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; }
84
85 virtual void allocateMipmap(State& /*state*/) const {};
86
87 /** Bind the texture buffer.*/
88 virtual void apply(State& state) const;
89
90 /** Set setBufferData attached */
91 void setBufferData(BufferData *bo);
92
93 /** Set setBufferData attached */
94 const BufferData * getBufferData()const {return _bufferData.get();}
95 protected :
96
97 virtual ~TextureBuffer();
98
99 virtual void computeInternalFormat() const;
100
101 ref_ptr< BufferData > _bufferData;
102
103 GLsizei _textureWidth;
104
105 typedef buffered_value< unsigned int > BufferDataModifiedCount;
106 mutable BufferDataModifiedCount _modifiedCount;
107
108
109 };
110
111}
112
113#endif