summaryrefslogtreecommitdiff
path: root/src/mbgl/gl/uniform.hpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2017-06-12 18:16:51 +0200
committerKonstantin Käfer <mail@kkaefer.com>2017-06-13 19:21:46 +0200
commit7f8f75b1c9d50fe02d0112717de5b4a79e1e44ce (patch)
tree7c68af71d5e6aa5c6628b94e6d2b039184b1df7d /src/mbgl/gl/uniform.hpp
parent9a05ebac5202b6e4b59f43707b96b4acd4c00b7b (diff)
downloadqtlocation-mapboxgl-7f8f75b1c9d50fe02d0112717de5b4a79e1e44ce.tar.gz
[core] verify that the active uniform types match our assumed types
Diffstat (limited to 'src/mbgl/gl/uniform.hpp')
-rw-r--r--src/mbgl/gl/uniform.hpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/mbgl/gl/uniform.hpp b/src/mbgl/gl/uniform.hpp
index 34a32aeee9..b877f10e46 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,11 +23,29 @@ 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:
void operator=(const Value& value) {
@@ -70,6 +89,18 @@ 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()) }... };
}