[core] Added stencilOp, depthFunc and blendFunc to GL config

All GL values are now reset upon Painter setup.
This commit is contained in:
Bruno de Oliveira Abinader
2015-10-20 11:34:50 -07:00
parent 5fa144647d
commit a1c53d92e5
3 changed files with 69 additions and 33 deletions

View File

@@ -3,17 +3,20 @@
namespace mbgl {
namespace gl {
const ClearDepth::Type ClearDepth::Default = 0;
const StencilFunc::Type StencilFunc::Default = { GL_ALWAYS, 0, ~0u };
const StencilMask::Type StencilMask::Default = ~0u;
const StencilTest::Type StencilTest::Default = GL_FALSE;
const StencilOp::Type StencilOp::Default = { GL_KEEP, GL_KEEP, GL_REPLACE };
const DepthRange::Type DepthRange::Default = { 0, 1 };
const DepthMask::Type DepthMask::Default = GL_TRUE;
const DepthTest::Type DepthTest::Default = GL_FALSE;
const DepthFunc::Type DepthFunc::Default = GL_LEQUAL;
const Blend::Type Blend::Default = GL_TRUE;
const BlendFunc::Type BlendFunc::Default = { GL_ONE, GL_ONE_MINUS_SRC_ALPHA };
const ColorMask::Type ColorMask::Default = { GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE };
const ClearDepth::Type ClearDepth::Default = 1;
const ClearColor::Type ClearColor::Default = { 0, 0, 0, 0 };
const ClearStencil::Type ClearStencil::Default = 0;
const StencilMask::Type StencilMask::Default = ~0u;
const DepthMask::Type DepthMask::Default = GL_TRUE;
const ColorMask::Type ColorMask::Default = { false, false, false, false };
const StencilFunc::Type StencilFunc::Default = { GL_ALWAYS, 0, ~0u };
const StencilTest::Type StencilTest::Default = false;
const DepthRange::Type DepthRange::Default = { 0, 1 };
const DepthTest::Type DepthTest::Default = false;
const Blend::Type Blend::Default = false;
}
}

View File

@@ -16,10 +16,15 @@ public:
inline void operator=(const typename T::Type& value) {
if (current != value) {
current = value;
MBGL_CHECK_ERROR(T::Set(current));
T::Set(current);
}
}
inline void reset() {
current = T::Default;
T::Set(current);
}
private:
typename T::Type current = T::Default;
};
@@ -100,6 +105,14 @@ struct StencilTest {
}
};
struct StencilOp {
struct Type { GLenum sfail, dpfail, dppass; };
static const Type Default;
inline static void Set(const Type& value) {
MBGL_CHECK_ERROR(glStencilOp(value.sfail, value.dpfail, value.dppass));
}
};
struct DepthRange {
struct Type { GLfloat near, far; };
static const Type Default;
@@ -120,6 +133,14 @@ struct DepthTest {
}
};
struct DepthFunc {
using Type = GLenum;
static const Type Default;
inline static void Set(const Type& value) {
MBGL_CHECK_ERROR(glDepthFunc(value));
}
};
struct Blend {
using Type = bool;
static const Type Default;
@@ -128,22 +149,50 @@ struct Blend {
}
};
struct BlendFunc {
struct Type { GLenum sfactor, dfactor; };
static const Type Default;
inline static void Set(const Type& value) {
MBGL_CHECK_ERROR(glBlendFunc(value.sfactor, value.dfactor));
}
};
class Config {
public:
void reset() {
stencilFunc.reset();
stencilMask.reset();
stencilTest.reset();
stencilOp.reset();
depthRange.reset();
depthMask.reset();
depthTest.reset();
depthFunc.reset();
blend.reset();
blendFunc.reset();
colorMask.reset();
clearDepth.reset();
clearColor.reset();
clearStencil.reset();
}
Value<StencilFunc> stencilFunc;
Value<StencilMask> stencilMask;
Value<StencilTest> stencilTest;
Value<StencilOp> stencilOp;
Value<DepthRange> depthRange;
Value<DepthMask> depthMask;
Value<DepthTest> depthTest;
Value<DepthFunc> depthFunc;
Value<Blend> blend;
Value<BlendFunc> blendFunc;
Value<ColorMask> colorMask;
Value<ClearDepth> clearDepth;
Value<ClearColor> clearColor;
Value<ClearStencil> clearStencil;
};
}
}
} // namespace gl
} // namespace mbgl
#endif
#endif // MBGL_RENDERER_GL_CONFIG

View File

@@ -72,24 +72,8 @@ void Painter::setup() {
assert(dotShader);
assert(circleShader);
// Blending
// We are blending new pixels on top of old pixels. Since we have depth testing
// and are drawing opaque fragments first front-to-back, then translucent
// fragments back-to-front, this shades the fewest fragments possible.
config.blend = true;
MBGL_CHECK_ERROR(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
// Set clear values
config.clearColor = { 0.0f, 0.0f, 0.0f, 0.0f };
config.clearDepth = 1.0f;
config.clearStencil = 0x0;
// Stencil test
MBGL_CHECK_ERROR(glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE));
// Depth test
glDepthFunc(GL_LEQUAL);
// Reset GL values
config.reset();
}
void Painter::setupShaders() {
@@ -145,9 +129,9 @@ void Painter::changeMatrix() {
void Painter::clear() {
MBGL_DEBUG_GROUP("clear");
config.stencilTest = true;
config.stencilTest = GL_TRUE;
config.stencilMask = 0xFF;
config.depthTest = false;
config.depthTest = GL_FALSE;
config.depthMask = GL_TRUE;
config.clearColor = { background[0], background[1], background[2], background[3] };
MBGL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));