summaryrefslogtreecommitdiff
path: root/src/mbgl/gl/state.hpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-10-10 17:16:37 +0200
committerKonstantin Käfer <mail@kkaefer.com>2016-10-25 13:52:36 -0700
commita4d259c33f9bb890bba97fd89552720e3e0ec09b (patch)
tree342ecc27a6993c48f3a2e1d739fce890350bc44d /src/mbgl/gl/state.hpp
parent5cc390d694fc7510d445310d8eb9e32429a5e67b (diff)
downloadqtlocation-mapboxgl-a4d259c33f9bb890bba97fd89552720e3e0ec09b.tar.gz
[core] move gl::Context to Backend and refactor View
Diffstat (limited to 'src/mbgl/gl/state.hpp')
-rw-r--r--src/mbgl/gl/state.hpp36
1 files changed, 6 insertions, 30 deletions
diff --git a/src/mbgl/gl/state.hpp b/src/mbgl/gl/state.hpp
index dbb005e77d..efe869e5b9 100644
--- a/src/mbgl/gl/state.hpp
+++ b/src/mbgl/gl/state.hpp
@@ -3,20 +3,6 @@
namespace mbgl {
namespace gl {
-// Helper struct that allows obtaining the default value of a Value class
-template <typename T, typename = void>
-struct DefaultValue {
- static typename T::Type Get() {
- return T::Get();
- }
-};
-template <typename T>
-struct DefaultValue<T, decltype((void)T::Default, void())> {
- static typename T::Type Get() {
- return T::Default;
- }
-};
-
// Wraps a piece of OpenGL state and remember its value to avoid redundant state calls.
// Wrapped types need to implement to the Value class interface:
//
@@ -26,17 +12,12 @@ struct DefaultValue<T, decltype((void)T::Default, void())> {
// static void Set(const Type& value);
// static Type Get();
// };
-//
-// The Get() function is optional, but if it is omitted, you must provide a Default.
-// Default is also optional, but if it is omitted, you must provide a Get() function.
-// If both are present, DefaultValue<T>::Get() will use the Default member.
template <typename T>
class State {
public:
void operator=(const typename T::Type& value) {
if (*this != value) {
- dirty = false;
- currentValue = value;
+ setCurrentValue(value);
T::Set(currentValue);
}
}
@@ -49,9 +30,9 @@ public:
return dirty || currentValue != value;
}
- // Explicitly resets the piece of OpenGL state to its default value.
- void reset() {
- *this = defaultValue;
+ void setCurrentValue(const typename T::Type& value) {
+ dirty = false;
+ currentValue = value;
}
// Mark the state as dirty. This means that the next time we are assigning a value to this
@@ -68,14 +49,9 @@ public:
return dirty;
}
- void setDefaultValue(const typename T::Type& value) {
- defaultValue = value;
- }
-
private:
- typename T::Type defaultValue = DefaultValue<T>::Get();
- typename T::Type currentValue = defaultValue;
- bool dirty = false;
+ typename T::Type currentValue = T::Default;
+ bool dirty = true;
};
// Helper struct that stores the current state and restores it upon destruction. You should not use