summaryrefslogtreecommitdiff
path: root/src/mbgl/geometry/buffer.hpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2015-04-22 17:52:10 +0200
committerKonstantin Käfer <mail@kkaefer.com>2015-05-04 17:33:04 +0200
commitc891df0b5f3e946840324dbe238f29c1fba16ea3 (patch)
tree232e4ac8a0a4f2a6bd9b95ee36bf62aa6eb96432 /src/mbgl/geometry/buffer.hpp
parent5beb635028b6634f57ae874a416a291999f31e97 (diff)
downloadqtlocation-mapboxgl-c891df0b5f3e946840324dbe238f29c1fba16ea3.tar.gz
add upload API to gl objects
Diffstat (limited to 'src/mbgl/geometry/buffer.hpp')
-rw-r--r--src/mbgl/geometry/buffer.hpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/mbgl/geometry/buffer.hpp b/src/mbgl/geometry/buffer.hpp
index 4198425ecf..01af5df18e 100644
--- a/src/mbgl/geometry/buffer.hpp
+++ b/src/mbgl/geometry/buffer.hpp
@@ -2,6 +2,7 @@
#define MBGL_GEOMETRY_BUFFER
#include <mbgl/platform/gl.hpp>
+#include <mbgl/platform/log.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/map/environment.hpp>
@@ -38,17 +39,16 @@ public:
}
// Transfers this buffer to the GPU and binds the buffer to the GL context.
- void bind(bool force = false) {
- if (buffer == 0) {
+ void bind() {
+ if (buffer) {
+ MBGL_CHECK_ERROR(glBindBuffer(bufferType, buffer));
+ } else {
MBGL_CHECK_ERROR(glGenBuffers(1, &buffer));
- force = true;
- }
- MBGL_CHECK_ERROR(glBindBuffer(bufferType, buffer));
- if (force) {
+ MBGL_CHECK_ERROR(glBindBuffer(bufferType, buffer));
if (array == nullptr) {
- throw std::runtime_error("Buffer was already deleted or doesn't contain elements");
+ Log::Debug(Event::OpenGL, "Buffer doesn't contain elements");
+ pos = 0;
}
-
MBGL_CHECK_ERROR(glBufferData(bufferType, pos, array, GL_STATIC_DRAW));
if (!retainAfterUpload) {
cleanup();
@@ -67,6 +67,12 @@ public:
return buffer;
}
+ inline void upload() {
+ if (!buffer) {
+ bind();
+ }
+ }
+
protected:
// increase the buffer size by at least /required/ bytes.
inline void *addElement() {