diff --git a/src/mbgl/renderer/gl_config.cpp b/src/mbgl/renderer/gl_config.cpp index ae648d4d3..c7425fd5f 100644 --- a/src/mbgl/renderer/gl_config.cpp +++ b/src/mbgl/renderer/gl_config.cpp @@ -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; } } diff --git a/src/mbgl/renderer/gl_config.hpp b/src/mbgl/renderer/gl_config.hpp index 59507f721..078dcabe7 100644 --- a/src/mbgl/renderer/gl_config.hpp +++ b/src/mbgl/renderer/gl_config.hpp @@ -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; Value stencilMask; Value stencilTest; + Value stencilOp; Value depthRange; Value depthMask; Value depthTest; + Value depthFunc; Value blend; + Value blendFunc; Value colorMask; Value clearDepth; Value clearColor; Value clearStencil; }; -} -} +} // namespace gl +} // namespace mbgl -#endif +#endif // MBGL_RENDERER_GL_CONFIG diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index a7ffd8269..c4b6e559a 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -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));