summaryrefslogtreecommitdiff
path: root/src/mbgl/programs/program.hpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-06-05 12:15:27 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-06-13 12:21:50 -0700
commit9d276f3b0f0e5f1b5089a6cd727927361e6634ac (patch)
treebbf0c446055126f060e8ee759b7b71281dea8f80 /src/mbgl/programs/program.hpp
parent18b50f51b4fa14b9f2fe6f865dc47490b22e74c6 (diff)
downloadqtlocation-mapboxgl-9d276f3b0f0e5f1b5089a6cd727927361e6634ac.tar.gz
[core] Dynamic program compilation for data-driven properties
Diffstat (limited to 'src/mbgl/programs/program.hpp')
-rw-r--r--src/mbgl/programs/program.hpp35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/mbgl/programs/program.hpp b/src/mbgl/programs/program.hpp
index 3351f5eeae..36bbdf349e 100644
--- a/src/mbgl/programs/program.hpp
+++ b/src/mbgl/programs/program.hpp
@@ -9,18 +9,21 @@
#include <mbgl/shaders/shaders.hpp>
#include <mbgl/util/io.hpp>
+#include <unordered_map>
+
namespace mbgl {
template <class Shaders,
class Primitive,
class LayoutAttrs,
class Uniforms,
- class PaintProperties>
+ class PaintProps>
class Program {
public:
using LayoutAttributes = LayoutAttrs;
using LayoutVertex = typename LayoutAttributes::Vertex;
+ using PaintProperties = PaintProps;
using PaintPropertyBinders = typename PaintProperties::Binders;
using PaintAttributes = typename PaintPropertyBinders::Attributes;
using Attributes = gl::ConcatenateAttributes<LayoutAttributes, PaintAttributes>;
@@ -71,4 +74,34 @@ public:
}
};
+template <class Program>
+class ProgramMap {
+public:
+ using PaintProperties = typename Program::PaintProperties;
+ using PaintPropertyBinders = typename Program::PaintPropertyBinders;
+ using Bitset = typename PaintPropertyBinders::Bitset;
+
+ ProgramMap(gl::Context& context_, ProgramParameters parameters_)
+ : context(context_),
+ parameters(std::move(parameters_)) {
+ }
+
+ Program& get(const typename PaintProperties::PossiblyEvaluated& currentProperties) {
+ Bitset bits = PaintPropertyBinders::constants(currentProperties);
+ auto it = programs.find(bits);
+ if (it != programs.end()) {
+ return it->second;
+ }
+ return programs.emplace(std::piecewise_construct,
+ std::forward_as_tuple(bits),
+ std::forward_as_tuple(context,
+ parameters.withAdditionalDefines(PaintPropertyBinders::defines(currentProperties)))).first->second;
+ }
+
+private:
+ gl::Context& context;
+ ProgramParameters parameters;
+ std::unordered_map<Bitset, Program> programs;
+};
+
} // namespace mbgl