summaryrefslogtreecommitdiff
path: root/src/geometry
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-01-29 15:31:22 +0100
committerKonstantin Käfer <mail@kkaefer.com>2014-01-29 15:31:22 +0100
commit2b59dfae6388f3ce4d38f8f9615c47d00b302518 (patch)
tree50f9cedd8466b3de6fdd9c79fdc5aee3aa6e1487 /src/geometry
parent3f9337b74c8d384f2635d0a6adc33869169300fc (diff)
downloadqtlocation-mapboxgl-2b59dfae6388f3ce4d38f8f9615c47d00b302518.tar.gz
move static global buffers to RAII
Diffstat (limited to 'src/geometry')
-rw-r--r--src/geometry/vertex_buffer.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/geometry/vertex_buffer.cpp b/src/geometry/vertex_buffer.cpp
new file mode 100644
index 0000000000..b190e31d8b
--- /dev/null
+++ b/src/geometry/vertex_buffer.cpp
@@ -0,0 +1,30 @@
+#include <llmr/geometry/vertex_buffer.hpp>
+#include <llmr/platform/gl.hpp>
+
+using namespace llmr;
+
+
+VertexBuffer::VertexBuffer(std::initializer_list<int16_t> init) : array(init) {}
+
+VertexBuffer::~VertexBuffer() {
+ if (buffer != 0) {
+ glDeleteBuffers(1, &buffer);
+ buffer = 0;
+ }
+}
+
+uint32_t VertexBuffer::length() const {
+ // We store 2 coordinates per vertex + 1 linesofar + 1 extrude coord pair == 4 (== 8 bytes)
+ return array.size() / 2;
+}
+
+void VertexBuffer::bind() {
+ if (buffer == 0) {
+ glGenBuffers(1, &buffer);
+ glBindBuffer(GL_ARRAY_BUFFER, buffer);
+ glBufferData(GL_ARRAY_BUFFER, array.size() * sizeof(int16_t), array.data(), GL_STATIC_DRAW);
+ } else {
+ glBindBuffer(GL_ARRAY_BUFFER, buffer);
+ }
+
+}