diff --git a/mapbox-gl-js b/mapbox-gl-js index 6b60f98e974..105c69c3312 160000 --- a/mapbox-gl-js +++ b/mapbox-gl-js @@ -1 +1 @@ -Subproject commit 6b60f98e9743cabac71c4a09c055a0bcd1fdca50 +Subproject commit 105c69c331238a6660009e539ed8811fa8bd2968 diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index 4afbe5af1e0..d7c03cd96c4 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -617,6 +617,9 @@ void Context::setDirtyState() { clearDepth.setDirty(); clearColor.setDirty(); clearStencil.setDirty(); + cullFace.setDirty(); + cullFaceMode.setDirty(); + frontFace.setDirty(); program.setDirty(); lineWidth.setDirty(); activeTextureUnit.setDirty(); @@ -663,6 +666,15 @@ void Context::clear(optional color, MBGL_CHECK_ERROR(glClear(mask)); } +void Context::setCullFace(CullFace cullFace_, optional cullFaceMode_, optional frontFace_) { + cullFace = cullFace_; + // These shouldn't need to be updated when face culling is disabled, but we + // might end up having the same isssues with Adreno 2xx GPUs as noted in + // Context::setDepthMode. + cullFaceMode = cullFaceMode_.value_or(gl::value::CullFaceMode::Default); + frontFace = frontFace_.value_or(gl::value::FrontFace::Default); +} + #if not MBGL_USE_GLES2 void Context::setDrawMode(const Points& points) { pointSize = points.pointSize; diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index c8181d7e800..784e2568160 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -163,6 +163,8 @@ class Context { optional depth, optional stencil); + void setCullFace(CullFace, optional = CullFaceMode::Back, optional = FrontFace::CounterClockwise); + void setDrawMode(const Points&); void setDrawMode(const Lines&); void setDrawMode(const LineStrip&); @@ -263,6 +265,9 @@ class Context { State clearStencil; State lineWidth; State bindRenderbuffer; + State cullFace; + State cullFaceMode; + State frontFace; #if not MBGL_USE_GLES2 State pointSize; #endif // MBGL_USE_GLES2 diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp index f33501cd11e..89bb1eb3adf 100644 --- a/src/mbgl/gl/program.hpp +++ b/src/mbgl/gl/program.hpp @@ -130,6 +130,7 @@ class Program { context.setDepthMode(depthMode); context.setStencilMode(stencilMode); context.setColorMode(colorMode); + context.setCullFace(CullFace::Enable, CullFaceMode::Back); context.program = program; diff --git a/src/mbgl/gl/types.hpp b/src/mbgl/gl/types.hpp index 376a784a0c5..04ba0a9d350 100644 --- a/src/mbgl/gl/types.hpp +++ b/src/mbgl/gl/types.hpp @@ -119,5 +119,21 @@ enum class BufferUsage : uint32_t { DynamicDraw = 0x88E8, }; +enum class CullFace : bool { + Disable = false, + Enable = true, +}; + +enum class CullFaceMode : uint32_t { + Front = 0x0404, + Back = 0x0405, + FrontAndBack = 0x0408, +}; + +enum class FrontFace : uint32_t { + Clockwise = 0x0900, + CounterClockwise = 0x0901 +}; + } // namespace gl } // namespace mbgl diff --git a/src/mbgl/gl/value.cpp b/src/mbgl/gl/value.cpp index 092403af0d8..c7c39f2fd4e 100644 --- a/src/mbgl/gl/value.cpp +++ b/src/mbgl/gl/value.cpp @@ -303,6 +303,42 @@ BindRenderbuffer::Type BindRenderbuffer::Get() { return binding; } +const constexpr CullFace::Type CullFace::Default; + +void CullFace::Set(const Type& value) { + MBGL_CHECK_ERROR(value == gl::CullFace::Enable ? glEnable(GL_CULL_FACE) : glDisable(GL_CULL_FACE)); +} + +CullFace::Type CullFace::Get() { + GLboolean cullFace; + MBGL_CHECK_ERROR(cullFace = glIsEnabled(GL_CULL_FACE)); + return cullFace ? gl::CullFace::Enable : gl::CullFace::Disable; +} + +const constexpr CullFaceMode::Type CullFaceMode::Default; + +void CullFaceMode::Set(const Type& value) { + MBGL_CHECK_ERROR(glCullFace(static_cast(value))); +} + +CullFaceMode::Type CullFaceMode::Get() { + GLint cullFaceMode; + MBGL_CHECK_ERROR(glGetIntegerv(GL_CULL_FACE_MODE, &cullFaceMode)); + return static_cast(cullFaceMode); +} + +const constexpr FrontFace::Type FrontFace::Default; + +void FrontFace::Set(const Type& value) { + MBGL_CHECK_ERROR(glFrontFace(static_cast(value))); +} + +FrontFace::Type FrontFace::Get() { + GLint frontFace; + MBGL_CHECK_ERROR(glGetIntegerv(GL_FRONT_FACE, &frontFace)); + return static_cast(frontFace); +} + const constexpr BindTexture::Type BindTexture::Default; void BindTexture::Set(const Type& value) { diff --git a/src/mbgl/gl/value.hpp b/src/mbgl/gl/value.hpp index 7b85a5ff4bf..1677df2979b 100644 --- a/src/mbgl/gl/value.hpp +++ b/src/mbgl/gl/value.hpp @@ -212,6 +212,27 @@ struct BindRenderbuffer { static Type Get(); }; +struct CullFace { + using Type = gl::CullFace; + static const constexpr Type Default = gl::CullFace::Disable; + static void Set(const Type&); + static Type Get(); +}; + +struct CullFaceMode { + using Type = gl::CullFaceMode; + static const constexpr Type Default = gl::CullFaceMode::Back; + static void Set(const Type&); + static Type Get(); +}; + +struct FrontFace { + using Type = gl::FrontFace; + static const constexpr Type Default = gl::FrontFace::CounterClockwise; + static void Set(const Type&); + static Type Get(); +}; + struct BindTexture { using Type = gl::TextureID; static const constexpr Type Default = 0; diff --git a/src/mbgl/renderer/layers/render_custom_layer.cpp b/src/mbgl/renderer/layers/render_custom_layer.cpp index be9f64d9eb7..4c7d2219fd9 100644 --- a/src/mbgl/renderer/layers/render_custom_layer.cpp +++ b/src/mbgl/renderer/layers/render_custom_layer.cpp @@ -62,6 +62,7 @@ void RenderCustomLayer::render(PaintParameters& paintParameters, RenderSource*) glContext.setDepthMode(paintParameters.depthModeForSublayer(0, gl::DepthMode::ReadOnly)); glContext.setStencilMode(gl::StencilMode::disabled()); glContext.setColorMode(paintParameters.colorModeForRenderPass()); + glContext.setCullFace(gl::CullFace::Disable); CustomLayerRenderParameters parameters;