NGL  6.5
The NCCA Graphics Library
SimpleIndexVAO.cpp
Go to the documentation of this file.
1 #include "SimpleIndexVAO.h"
2 #include <iostream>
3 namespace ngl
4 {
6  {
7  removeVAO();
8  }
9 
10  void SimpleIndexVAO::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  glDrawElements(m_mode,static_cast<GLsizei>(m_indicesCount),m_indexType,static_cast<GLvoid *>(nullptr));
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 
38  //void SimpleIndexVAO::setData(size_t _size, const GLfloat &_data, unsigned int _indexSize, const GLvoid *_indexData, GLenum _indexType, GLenum _mode )
40  {
41  const VertexData &data = static_cast<const VertexData &>(_data);
42  if(m_bound == false)
43  {
44  std::cerr<<"trying to set VOA data when unbound\n";
45  }
46  GLuint vboID;
47  glGenBuffers(1, &vboID);
48 
49  GLuint iboID;
50  glGenBuffers(1, &iboID);
51 
52  // now we will bind an array buffer to the first one and load the data for the verts
54  glBufferData(GL_ARRAY_BUFFER, static_cast<GLsizeiptr>(data.m_size), &data.m_data, data.m_mode);
55  // we need to determine the size of the data type before we set it
56  // in default to a ushort
57  int size=sizeof(GLushort);
58  switch(data.m_indexType)
59  {
60  case GL_UNSIGNED_INT : size=sizeof(GLuint); break;
61  case GL_UNSIGNED_SHORT : size=sizeof(GLushort); break;
62  case GL_UNSIGNED_BYTE : size=sizeof(GLubyte); break;
63  default : std::cerr<<"wrong data type send for index value\n"; break;
64  }
65  // now for the indices
67  glBufferData(GL_ELEMENT_ARRAY_BUFFER, data.m_indexSize * static_cast<GLsizeiptr>(size), const_cast<GLvoid *>(data.m_indexData),data.m_mode);
68 
69  m_allocated=true;
71  }
72 
73 }
unsigned int GLuint
Definition: glew.h:280
virtual void removeVAO()
remove the VAO and buffers created
#define GL_ELEMENT_ARRAY_BUFFER
Definition: glew.h:1649
unsigned short GLushort
Definition: glew.h:287
#define glDeleteVertexArrays
Definition: glew.h:7446
#define GL_UNSIGNED_BYTE
Definition: glew.h:637
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1382
implementation files for RibExport class
Definition: AABB.cpp:22
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
GLenum m_indexType
data type of the index data (e.g. GL_UNSIGNED_INT)
virtual ~SimpleIndexVAO()
dtor don&#39;t do anything as the remove clears things
virtual void draw() const
draw the VAO using glDrawArrays
#define glGenBuffers
Definition: glew.h:1709
GLuint m_id
the id of the VAO allocated from OpenGL
Definition: AbstractVAO.h:121
void unbind()
unbind the VAO by binding default 0
Definition: AbstractVAO.cpp:29
#define GL_UNSIGNED_INT
Definition: glew.h:641
#define GL_UNSIGNED_SHORT
Definition: glew.h:639
GLuint m_buffer
the id of the buffer for the VAO
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
GLsizeiptr size
Definition: glew.h:1684
#define glDeleteBuffers
Definition: glew.h:1706
#define glBindBuffer
Definition: glew.h:1703
#define GL_ARRAY_BUFFER
Definition: glew.h:1648
virtual void setData(const AbstractVAO::VertexData &_data)
, this method sets the data for the VAO if data has already been set it will remove the existing data...
#define glBufferData
Definition: glew.h:1704
GLAPI void GLAPIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
unsigned char GLubyte
Definition: glew.h:286