diff options
Diffstat (limited to 'src/mbgl/gl/uniform.hpp')
-rw-r--r-- | src/mbgl/gl/uniform.hpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/mbgl/gl/uniform.hpp b/src/mbgl/gl/uniform.hpp index 3cac09c526..5a78068fc8 100644 --- a/src/mbgl/gl/uniform.hpp +++ b/src/mbgl/gl/uniform.hpp @@ -7,6 +7,7 @@ #include <array> #include <vector> +#include <map> #include <functional> namespace mbgl { @@ -22,13 +23,33 @@ public: T t; }; +class ActiveUniform { +public: + std::size_t size; + UniformDataType type; +}; + +#ifndef NDEBUG + +template <class T> +bool verifyUniform(const ActiveUniform&); + +using ActiveUniforms = std::map<std::string, ActiveUniform>; +ActiveUniforms activeUniforms(ProgramID); + +#endif + template <class Tag, class T> class Uniform { public: using Value = UniformValue<Tag, T>; + using Type = T; + class State { public: + State(UniformLocation location_) : location(std::move(location_)) {} + void operator=(const Value& value) { if (location >= 0 && (!current || *current != value.t)) { current = value.t; @@ -70,12 +91,24 @@ public: using NamedLocations = std::vector<std::pair<const std::string, UniformLocation>>; static State bindLocations(const ProgramID& id) { +#ifndef NDEBUG + // Verify active uniform types match the enum + const auto active = activeUniforms(id); + + util::ignore( + { // Some shader programs have uniforms declared, but not used, so they're not active. + // Therefore, we'll only verify them when they are indeed active. + (active.find(Us::name()) != active.end() + ? verifyUniform<typename Us::Type>(active.at(Us::name())) + : false)... }); +#endif + return State { { uniformLocation(id, Us::name()) }... }; } template <class Program> static State loadNamedLocations(const Program& program) { - return State{ { program.uniformLocation(Us::name()) }... }; + return State(typename Us::State(program.uniformLocation(Us::name()))...); } static NamedLocations getNamedLocations(const State& state) { |