From 2e10c0a8660af9cdf6ff897aaa39e15fe62c6582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 7 Jul 2016 16:29:34 +0200 Subject: [core] don't force GL state to be set when calling .reset() We are using Value::reset() to change a piece of GL state to its default value. However, the current implementation always executes the GL call, even if our state tracking system knows that it's already at that value. The new implementation of Value::reset() now respects that, resulting in a lot fewer GL calls. --- include/mbgl/gl/gl_values.hpp | 4 ++++ src/mbgl/gl/gl_config.hpp | 4 +--- src/mbgl/renderer/painter.cpp | 1 + test/gl/object.cpp | 6 ++++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/mbgl/gl/gl_values.hpp b/include/mbgl/gl/gl_values.hpp index 1e05984fbc..b15ef18f48 100644 --- a/include/mbgl/gl/gl_values.hpp +++ b/include/mbgl/gl/gl_values.hpp @@ -140,6 +140,10 @@ struct StencilOp { } }; +constexpr bool operator!=(const StencilOp::Type& a, const StencilOp::Type& b) { + return a.sfail != b.sfail || a.dpfail != b.dpfail || a.dppass != b.dppass; +} + struct DepthRange { struct Type { GLfloat near, far; }; static const Type Default; diff --git a/src/mbgl/gl/gl_config.hpp b/src/mbgl/gl/gl_config.hpp index 09080ca365..9d7dfb3b6c 100644 --- a/src/mbgl/gl/gl_config.hpp +++ b/src/mbgl/gl/gl_config.hpp @@ -21,9 +21,7 @@ public: } void reset() { - dirty = true; - current = T::Default; - T::Set(current); + *this = T::Default; } void setDirty() { diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index e5c88de635..ba68b5a24d 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -83,6 +83,7 @@ Painter::Painter(const TransformState& state_, overdrawShader.circle = std::make_unique(store, Shader::Overdraw); // Reset GL values + config.setDirty(); config.reset(); } diff --git a/test/gl/object.cpp b/test/gl/object.cpp index 5e7a158939..1506c33956 100644 --- a/test/gl/object.cpp +++ b/test/gl/object.cpp @@ -18,11 +18,13 @@ static bool setFlag = false; struct MockGLObject { using Type = bool; - static const Type Default = false; + static const Type Default; static Type Get() { getFlag = true; return true; } static void Set(const Type&) { setFlag = true; } }; +const bool MockGLObject::Default = false; + TEST(GLObject, Preserve) { getFlag = false; setFlag = false; @@ -61,7 +63,7 @@ TEST(GLObject, Value) { object->reset(); EXPECT_EQ(object->getCurrent(), false); - EXPECT_TRUE(object->getDirty()); + EXPECT_FALSE(object->getDirty()); EXPECT_TRUE(setFlag); } -- cgit v1.2.1