summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-11-14 11:57:02 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-11-15 13:55:08 -0800
commit9d2be044614c3719a88523e32f4d8155bd6debb8 (patch)
tree718ec2f7adb7e73ef724ab070e7e7722247e338b
parent377d0fb0d20fa4129d867f0e8762ce208ccee14d (diff)
downloadqtlocation-mapboxgl-9d2be044614c3719a88523e32f4d8155bd6debb8.tar.gz
[core] Return to static, per-segment approach to VAOs
This is safer now -- it can be an implementation detail of Segment/Context. And the typing of SegmentVector now ensures that the attributes and program match.
-rw-r--r--src/mbgl/gl/context.cpp32
-rw-r--r--src/mbgl/gl/context.hpp14
-rw-r--r--src/mbgl/gl/segment.hpp6
3 files changed, 10 insertions, 42 deletions
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp
index 3251be0c87..41e81a186f 100644
--- a/src/mbgl/gl/context.cpp
+++ b/src/mbgl/gl/context.cpp
@@ -6,7 +6,7 @@
#include <mbgl/util/std.hpp>
#include <mbgl/platform/log.hpp>
-#include <boost/functional/hash.hpp>
+#include <cstring>
namespace mbgl {
namespace gl {
@@ -434,15 +434,6 @@ PrimitiveType Context::operator()(const TriangleStrip&) {
return PrimitiveType::TriangleStrip;
}
-std::size_t Context::VertexArrayObjectHash::operator()(const VertexArrayObjectKey& key) const {
- std::size_t seed = 0;
- boost::hash_combine(seed, std::get<0>(key));
- boost::hash_combine(seed, std::get<1>(key));
- boost::hash_combine(seed, std::get<2>(key));
- boost::hash_combine(seed, std::get<3>(key));
- return seed;
-}
-
void Context::setDepthMode(const DepthMode& depth) {
if (depth.func == DepthMode::Always && !depth.mask) {
depthTest = false;
@@ -503,23 +494,15 @@ void Context::draw(const Drawable& drawable) {
return true;
}
- VertexArrayObjectKey vaoKey {
- drawable.program,
- drawable.vertexBuffer,
- drawable.indexBuffer,
- segment.vertexOffset
- };
-
- auto it = vaos.find(vaoKey);
- if (it != vaos.end()) {
- vertexArrayObject = it->second;
+ if (segment.vao) {
+ vertexArrayObject = *segment.vao;
return false;
}
VertexArrayID id = 0;
MBGL_CHECK_ERROR(gl::GenVertexArrays(1, &id));
vertexArrayObject = id;
- vaos.emplace(vaoKey, UniqueVertexArray(std::move(id), { this }));
+ segment.vao = UniqueVertexArray(std::move(id), { this });
// If we are initializing a new VAO, we need to force the buffers
// to be rebound. VAOs don't inherit the existing buffer bindings.
@@ -555,9 +538,6 @@ void Context::performCleanup() {
if (program == id) {
program.setDirty();
}
- mbgl::util::erase_if(vaos, [&] (const VertexArrayObjectMap::value_type& kv) {
- return std::get<0>(kv.first) == id;
- });
MBGL_CHECK_ERROR(glDeleteProgram(id));
}
abandonedPrograms.clear();
@@ -574,10 +554,6 @@ void Context::performCleanup() {
} else if (elementBuffer == id) {
elementBuffer.setDirty();
}
- mbgl::util::erase_if(vaos, [&] (const VertexArrayObjectMap::value_type& kv) {
- return std::get<1>(kv.first) == id
- || std::get<2>(kv.first) == id;
- });
}
MBGL_CHECK_ERROR(glDeleteBuffers(int(abandonedBuffers.size()), abandonedBuffers.data()));
abandonedBuffers.clear();
diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp
index 33b7a555a8..093afa20ed 100644
--- a/src/mbgl/gl/context.hpp
+++ b/src/mbgl/gl/context.hpp
@@ -233,20 +233,6 @@ private:
std::vector<VertexArrayID> abandonedVertexArrays;
std::vector<FramebufferID> abandonedFramebuffers;
std::vector<RenderbufferID> abandonedRenderbuffers;
-
- using VertexArrayObjectKey = std::tuple<
- ProgramID, // Program
- BufferID, // Vertex buffer
- BufferID, // Index buffer
- std::size_t // Vertex buffer offset
- >;
-
- struct VertexArrayObjectHash {
- std::size_t operator()(const VertexArrayObjectKey&) const;
- };
-
- using VertexArrayObjectMap = std::unordered_map<VertexArrayObjectKey, UniqueVertexArray, VertexArrayObjectHash>;
- VertexArrayObjectMap vaos;
};
} // namespace gl
diff --git a/src/mbgl/gl/segment.hpp b/src/mbgl/gl/segment.hpp
index 283b4f572a..0a735ababf 100644
--- a/src/mbgl/gl/segment.hpp
+++ b/src/mbgl/gl/segment.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include <mbgl/util/optional.hpp>
+
#include <cstddef>
namespace mbgl {
@@ -21,6 +23,10 @@ public:
std::size_t vertexLength;
std::size_t indexLength;
+
+private:
+ friend class Context;
+ mutable optional<UniqueVertexArray> vao;
};
template <class Attributes>