NGL  6.5
The NCCA Graphics Library
VertexArrayObject.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Jon Macey
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #ifndef VERTEXARRAYOBJECT_H_
18 #define VERTEXARRAYOBJECT_H_
19 //----------------------------------------------------------------------------------------------------------------------
22 //----------------------------------------------------------------------------------------------------------------------
23 #include <vector>
24 #define BUFFER_OFFSET(i) (reinterpret_cast<void*>(i))
25 
26 
27 // must include types.h first for Real and GLEW if required
28 #include "Types.h"
29 
30 
31 //----------------------------------------------------------------------------------------------------------------------
40 //----------------------------------------------------------------------------------------------------------------------
41 namespace ngl
42 {
43 
44 //----------------------------------------------------------------------------------------------------------------------
47 //----------------------------------------------------------------------------------------------------------------------
48 
49 #warning This Class is deprecated and should not be used. [[deprecated("use factories instead")]]
51 {
52 
53 public:
54  //----------------------------------------------------------------------------------------------------------------------
57  //----------------------------------------------------------------------------------------------------------------------
59  {
60  return new VertexArrayObject(_mode);
61  }
62  //----------------------------------------------------------------------------------------------------------------------
64  //----------------------------------------------------------------------------------------------------------------------
65  void bind();
66  //----------------------------------------------------------------------------------------------------------------------
68  //----------------------------------------------------------------------------------------------------------------------
69  void unbind();
70  //----------------------------------------------------------------------------------------------------------------------
72  //----------------------------------------------------------------------------------------------------------------------
73  void removeVOA();
74  //----------------------------------------------------------------------------------------------------------------------
77  //----------------------------------------------------------------------------------------------------------------------
78  GLuint getID()const {return m_id;}
79  //----------------------------------------------------------------------------------------------------------------------
82  //----------------------------------------------------------------------------------------------------------------------
83  bool isBound()const {return m_bound;}
84  //----------------------------------------------------------------------------------------------------------------------
87  //----------------------------------------------------------------------------------------------------------------------
88  bool isAllocated()const {return m_allocated;}
89  //----------------------------------------------------------------------------------------------------------------------
95  //----------------------------------------------------------------------------------------------------------------------
96  void setData(size_t _size, const GLfloat &_data, GLenum _mode=GL_STATIC_DRAW );
97  //----------------------------------------------------------------------------------------------------------------------
108  //----------------------------------------------------------------------------------------------------------------------
109  void setIndexedData(size_t _size,const GLfloat &_data,unsigned int _indexSize,const GLvoid *_indexData,GLenum _indexType,GLenum _mode=GL_STATIC_DRAW);
110  //----------------------------------------------------------------------------------------------------------------------
121  //----------------------------------------------------------------------------------------------------------------------
122  void setRawIndexedData(size_t _size, const GLvoid *_data, unsigned int _indexSize, const GLvoid *_indexData, GLenum _indexType, GLenum _mode=GL_STATIC_DRAW );
123  //----------------------------------------------------------------------------------------------------------------------
128  //----------------------------------------------------------------------------------------------------------------------
129  void updateIndexedData(size_t _size, const GLfloat &_data, GLenum _mode=GL_STREAM_DRAW);
130  void updateIndexedData(GLuint _vboidx, size_t _size, const GLfloat &_data, GLenum _mode=GL_STREAM_DRAW);
131  //----------------------------------------------------------------------------------------------------------------------
136  //----------------------------------------------------------------------------------------------------------------------
137  void updateData(unsigned int _size,const GLfloat &_data,GLenum _mode=GL_STREAM_DRAW);
138  void updateData(GLuint _vboidx, unsigned int _size, const GLfloat &_data, GLenum _mode=GL_STREAM_DRAW);
139 
140  //----------------------------------------------------------------------------------------------------------------------
149  //----------------------------------------------------------------------------------------------------------------------
150  void setVertexAttributePointer(GLuint _id,GLint _size,GLenum _type,GLsizei _stride,unsigned int _dataOffset,bool _normalise=GL_FALSE);
151  //----------------------------------------------------------------------------------------------------------------------
157  //----------------------------------------------------------------------------------------------------------------------
158  void setVertexAttributeIPointer(GLuint _id, GLint _size, GLenum _type, GLsizei _stride, unsigned int _dataOffset);
159  //----------------------------------------------------------------------------------------------------------------------
165  //----------------------------------------------------------------------------------------------------------------------
166  GLuint getVBOid(unsigned int _index );
167  //----------------------------------------------------------------------------------------------------------------------
169  //----------------------------------------------------------------------------------------------------------------------
170  void draw() const;
171  //----------------------------------------------------------------------------------------------------------------------
174  //----------------------------------------------------------------------------------------------------------------------
175  void draw(GLenum _mode) const;
176  //----------------------------------------------------------------------------------------------------------------------
181  //----------------------------------------------------------------------------------------------------------------------
182  void draw(unsigned int _startIndex, unsigned int _numVerts, GLenum _mode=GL_TRIANGLES ) const;
183 
184  //----------------------------------------------------------------------------------------------------------------------
187  //----------------------------------------------------------------------------------------------------------------------
188  void drawInstanced(GLenum _n) const;
189  //----------------------------------------------------------------------------------------------------------------------
192  //----------------------------------------------------------------------------------------------------------------------
193  void setNumIndices(size_t _n){m_indicesCount=_n;}
194  //----------------------------------------------------------------------------------------------------------------------
197  //----------------------------------------------------------------------------------------------------------------------
198  unsigned int getNumIndices() const {return m_indicesCount; }
199  //----------------------------------------------------------------------------------------------------------------------
206  //----------------------------------------------------------------------------------------------------------------------
207  #ifdef USINGIOS_
208  Real *getDataPointer(unsigned int _vbo,GLenum _accessMode);
209  #else
210  Real *getDataPointer(unsigned int _vbo,GLenum _accessMode=GL_READ_WRITE);
211  #endif
212  //----------------------------------------------------------------------------------------------------------------------
214  //----------------------------------------------------------------------------------------------------------------------
215  void freeDataPointer();
216  //----------------------------------------------------------------------------------------------------------------------
218  //----------------------------------------------------------------------------------------------------------------------
219  int getSize() const;
220  //----------------------------------------------------------------------------------------------------------------------
222  //----------------------------------------------------------------------------------------------------------------------
224 
225 protected :
226  //----------------------------------------------------------------------------------------------------------------------
228  //----------------------------------------------------------------------------------------------------------------------
230  //----------------------------------------------------------------------------------------------------------------------
232  //----------------------------------------------------------------------------------------------------------------------
234  //----------------------------------------------------------------------------------------------------------------------
236  //----------------------------------------------------------------------------------------------------------------------
238  //----------------------------------------------------------------------------------------------------------------------
240  //----------------------------------------------------------------------------------------------------------------------
242  //----------------------------------------------------------------------------------------------------------------------
244  //----------------------------------------------------------------------------------------------------------------------
245  bool m_indexed;
246  //----------------------------------------------------------------------------------------------------------------------
249  //----------------------------------------------------------------------------------------------------------------------
251  //----------------------------------------------------------------------------------------------------------------------
253  //----------------------------------------------------------------------------------------------------------------------
255  //----------------------------------------------------------------------------------------------------------------------
257  //----------------------------------------------------------------------------------------------------------------------
258  bool m_bound;
259  //----------------------------------------------------------------------------------------------------------------------
261  //----------------------------------------------------------------------------------------------------------------------
262  std::vector <GLuint> m_vboIDs;
263  //----------------------------------------------------------------------------------------------------------------------
265  //----------------------------------------------------------------------------------------------------------------------
267  //----------------------------------------------------------------------------------------------------------------------
269  //----------------------------------------------------------------------------------------------------------------------
270  VertexArrayObject(GLenum _mode);
271  //----------------------------------------------------------------------------------------------------------------------
273  //----------------------------------------------------------------------------------------------------------------------
275  //----------------------------------------------------------------------------------------------------------------------
277  //----------------------------------------------------------------------------------------------------------------------
278 
279 };
280 
281 
282 }
283 #endif
284 
285 //----------------------------------------------------------------------------------------------------------------------
bool m_indexed
flag to indicate if we have an index or non index vao to draw
unsigned int GLuint
Definition: glew.h:280
void GLvoid
Definition: glew.h:293
main definition of types and namespace
#define GL_STATIC_DRAW
Definition: glew.h:1671
#define NGL_DLLEXPORT
Definition: Types.h:65
#define GL_STREAM_DRAW
Definition: glew.h:1668
#define GL_FALSE
Definition: glew.h:314
#define GL_TRIANGLES
Definition: glew.h:330
bool isAllocated() const
accesor to see if VOA has allocated data
GLenum m_drawMode
the draw mode of the VAO e.g. GL_TRIANGLES
bool isBound() const
accesor to see if VOA is bound
unsigned int GLenum
Definition: glew.h:278
implementation files for RibExport class
Definition: AABB.cpp:22
float GLfloat
Definition: glew.h:289
GLuint getID() const
accesor for the VOA id
PRECISION Real
create a variable called Real which is the main data type we use (GLfloat for most cases) ...
Definition: Types.h:127
static VertexArrayObject * createVOA(GLenum _mode)
method to return a newVOA object
bool m_bound
flag to indicate if we are bound
VertexArrayObject()
hide the ctor as we want to create static factory only
unsigned int getNumIndices() const
get the number of indices in the vao
#define GL_READ_WRITE
Definition: glew.h:1664
bool m_allocated
flag to indicate if we have allocated the data to the VAO
GLuint m_id
the id of the VAO allocated by OpenGL
std::vector< GLuint > m_vboIDs
an array of VBO associated with this VAO
void setNumIndices(size_t _n)
set the number of faces to draw
a class to encapsulate an OpenGL VAO
GLuint m_indicesCount
the number of faces to draw
GLuint m_iboID
the id of the index bufffer object
int GLint
Definition: glew.h:281
GLenum m_indexType
Specifies the type of the values in the indices buffer. Must be one of GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, or GL_UNSIGNED_INT.
int GLsizei
Definition: glew.h:282
~VertexArrayObject()
dtor doesn&#39;t do anything use the removeVAO method instead