OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TextureBuffer.h
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 
22 namespace osg {
23 
27 {
28 
29  public :
30 
31  TextureBuffer();
32 
33  TextureBuffer(Image* image);
34 
36  TextureBuffer(const TextureBuffer& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
37 
39 
41  virtual int compare(const StateAttribute& rhs) const;
42 
43  virtual GLenum getTextureTarget() const { return GL_TEXTURE_BUFFER; }
44 
46  void setImage(Image* image);
47 
49  Image* getImage() { return _image.get(); }
50 
52  inline const Image* getImage() const { return _image.get(); }
53 
54  inline unsigned int& getModifiedCount(unsigned int contextID) const
55  {
56  // get the modified count for the current contextID.
57  return _modifiedCount[contextID];
58  }
59 
60 
62  virtual void setImage(unsigned int, Image* image) { setImage(image); }
63 
65  virtual Image* getImage(unsigned int) { return _image.get(); }
66 
68  virtual const Image* getImage(unsigned int) const { return _image.get(); }
69 
71  virtual unsigned int getNumImages() const { return 1; }
72 
73 
76  inline void setTextureWidth(int width) { _textureWidth = width; }
77 
79  virtual int getTextureWidth() const { return _textureWidth; }
80  virtual int getTextureHeight() const { return 1; }
81  virtual int getTextureDepth() const { return 1; }
82 
83  inline void setUsageHint( GLenum usageHint ) { _usageHint=usageHint; }
84  inline GLenum getUsageHint() const { return _usageHint; }
85 
86  virtual void allocateMipmap(State& /*state*/) const {};
87 
89  virtual void apply(State& state) const;
90 
92  void bindBufferAs(unsigned int contextID, GLenum target);
93  void unbindBufferAs(unsigned int contextID, GLenum target);
94 
95  protected :
96 
97  virtual ~TextureBuffer();
98 
99  virtual void computeInternalFormat() const;
100 
102 
103  mutable GLsizei _textureWidth;
104  GLenum _usageHint;
105 
107  mutable ImageModifiedCount _modifiedCount;
108 
110  {
111  public:
112  TextureBufferObject(unsigned int contextID, GLenum usageHint) :
113  _id(0),
114  _usageHint(usageHint)
115  {
116  _extensions = osg::GLExtensions::Get(contextID, true);
117  }
118 
119  void bindBuffer(GLenum target);
120  void unbindBuffer(GLenum target);
121 
122  void texBuffer(GLenum internalFormat);
123  void bufferData( osg::Image* image );
124  void bufferSubData( osg::Image* image );
125 
126  public:
127  GLuint _id;
128  GLenum _usageHint;
130  };
131 
133  mutable TextureBufferObjectList _textureBufferObjects;
134 };
135 
136 }
137 
138 #endif
#define OSG_EXPORT
Definition: Export.h:43
buffered_value< unsigned int > ImageModifiedCount
virtual Image * getImage(unsigned int)
Definition: TextureBuffer.h:65
GLint GLenum internalFormat
Definition: GLU.h:71
virtual int getTextureDepth() const
Definition: TextureBuffer.h:81
GLenum getUsageHint() const
Definition: TextureBuffer.h:84
osg::buffered_object< osg::ref_ptr< TextureBufferObject > > TextureBufferObjectList
#define GL_TEXTURE_BUFFER
Definition: GLDefines.h:400
virtual GLenum getTextureTarget() const
Definition: TextureBuffer.h:43
virtual void setImage(unsigned int, Image *image)
Definition: TextureBuffer.h:62
unsigned int & getModifiedCount(unsigned int contextID) const
Definition: TextureBuffer.h:54
TextureBufferObject(unsigned int contextID, GLenum usageHint)
virtual void allocateMipmap(State &) const
Definition: TextureBuffer.h:86
GLint GLenum GLsizei width
Definition: GLU.h:71
virtual unsigned int getNumImages() const
Definition: TextureBuffer.h:71
ref_ptr< Image > _image
virtual int getTextureWidth() const
Definition: TextureBuffer.h:79
TextureBufferObjectList _textureBufferObjects
#define META_StateAttribute(library, name, type)
Definition: AlphaFunc.h:19
virtual int getTextureHeight() const
Definition: TextureBuffer.h:80
void setTextureWidth(int width)
Definition: TextureBuffer.h:76
static GLExtensions * Get(unsigned int contextID, bool createIfNotInitalized)
const Image * getImage() const
Definition: TextureBuffer.h:52
ImageModifiedCount _modifiedCount
virtual const Image * getImage(unsigned int) const
Definition: TextureBuffer.h:68
void setUsageHint(GLenum usageHint)
Definition: TextureBuffer.h:83