[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.
This commit is contained in:
Konstantin Käfer
2016-07-07 16:29:34 +02:00
parent ab1face71f
commit 2e10c0a866
4 changed files with 10 additions and 5 deletions

View File

@@ -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;

View File

@@ -21,9 +21,7 @@ public:
}
void reset() {
dirty = true;
current = T::Default;
T::Set(current);
*this = T::Default;
}
void setDirty() {

View File

@@ -83,6 +83,7 @@ Painter::Painter(const TransformState& state_,
overdrawShader.circle = std::make_unique<CircleShader>(store, Shader::Overdraw);
// Reset GL values
config.setDirty();
config.reset();
}

View File

@@ -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);
}