SimpleGL  1.1.0
A framework for platform independent rendering
vertex_buffer_object.cpp
Go to the documentation of this file.
1 
9 
11 
12 using namespace std;
13 
14 namespace sgl {
15  Buffer* Buffer::current = nullptr;
16 
17  Buffer::Buffer(void) {
18  glGenBuffers(1, &handle);
19  }
20 
21  Buffer::~Buffer(void) {
22  glDeleteBuffers(1, &handle);
23 
24  /* Set current to nullptr if this was the bound vertex buffer object */
25  if (Buffer::current == this) {
26  Buffer::current = nullptr;
27  }
28  }
29 
30  GLuint Buffer::getHandle() {
31  return handle;
32  }
33 
34  void Buffer::bind(BufferTarget target) {
35  /* If already bound return immediately */
36  if (Buffer::current == this) {
37  return;
38  }
39 
40  /* Bind buffer object */
41  glBindBuffer(to_GLenum(target), handle);
42  Buffer::current = this;
43  }
44 
45  void Buffer::uploadData(BufferTarget target, long size, float* data, BufferUsage usage) {
46  glBufferData(to_GLenum(target), size, data, to_GLenum(usage));
47  }
48 
49  void Buffer::uploadData(BufferTarget target, long size, std::vector<float> data, BufferUsage usage) {
50  glBufferData(to_GLenum(target), size, data.data(), to_GLenum(usage));
51  }
52 
53  void Buffer::uploadData(BufferTarget target, long size, std::vector<glm::vec2> data, BufferUsage usage) {
54  glBufferData(to_GLenum(target), size, data.data(), to_GLenum(usage));
55  }
56 
57  void Buffer::uploadData(BufferTarget target, long size, std::vector<glm::vec3> data, BufferUsage usage) {
58  glBufferData(to_GLenum(target), size, data.data(), to_GLenum(usage));
59  }
60 
61  void Buffer::uploadData(BufferTarget target, long size, std::vector<glm::vec4> data, BufferUsage usage) {
62  glBufferData(to_GLenum(target), size, data.data(), to_GLenum(usage));
63  }
64 
65  void Buffer::uploadData(BufferTarget target, long size, BufferUsage usage) {
66  glBufferData(to_GLenum(target), size, nullptr, to_GLenum(usage));
67  }
68 
69  void Buffer::uploadSubData(BufferTarget target, long offset, long size, float* data) {
70  glBufferSubData(to_GLenum(target), offset, size, data);
71  }
72 
73  void Buffer::uploadSubData(BufferTarget target, long offset, long size, std::vector<float> data) {
74  glBufferSubData(to_GLenum(target), offset, size, data.data());
75  }
76 
77  void Buffer::uploadSubData(BufferTarget target, long offset, long size, std::vector<glm::vec2> data) {
78  glBufferSubData(to_GLenum(target), offset, size, data.data());
79  }
80 
81  void Buffer::uploadSubData(BufferTarget target, long offset, long size, std::vector<glm::vec3> data) {
82  glBufferSubData(to_GLenum(target), offset, size, data.data());
83  }
84 
85  void Buffer::uploadSubData(BufferTarget target, long offset, long size, std::vector<glm::vec4> data) {
86  glBufferSubData(to_GLenum(target), offset, size, data.data());
87  }
88 
89  void* Buffer::map(BufferTarget target, MapAccess access) {
90  return glMapBuffer(to_GLenum(target), to_GLenum(access));
91  }
92 
93  void* Buffer::mapRange(BufferTarget target, long offset, long length, MapRangeAccess access) {
94  return glMapBufferRange(to_GLenum(target), offset, length, to_GLbitfield(access));
95  }
96 
97  void Buffer::unmap(BufferTarget target) {
98  glUnmapBuffer(to_GLenum(target));
99  }
100 }
BufferUsage
This enum wraps the buffer object&#39;s usages.
MapRangeAccess
This enum wraps the buffer object&#39;s map range access bits.
GLenum to_GLenum(E e)
Gets the GLenum value from an enum class.
Definition: backend_gl.tcc:22
Generic namespace for the SimpleGL framework.
Definition: application.hpp:18
MapAccess
This enum wraps the buffer object&#39;s map accesses.
GLbitfield to_GLbitfield(E e)
Gets the GLbitfield value from an enum class.
Definition: backend_gl.tcc:27
BufferTarget
This enum wraps the buffer object&#39;s targets.