NGL  6.5
The NCCA Graphics Library
SimpleVAO.cpp
Go to the documentation of this file.
1 #include "SimpleVAO.h"
2 #include <iostream>
3 namespace ngl
4 {
6  {
7  removeVAO();
8  }
9 
10  void SimpleVAO::draw() const
11  {
12  if(m_allocated == false)
13  {
14  std::cerr<<"Warning trying to draw an unallocated VOA\n";
15  }
16  if(m_bound == false)
17  {
18  std::cerr<<"Warning trying to draw an unbound VOA\n";
19  }
20  glDrawArrays(m_mode, 0, static_cast<GLsizei>(m_indicesCount));
21  }
22 
24  {
25  if(m_bound == true)
26  {
27  unbind();
28  }
29  if( m_allocated ==true)
30  {
32  }
34  m_allocated=false;
35  }
36 
37  void SimpleVAO::setData(const VertexData &_data)
38  {
39  if(m_bound == false)
40  {
41  std::cerr<<"trying to set VOA data when unbound\n";
42  }
43  if( m_allocated ==true)
44  {
46  }
47 
49  // now we will bind an array buffer to the first one and load the data for the verts
51  glBufferData(GL_ARRAY_BUFFER,static_cast<GLsizeiptr>( _data.m_size), &_data.m_data, _data.m_mode);
52  m_allocated=true;
53 
54  }
55 
56 }
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...
Definition: SimpleVAO.cpp:37
#define glDeleteVertexArrays
Definition: glew.h:7446
virtual ~SimpleVAO()
dtor clears the VAO data
Definition: SimpleVAO.cpp:5
implementation files for RibExport class
Definition: AABB.cpp:22
GLenum m_mode
the draw mode
Definition: AbstractVAO.h:117
virtual void draw() const
draw the VAO using glDrawArrays
Definition: SimpleVAO.cpp:10
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)
#define glGenBuffers
Definition: glew.h:1709
GLuint m_id
the id of the VAO allocated from OpenGL
Definition: AbstractVAO.h:121
virtual void removeVAO()
remove the VAO and buffers created
Definition: SimpleVAO.cpp:23
void unbind()
unbind the VAO by binding default 0
Definition: AbstractVAO.cpp:29
size_t m_indicesCount
the number of indices stored in the VAO.
Definition: AbstractVAO.h:133
bool m_allocated
debug flag to indicate if data has been set for the VAO
Definition: AbstractVAO.h:129
#define glDeleteBuffers
Definition: glew.h:1706
GLuint m_buffer
the id of the buffer for the VAO
Definition: SimpleVAO.h:80
#define glBindBuffer
Definition: glew.h:1703
#define GL_ARRAY_BUFFER
Definition: glew.h:1648
#define glBufferData
Definition: glew.h:1704