From 9d2be044614c3719a88523e32f4d8155bd6debb8 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 14 Nov 2016 11:57:02 -0800 Subject: [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. --- src/mbgl/gl/context.cpp | 32 ++++---------------------------- src/mbgl/gl/context.hpp | 14 -------------- src/mbgl/gl/segment.hpp | 6 ++++++ 3 files changed, 10 insertions(+), 42 deletions(-) (limited to 'src/mbgl/gl') 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 #include -#include +#include 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 abandonedVertexArrays; std::vector abandonedFramebuffers; std::vector 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; - 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 + #include namespace mbgl { @@ -21,6 +23,10 @@ public: std::size_t vertexLength; std::size_t indexLength; + +private: + friend class Context; + mutable optional vao; }; template -- cgit v1.2.1