From 9d276f3b0f0e5f1b5089a6cd727927361e6634ac Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 5 Jun 2017 12:15:27 -0700 Subject: [core] Dynamic program compilation for data-driven properties --- src/mbgl/programs/program.hpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/mbgl/programs/program.hpp') 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 #include +#include + namespace mbgl { template + 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; @@ -71,4 +74,34 @@ public: } }; +template +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 programs; +}; + } // namespace mbgl -- cgit v1.2.1