[core] Dynamic program compilation for data-driven properties
This commit is contained in:
@@ -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::Evaluated& 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
|
||||
|
||||
Reference in New Issue
Block a user