GameKit  0.0.1a
C++ gamedev tools
VertexBuffer.cpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: VertexBuffer.cpp
5  *
6  * Description:
7  *
8  * Created: 15/12/2014 17:10:16
9  *
10  * Author: Quentin Bazin, <quent42340@gmail.com>
11  *
12  * =====================================================================================
13  */
14 #include "gk/gl/GLCheck.hpp"
15 #include "gk/gl/VertexBuffer.hpp"
16 
17 namespace gk {
18 
20  glCheck(glGenBuffers(1, &m_id));
21 }
22 
24  m_id = vertexBuffer.m_id;
25  vertexBuffer.m_id = 0;
26 }
27 
29  glCheck(glDeleteBuffers(1, &m_id));
30 }
31 
32 void VertexBuffer::setData(GLsizeiptr size, const GLvoid *data, GLenum usage) const {
33  glCheck(glBufferData(GL_ARRAY_BUFFER, size, data, usage));
34 }
35 
36 void VertexBuffer::updateData(GLintptr offset, GLsizeiptr size, const GLvoid *data) const {
37  glCheck(glBufferSubData(GL_ARRAY_BUFFER, offset, size, data));
38 }
39 
40 void VertexBuffer::setAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer) const {
41  glCheck(glVertexAttribPointer(index, size, type, normalized, stride, pointer));
42 }
43 
44 void VertexBuffer::bind(const VertexBuffer *vertexBuffer) {
45  if(vertexBuffer) {
46  glCheck(glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer->m_id));
47  } else {
48  glCheck(glBindBuffer(GL_ARRAY_BUFFER, 0));
49  }
50 }
51 
52 } // namespace gk
53 
~VertexBuffer() noexcept
void updateData(GLintptr offset, GLsizeiptr size, const GLvoid *data) const
void setAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer) const
static void bind(const VertexBuffer *vertexBuffer)
#define glCheck(expr)
Definition: GLCheck.hpp:18
void setData(GLsizeiptr size, const GLvoid *data, GLenum usage) const