NGL  6.5
The NCCA Graphics Library
MultiBufferVAO.cpp
Go to the documentation of this file.
1 #include "MultiBufferVAO.h"
2 #include <iostream>
3 #include <NGLassert.h>
4 namespace ngl
5 {
7  {
8  removeVAO();
9  }
10 
11  void MultiBufferVAO::draw() const
12  {
13  if(m_allocated == false)
14  {
15  std::cerr<<"Warning trying to draw an unallocated VOA\n";
16  }
17  if(m_bound == false)
18  {
19  std::cerr<<"Warning trying to draw an unbound VOA\n";
20  }
21  glDrawArrays(m_mode, 0, static_cast<GLsizei>(m_indicesCount));
22  }
23 
25  {
26  if(m_bound == true)
27  {
28  unbind();
29  }
30  if( m_allocated ==true)
31  {
32  for(auto b : m_vboIDs)
33  {
34  glDeleteBuffers(1,&b);
35  }
37  m_allocated=false;
38  }
39  }
41  {
42  if(m_bound == false)
43  {
44  std::cerr<<"trying to set VOA data when unbound\n";
45  }
46 
47  GLuint vboID;
48  glGenBuffers(1, &vboID);
49  m_vboIDs.push_back(vboID);
50  // now we will bind an array buffer to the first one and load the data for the verts
52  glBufferData(GL_ARRAY_BUFFER,static_cast<GLsizeiptr>(_data.m_size), &_data.m_data, _data.m_mode);
53  m_allocated=true;
54 
55  }
56 
58  {
59  NGL_ASSERT(_id<m_vboIDs.size());
60  return m_vboIDs[_id];
61  }
62 
63 
64 
65 }
virtual void setData(const VertexData &_data)
, this method sets the data for the VAO if data has already been set it will remove the existing data...
unsigned int GLuint
Definition: glew.h:280
#define glDeleteVertexArrays
Definition: glew.h:7446
virtual void removeVAO()
remove the VAO and buffers created
implementation files for RibExport class
Definition: AABB.cpp:22
GLdouble GLdouble GLdouble b
Definition: glew.h:9162
GLenum m_mode
the draw mode
Definition: AbstractVAO.h:117
bool m_bound
debug flag to indicate if the vao is bound.
Definition: AbstractVAO.h:125
GLAPI void GLAPIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count)
virtual GLuint getBufferID(unsigned int _id)
return the id of the buffer, if there is only 1 buffer just return this if we have the more than one ...
#define glGenBuffers
Definition: glew.h:1709
GLuint m_id
the id of the VAO allocated from OpenGL
Definition: AbstractVAO.h:121
std::vector< GLuint > m_vboIDs
the id of the buffers for the VAO
void unbind()
unbind the VAO by binding default 0
Definition: AbstractVAO.cpp:29
virtual void draw() const
draw the VAO using glDrawArrays
size_t m_indicesCount
the number of indices stored in the VAO.
Definition: AbstractVAO.h:133
#define NGL_ASSERT(X)
re-define the standard assert to work for ngl first check to see if assert is defined and undef it th...
Definition: NGLassert.h:53
bool m_allocated
debug flag to indicate if data has been set for the VAO
Definition: AbstractVAO.h:129
virtual ~MultiBufferVAO()
dtor don&#39;t do anything as the remove clears things
#define glDeleteBuffers
Definition: glew.h:1706
#define glBindBuffer
Definition: glew.h:1703
#define GL_ARRAY_BUFFER
Definition: glew.h:1648
re impliment asserts so we don&#39;t exit on failure
#define glBufferData
Definition: glew.h:1704