diff options
25 files changed, 164 insertions, 0 deletions
diff --git a/cmake/core-files.txt b/cmake/core-files.txt index ec3c9266d8..6361540eb3 100644 --- a/cmake/core-files.txt +++ b/cmake/core-files.txt @@ -59,6 +59,8 @@ src/mbgl/gl/color_mode.cpp src/mbgl/gl/color_mode.hpp src/mbgl/gl/context.cpp src/mbgl/gl/context.hpp +src/mbgl/gl/cull_face_mode.cpp +src/mbgl/gl/cull_face_mode.hpp src/mbgl/gl/debugging.cpp src/mbgl/gl/debugging.hpp src/mbgl/gl/debugging_extension.cpp diff --git a/mapbox-gl-js b/mapbox-gl-js -Subproject e8fd41abae382f39f17a561a1461db90bd2204f +Subproject e682aa65da789df11fe7e76dbc56ada33e6e56a diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index 4afbe5af1e..22b22b549d 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(); + cullFaceSide.setDirty(); + frontFace.setDirty(); program.setDirty(); lineWidth.setDirty(); activeTextureUnit.setDirty(); @@ -663,6 +666,16 @@ void Context::clear(optional<mbgl::Color> color, MBGL_CHECK_ERROR(glClear(mask)); } +void Context::setCullFaceMode(const CullFaceMode& mode) { + cullFace = mode.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. + cullFaceSide = mode.side; + frontFace = mode.frontFace; +} + #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 c8181d7e80..f8cb546585 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -172,6 +172,7 @@ public: void setDepthMode(const DepthMode&); void setStencilMode(const StencilMode&); void setColorMode(const ColorMode&); + void setCullFaceMode(const CullFaceMode&); void draw(PrimitiveType, std::size_t indexOffset, @@ -263,6 +264,9 @@ private: State<value::ClearStencil> clearStencil; State<value::LineWidth> lineWidth; State<value::BindRenderbuffer> bindRenderbuffer; + State<value::CullFace> cullFace; + State<value::CullFaceSide> cullFaceSide; + State<value::FrontFace> frontFace; #if not MBGL_USE_GLES2 State<value::PointSize> pointSize; #endif // MBGL_USE_GLES2 diff --git a/src/mbgl/gl/cull_face_mode.cpp b/src/mbgl/gl/cull_face_mode.cpp new file mode 100644 index 0000000000..42729aeea7 --- /dev/null +++ b/src/mbgl/gl/cull_face_mode.cpp @@ -0,0 +1,16 @@ +#include <mbgl/gl/cull_face_mode.hpp> +#include <mbgl/gl/gl.hpp> +#include <mbgl/util/traits.hpp> + +namespace mbgl { +namespace gl { + +static_assert(underlying_type(CullFaceMode::Front) == GL_FRONT, "OpenGL enum mismatch"); +static_assert(underlying_type(CullFaceMode::Back) == GL_BACK, "OpenGL enum mismatch"); +static_assert(underlying_type(CullFaceMode::FrontAndBack) == GL_FRONT_AND_BACK, "OpenGL enum mismatch"); + +static_assert(underlying_type(CullFaceMode::Clockwise) == GL_CW, "OpenGL enum mismatch"); +static_assert(underlying_type(CullFaceMode::CounterClockwise) == GL_CCW, "OpenGL enum mismatch"); + +} // namespace gl +} // namespace mbgl diff --git a/src/mbgl/gl/cull_face_mode.hpp b/src/mbgl/gl/cull_face_mode.hpp new file mode 100644 index 0000000000..a408d7a88c --- /dev/null +++ b/src/mbgl/gl/cull_face_mode.hpp @@ -0,0 +1,40 @@ +#pragma once + +#include <cstdint> + +namespace mbgl { +namespace gl { + +class CullFaceMode { +public: + enum CullFace : bool { + Disable = false, + Enable = true, + }; + + enum CullFaceSide : uint32_t { + Front = 0x0404, + Back = 0x0405, + FrontAndBack = 0x0408, + }; + + enum FrontFace : uint32_t { + Clockwise = 0x0900, + CounterClockwise = 0x0901 + }; + + CullFace cullFace; + CullFaceSide side; + FrontFace frontFace; + + static CullFaceMode disabled() { + return CullFaceMode { Disable, CullFaceSide::Back, FrontFace::CounterClockwise }; + } + + static CullFaceMode backCCW() { + return CullFaceMode { Enable, CullFaceSide::Back, FrontFace::CounterClockwise }; + } +}; + +} // namespace gl +} // namespace mbgl diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp index f33501cd11..3ef7955949 100644 --- a/src/mbgl/gl/program.hpp +++ b/src/mbgl/gl/program.hpp @@ -118,6 +118,7 @@ public: DepthMode depthMode, StencilMode stencilMode, ColorMode colorMode, + CullFaceMode cullFaceMode, const UniformValues& uniformValues, VertexArray& vertexArray, const AttributeBindings& attributeBindings, @@ -130,6 +131,7 @@ public: context.setDepthMode(depthMode); context.setStencilMode(stencilMode); context.setColorMode(colorMode); + context.setCullFaceMode(cullFaceMode); context.program = program; diff --git a/src/mbgl/gl/value.cpp b/src/mbgl/gl/value.cpp index 092403af0d..581acd0358 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 == CullFaceMode::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 ? CullFaceMode::Enable : CullFaceMode::Disable; +} + +const constexpr CullFaceSide::Type CullFaceSide::Default; + +void CullFaceSide::Set(const Type& value) { + MBGL_CHECK_ERROR(glCullFace(static_cast<GLenum>(value))); +} + +CullFaceSide::Type CullFaceSide::Get() { + GLint cullFaceMode; + MBGL_CHECK_ERROR(glGetIntegerv(GL_CULL_FACE_MODE, &cullFaceMode)); + return static_cast<Type>(cullFaceMode); +} + +const constexpr FrontFace::Type FrontFace::Default; + +void FrontFace::Set(const Type& value) { + MBGL_CHECK_ERROR(glFrontFace(static_cast<GLenum>(value))); +} + +FrontFace::Type FrontFace::Get() { + GLint frontFace; + MBGL_CHECK_ERROR(glGetIntegerv(GL_FRONT_FACE, &frontFace)); + return static_cast<Type>(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 7b85a5ff4b..25f22aa038 100644 --- a/src/mbgl/gl/value.hpp +++ b/src/mbgl/gl/value.hpp @@ -4,6 +4,7 @@ #include <mbgl/gl/depth_mode.hpp> #include <mbgl/gl/stencil_mode.hpp> #include <mbgl/gl/color_mode.hpp> +#include <mbgl/gl/cull_face_mode.hpp> #include <mbgl/gl/attribute.hpp> #include <mbgl/util/color.hpp> #include <mbgl/util/size.hpp> @@ -212,6 +213,27 @@ struct BindRenderbuffer { static Type Get(); }; +struct CullFace { + using Type = CullFaceMode::CullFace; + static const constexpr Type Default = CullFaceMode::Disable; + static void Set(const Type&); + static Type Get(); +}; + +struct CullFaceSide { + using Type = CullFaceMode::CullFaceSide; + static const constexpr Type Default = CullFaceMode::Back; + static void Set(const Type&); + static Type Get(); +}; + +struct FrontFace { + using Type = CullFaceMode::FrontFace; + static const constexpr Type Default = CullFaceMode::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/programs/collision_box_program.hpp b/src/mbgl/programs/collision_box_program.hpp index 6e75adf36e..0b1abf97c7 100644 --- a/src/mbgl/programs/collision_box_program.hpp +++ b/src/mbgl/programs/collision_box_program.hpp @@ -61,6 +61,7 @@ public: gl::DepthMode depthMode, gl::StencilMode stencilMode, gl::ColorMode colorMode, + gl::CullFaceMode cullFaceMode, const UniformValues& uniformValues, const gl::VertexBuffer<CollisionBoxLayoutAttributes::Vertex>& layoutVertexBuffer, const gl::VertexBuffer<CollisionBoxDynamicAttributes::Vertex>& dynamicVertexBuffer, @@ -92,6 +93,7 @@ public: std::move(depthMode), std::move(stencilMode), std::move(colorMode), + std::move(cullFaceMode), allUniformValues, vertexArrayIt->second, Attributes::offsetBindings(allAttributeBindings, segment.vertexOffset), @@ -140,6 +142,7 @@ public: gl::DepthMode depthMode, gl::StencilMode stencilMode, gl::ColorMode colorMode, + gl::CullFaceMode cullFaceMode, const UniformValues& uniformValues, const gl::VertexBuffer<CollisionBoxLayoutAttributes::Vertex>& layoutVertexBuffer, const gl::VertexBuffer<CollisionBoxDynamicAttributes::Vertex>& dynamicVertexBuffer, @@ -169,6 +172,7 @@ public: std::move(depthMode), std::move(stencilMode), std::move(colorMode), + std::move(cullFaceMode), allUniformValues, vertexArrayIt->second, Attributes::offsetBindings(allAttributeBindings, segment.vertexOffset), diff --git a/src/mbgl/programs/program.hpp b/src/mbgl/programs/program.hpp index 4d5de05337..ddbda30686 100644 --- a/src/mbgl/programs/program.hpp +++ b/src/mbgl/programs/program.hpp @@ -73,6 +73,7 @@ public: gl::DepthMode depthMode, gl::StencilMode stencilMode, gl::ColorMode colorMode, + gl::CullFaceMode cullFaceMode, const gl::IndexBuffer<DrawMode>& indexBuffer, const SegmentVector<Attributes>& segments, const typename AllUniforms::Values& allUniformValues, @@ -91,6 +92,7 @@ public: std::move(depthMode), std::move(stencilMode), std::move(colorMode), + std::move(cullFaceMode), allUniformValues, vertexArrayIt->second, Attributes::offsetBindings(allAttributeBindings, segment.vertexOffset), diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp index 6d22e812fa..272c72ef99 100644 --- a/src/mbgl/programs/symbol_program.hpp +++ b/src/mbgl/programs/symbol_program.hpp @@ -311,6 +311,7 @@ public: gl::DepthMode depthMode, gl::StencilMode stencilMode, gl::ColorMode colorMode, + gl::CullFaceMode cullFaceMode, const gl::IndexBuffer<DrawMode>& indexBuffer, const SegmentVector<Attributes>& segments, const typename AllUniforms::Values& allUniformValues, @@ -329,6 +330,7 @@ public: std::move(depthMode), std::move(stencilMode), std::move(colorMode), + std::move(cullFaceMode), allUniformValues, vertexArrayIt->second, Attributes::offsetBindings(allAttributeBindings, segment.vertexOffset), diff --git a/src/mbgl/renderer/layers/render_background_layer.cpp b/src/mbgl/renderer/layers/render_background_layer.cpp index ad85fe0cce..f20bd7ae5e 100644 --- a/src/mbgl/renderer/layers/render_background_layer.cpp +++ b/src/mbgl/renderer/layers/render_background_layer.cpp @@ -76,6 +76,7 @@ void RenderBackgroundLayer::render(PaintParameters& parameters, RenderSource*) { parameters.depthModeForSublayer(0, gl::DepthMode::ReadOnly), gl::StencilMode::disabled(), parameters.colorModeForRenderPass(), + gl::CullFaceMode::disabled(), parameters.staticData.quadTriangleIndexBuffer, parameters.staticData.tileTriangleSegments, allUniformValues, diff --git a/src/mbgl/renderer/layers/render_circle_layer.cpp b/src/mbgl/renderer/layers/render_circle_layer.cpp index af96e2e991..46db06416d 100644 --- a/src/mbgl/renderer/layers/render_circle_layer.cpp +++ b/src/mbgl/renderer/layers/render_circle_layer.cpp @@ -106,6 +106,7 @@ void RenderCircleLayer::render(PaintParameters& parameters, RenderSource*) { ? parameters.stencilModeForClipping(tile.clip) : gl::StencilMode::disabled(), parameters.colorModeForRenderPass(), + gl::CullFaceMode::disabled(), *bucket.indexBuffer, bucket.segments, allUniformValues, diff --git a/src/mbgl/renderer/layers/render_custom_layer.cpp b/src/mbgl/renderer/layers/render_custom_layer.cpp index 16c18447c5..2bad375bb7 100644 --- a/src/mbgl/renderer/layers/render_custom_layer.cpp +++ b/src/mbgl/renderer/layers/render_custom_layer.cpp @@ -65,6 +65,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.setCullFaceMode(gl::CullFaceMode::disabled()); CustomLayerRenderParameters parameters; diff --git a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp index d6623455e0..0b5c05759c 100644 --- a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp @@ -109,6 +109,7 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource* parameters.depthModeFor3D(gl::DepthMode::ReadWrite), gl::StencilMode::disabled(), parameters.colorModeForRenderPass(), + gl::CullFaceMode::disabled(), *tileBucket.indexBuffer, tileBucket.triangleSegments, allUniformValues, @@ -209,6 +210,7 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource* gl::DepthMode::disabled(), gl::StencilMode::disabled(), parameters.colorModeForRenderPass(), + gl::CullFaceMode::disabled(), parameters.staticData.quadTriangleIndexBuffer, parameters.staticData.extrusionTextureSegments, allUniformValues, diff --git a/src/mbgl/renderer/layers/render_fill_layer.cpp b/src/mbgl/renderer/layers/render_fill_layer.cpp index e0edd37988..a0453121a8 100644 --- a/src/mbgl/renderer/layers/render_fill_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_layer.cpp @@ -119,6 +119,7 @@ void RenderFillLayer::render(PaintParameters& parameters, RenderSource*) { depthMode, parameters.stencilModeForClipping(tile.clip), parameters.colorModeForRenderPass(), + gl::CullFaceMode::disabled(), indexBuffer, segments, allUniformValues, @@ -208,6 +209,7 @@ void RenderFillLayer::render(PaintParameters& parameters, RenderSource*) { depthMode, parameters.stencilModeForClipping(tile.clip), parameters.colorModeForRenderPass(), + gl::CullFaceMode::disabled(), indexBuffer, segments, allUniformValues, diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.cpp b/src/mbgl/renderer/layers/render_heatmap_layer.cpp index 8e24cf8f32..62330bcab7 100644 --- a/src/mbgl/renderer/layers/render_heatmap_layer.cpp +++ b/src/mbgl/renderer/layers/render_heatmap_layer.cpp @@ -127,6 +127,7 @@ void RenderHeatmapLayer::render(PaintParameters& parameters, RenderSource*) { parameters.depthModeForSublayer(0, gl::DepthMode::ReadOnly), stencilMode, gl::ColorMode::additive(), + gl::CullFaceMode::disabled(), *bucket.indexBuffer, bucket.segments, allUniformValues, @@ -174,6 +175,7 @@ void RenderHeatmapLayer::render(PaintParameters& parameters, RenderSource*) { gl::DepthMode::disabled(), gl::StencilMode::disabled(), parameters.colorModeForRenderPass(), + gl::CullFaceMode::disabled(), parameters.staticData.quadTriangleIndexBuffer, parameters.staticData.extrusionTextureSegments, allUniformValues, diff --git a/src/mbgl/renderer/layers/render_hillshade_layer.cpp b/src/mbgl/renderer/layers/render_hillshade_layer.cpp index b96030f44d..835cb3f9f9 100644 --- a/src/mbgl/renderer/layers/render_hillshade_layer.cpp +++ b/src/mbgl/renderer/layers/render_hillshade_layer.cpp @@ -105,6 +105,7 @@ void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource* src parameters.depthModeForSublayer(0, gl::DepthMode::ReadOnly), gl::StencilMode::disabled(), parameters.colorModeForRenderPass(), + gl::CullFaceMode::disabled(), indexBuffer, segments, allUniformValues, @@ -165,6 +166,7 @@ void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource* src parameters.depthModeForSublayer(0, gl::DepthMode::ReadOnly), gl::StencilMode::disabled(), parameters.colorModeForRenderPass(), + gl::CullFaceMode::disabled(), parameters.staticData.quadTriangleIndexBuffer, parameters.staticData.rasterSegments, allUniformValues, diff --git a/src/mbgl/renderer/layers/render_line_layer.cpp b/src/mbgl/renderer/layers/render_line_layer.cpp index 3adcfc408e..2811a1ffdd 100644 --- a/src/mbgl/renderer/layers/render_line_layer.cpp +++ b/src/mbgl/renderer/layers/render_line_layer.cpp @@ -108,6 +108,7 @@ void RenderLineLayer::render(PaintParameters& parameters, RenderSource*) { parameters.depthModeForSublayer(0, gl::DepthMode::ReadOnly), parameters.stencilModeForClipping(tile.clip), parameters.colorModeForRenderPass(), + gl::CullFaceMode::disabled(), *bucket.indexBuffer, bucket.segments, allUniformValues, diff --git a/src/mbgl/renderer/layers/render_raster_layer.cpp b/src/mbgl/renderer/layers/render_raster_layer.cpp index b8df71b7c1..8e0651b65b 100644 --- a/src/mbgl/renderer/layers/render_raster_layer.cpp +++ b/src/mbgl/renderer/layers/render_raster_layer.cpp @@ -119,6 +119,7 @@ void RenderRasterLayer::render(PaintParameters& parameters, RenderSource* source parameters.depthModeForSublayer(0, gl::DepthMode::ReadOnly), gl::StencilMode::disabled(), parameters.colorModeForRenderPass(), + gl::CullFaceMode::disabled(), indexBuffer, segments, allUniformValues, diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp index 7b630a551a..df38d64d70 100644 --- a/src/mbgl/renderer/layers/render_symbol_layer.cpp +++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp @@ -122,6 +122,7 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) { : gl::DepthMode::disabled(), gl::StencilMode::disabled(), parameters.colorModeForRenderPass(), + gl::CullFaceMode::disabled(), *buffers.indexBuffer, buffers.segments, allUniformValues, @@ -254,6 +255,7 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) { gl::DepthMode::disabled(), gl::StencilMode::disabled(), parameters.colorModeForRenderPass(), + gl::CullFaceMode::disabled(), CollisionBoxProgram::UniformValues { uniforms::u_matrix::Value( tile.matrix ), uniforms::u_extrude_scale::Value( extrudeScale ), @@ -288,6 +290,7 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) { gl::DepthMode::disabled(), gl::StencilMode::disabled(), parameters.colorModeForRenderPass(), + gl::CullFaceMode::disabled(), CollisionCircleProgram::UniformValues { uniforms::u_matrix::Value( tile.matrix ), uniforms::u_extrude_scale::Value( extrudeScale ), diff --git a/src/mbgl/renderer/render_tile.cpp b/src/mbgl/renderer/render_tile.cpp index fcd8b77771..61b92fb6d4 100644 --- a/src/mbgl/renderer/render_tile.cpp +++ b/src/mbgl/renderer/render_tile.cpp @@ -99,6 +99,7 @@ void RenderTile::finishRender(PaintParameters& parameters) { gl::DepthMode::disabled(), parameters.stencilModeForClipping(clip), gl::ColorMode::unblended(), + gl::CullFaceMode::disabled(), *tile.debugBucket->indexBuffer, tile.debugBucket->segments, program.computeAllUniformValues( @@ -120,6 +121,7 @@ void RenderTile::finishRender(PaintParameters& parameters) { gl::DepthMode::disabled(), parameters.stencilModeForClipping(clip), gl::ColorMode::unblended(), + gl::CullFaceMode::disabled(), *tile.debugBucket->indexBuffer, tile.debugBucket->segments, program.computeAllUniformValues( @@ -143,6 +145,7 @@ void RenderTile::finishRender(PaintParameters& parameters) { gl::DepthMode::disabled(), parameters.stencilModeForClipping(clip), gl::ColorMode::unblended(), + gl::CullFaceMode::disabled(), parameters.staticData.tileBorderIndexBuffer, parameters.staticData.tileBorderSegments, program.computeAllUniformValues( diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp index 6f7814190d..84f6828186 100644 --- a/src/mbgl/renderer/renderer_impl.cpp +++ b/src/mbgl/renderer/renderer_impl.cpp @@ -509,6 +509,7 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) { gl::StencilMode::Replace }, gl::ColorMode::disabled(), + gl::CullFaceMode::disabled(), parameters.staticData.quadTriangleIndexBuffer, parameters.staticData.tileTriangleSegments, program.computeAllUniformValues( diff --git a/src/mbgl/renderer/sources/render_image_source.cpp b/src/mbgl/renderer/sources/render_image_source.cpp index f9ae5588d1..957403fc2f 100644 --- a/src/mbgl/renderer/sources/render_image_source.cpp +++ b/src/mbgl/renderer/sources/render_image_source.cpp @@ -67,6 +67,7 @@ void RenderImageSource::finishRender(PaintParameters& parameters) { gl::DepthMode::disabled(), gl::StencilMode::disabled(), gl::ColorMode::unblended(), + gl::CullFaceMode::disabled(), parameters.staticData.tileBorderIndexBuffer, parameters.staticData.tileBorderSegments, programInstance.computeAllUniformValues( |