diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-07-06 08:06:12 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-07-12 14:48:22 -0700 |
commit | 358b0305ae1f52b477ae145bcca4b7af242dd5c3 (patch) | |
tree | f5b1315e650079fce12130611896836e1c8cfa98 | |
parent | c61041b44cd9181641db2351f4657cc356300226 (diff) | |
download | qtlocation-mapboxgl-358b0305ae1f52b477ae145bcca4b7af242dd5c3.tar.gz |
[core] Per-segment-per-layer vertex arrays
Reduces rebinding, matches gl-js, and works around the buggy VAO implementation on PowerVR SGX544 GPUs.
-rw-r--r-- | src/mbgl/programs/program.hpp | 11 | ||||
-rw-r--r-- | src/mbgl/programs/segment.hpp | 9 | ||||
-rw-r--r-- | src/mbgl/programs/symbol_program.hpp | 11 | ||||
-rw-r--r-- | src/mbgl/renderer/painter.cpp | 15 | ||||
-rw-r--r-- | src/mbgl/renderer/painters/painter_background.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/renderer/painters/painter_circle.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/renderer/painters/painter_clipping.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/renderer/painters/painter_debug.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/renderer/painters/painter_fill.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/renderer/painters/painter_fill_extrusion.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/renderer/painters/painter_line.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/renderer/painters/painter_raster.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/renderer/painters/painter_symbol.cpp | 6 |
13 files changed, 61 insertions, 27 deletions
diff --git a/src/mbgl/programs/program.hpp b/src/mbgl/programs/program.hpp index 0199752b06..71d7569f53 100644 --- a/src/mbgl/programs/program.hpp +++ b/src/mbgl/programs/program.hpp @@ -58,7 +58,8 @@ public: const SegmentVector<Attributes>& segments, const PaintPropertyBinders& paintPropertyBinders, const typename PaintProperties::PossiblyEvaluated& currentProperties, - float currentZoom) { + float currentZoom, + const std::string& layerID) { typename AllUniforms::Values allUniformValues = uniformValues .concat(paintPropertyBinders.uniformValues(currentZoom, currentProperties)); @@ -66,8 +67,10 @@ public: .concat(paintPropertyBinders.attributeBindings(currentProperties)); for (auto& segment : segments) { - if (!segment.vertexArray) { - segment.vertexArray = context.createVertexArray(); + optional<gl::VertexArray>& vertexArray = segment.vertexArrays[layerID]; + + if (!vertexArray) { + vertexArray = context.createVertexArray(); } program.draw( @@ -77,7 +80,7 @@ public: std::move(stencilMode), std::move(colorMode), allUniformValues, - *segment.vertexArray, + *vertexArray, Attributes::offsetBindings(allAttributeBindings, segment.vertexOffset), indexBuffer, segment.indexOffset, diff --git a/src/mbgl/programs/segment.hpp b/src/mbgl/programs/segment.hpp index d8cc9679d7..74bf4a75c5 100644 --- a/src/mbgl/programs/segment.hpp +++ b/src/mbgl/programs/segment.hpp @@ -28,7 +28,14 @@ public: std::size_t vertexLength; std::size_t indexLength; - mutable optional<gl::VertexArray> vertexArray; + // One VertexArray per layer ID. This minimizes rebinding in cases where + // several layers share buckets but have different sets of active attributes. + // This can happen: + // * when two layers have the same layout properties, but differing + // data-driven paint properties + // * when two fill layers have the same layout properties, but one + // uses fill-color and the other uses fill-pattern + mutable std::map<std::string, optional<gl::VertexArray>> vertexArrays; }; template <class Attributes> diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp index 8c59cfd5a2..ee4855cf8f 100644 --- a/src/mbgl/programs/symbol_program.hpp +++ b/src/mbgl/programs/symbol_program.hpp @@ -315,7 +315,8 @@ public: const SegmentVector<Attributes>& segments, const PaintPropertyBinders& paintPropertyBinders, const typename PaintProperties::PossiblyEvaluated& currentProperties, - float currentZoom) { + float currentZoom, + const std::string& layerID) { typename AllUniforms::Values allUniformValues = uniformValues .concat(symbolSizeBinder.uniformValues(currentZoom)) .concat(paintPropertyBinders.uniformValues(currentZoom, currentProperties)); @@ -325,8 +326,10 @@ public: .concat(paintPropertyBinders.attributeBindings(currentProperties)); for (auto& segment : segments) { - if (!segment.vertexArray) { - segment.vertexArray = context.createVertexArray(); + optional<gl::VertexArray>& vertexArray = segment.vertexArrays[layerID]; + + if (!vertexArray) { + vertexArray = context.createVertexArray(); } program.draw( @@ -336,7 +339,7 @@ public: std::move(stencilMode), std::move(colorMode), allUniformValues, - *segment.vertexArray, + *vertexArray, Attributes::offsetBindings(allAttributeBindings, segment.vertexOffset), indexBuffer, segment.indexOffset, diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 35d03e7cb4..9ab50e83b0 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -316,16 +316,23 @@ void Painter::renderPass(PaintParameters& parameters, const Properties<>::PossiblyEvaluated properties; parameters.programs.extrusionTexture.draw( - context, gl::Triangles(), gl::DepthMode::disabled(), gl::StencilMode::disabled(), + context, + gl::Triangles(), + gl::DepthMode::disabled(), + gl::StencilMode::disabled(), colorModeForRenderPass(), ExtrusionTextureProgram::UniformValues{ uniforms::u_matrix::Value{ viewportMat }, uniforms::u_world::Value{ size }, uniforms::u_image::Value{ 0 }, uniforms::u_opacity::Value{ layer.as<RenderFillExtrusionLayer>() ->evaluated.get<FillExtrusionOpacity>() } }, - extrusionTextureVertexBuffer, quadTriangleIndexBuffer, extrusionTextureSegments, - ExtrusionTextureProgram::PaintPropertyBinders{ properties, 0 }, properties, - state.getZoom()); + extrusionTextureVertexBuffer, + quadTriangleIndexBuffer, + extrusionTextureSegments, + ExtrusionTextureProgram::PaintPropertyBinders{ properties, 0 }, + properties, + state.getZoom(), + layer.getID()); } else { renderItem(parameters, item); } diff --git a/src/mbgl/renderer/painters/painter_background.cpp b/src/mbgl/renderer/painters/painter_background.cpp index 577d7d6cda..661da0cc99 100644 --- a/src/mbgl/renderer/painters/painter_background.cpp +++ b/src/mbgl/renderer/painters/painter_background.cpp @@ -54,7 +54,8 @@ void Painter::renderBackground(PaintParameters& parameters, const RenderBackgrou tileTriangleSegments, paintAttibuteData, properties, - state.getZoom() + state.getZoom(), + layer.getID() ); } } else { @@ -74,7 +75,8 @@ void Painter::renderBackground(PaintParameters& parameters, const RenderBackgrou tileTriangleSegments, paintAttibuteData, properties, - state.getZoom() + state.getZoom(), + layer.getID() ); } } diff --git a/src/mbgl/renderer/painters/painter_circle.cpp b/src/mbgl/renderer/painters/painter_circle.cpp index a077f557fc..72a17d19fb 100644 --- a/src/mbgl/renderer/painters/painter_circle.cpp +++ b/src/mbgl/renderer/painters/painter_circle.cpp @@ -52,7 +52,8 @@ void Painter::renderCircle(PaintParameters& parameters, bucket.segments, bucket.paintPropertyBinders.at(layer.getID()), properties, - state.getZoom() + state.getZoom(), + layer.getID() ); } diff --git a/src/mbgl/renderer/painters/painter_clipping.cpp b/src/mbgl/renderer/painters/painter_clipping.cpp index cad092594e..025019b5c7 100644 --- a/src/mbgl/renderer/painters/painter_clipping.cpp +++ b/src/mbgl/renderer/painters/painter_clipping.cpp @@ -30,7 +30,8 @@ void Painter::renderClippingMask(const UnwrappedTileID& tileID, const ClipID& cl tileTriangleSegments, paintAttibuteData, properties, - state.getZoom() + state.getZoom(), + "clipping" ); } diff --git a/src/mbgl/renderer/painters/painter_debug.cpp b/src/mbgl/renderer/painters/painter_debug.cpp index ee76aee54c..989bbab5e5 100644 --- a/src/mbgl/renderer/painters/painter_debug.cpp +++ b/src/mbgl/renderer/painters/painter_debug.cpp @@ -39,7 +39,8 @@ void Painter::renderTileDebug(const RenderTile& renderTile) { segments, paintAttibuteData, properties, - state.getZoom() + state.getZoom(), + "debug" ); }; @@ -100,7 +101,8 @@ void Painter::renderTileDebug(const mat4& matrix) { tileBorderSegments, paintAttibuteData, properties, - state.getZoom() + state.getZoom(), + "debug" ); } } diff --git a/src/mbgl/renderer/painters/painter_fill.cpp b/src/mbgl/renderer/painters/painter_fill.cpp index 3a0bfed454..3ca3bdf6b8 100644 --- a/src/mbgl/renderer/painters/painter_fill.cpp +++ b/src/mbgl/renderer/painters/painter_fill.cpp @@ -61,7 +61,8 @@ void Painter::renderFill(PaintParameters& parameters, segments, bucket.paintPropertyBinders.at(layer.getID()), properties, - state.getZoom() + state.getZoom(), + layer.getID() ); }; @@ -105,7 +106,8 @@ void Painter::renderFill(PaintParameters& parameters, segments, bucket.paintPropertyBinders.at(layer.getID()), properties, - state.getZoom() + state.getZoom(), + layer.getID() ); }; diff --git a/src/mbgl/renderer/painters/painter_fill_extrusion.cpp b/src/mbgl/renderer/painters/painter_fill_extrusion.cpp index 165476944b..d7310dc208 100644 --- a/src/mbgl/renderer/painters/painter_fill_extrusion.cpp +++ b/src/mbgl/renderer/painters/painter_fill_extrusion.cpp @@ -58,7 +58,8 @@ void Painter::renderFillExtrusion(PaintParameters& parameters, bucket.triangleSegments, bucket.paintPropertyBinders.at(layer.getID()), properties, - state.getZoom()); + state.getZoom(), + layer.getID()); } else { parameters.programs.fillExtrusion.get(properties).draw( @@ -79,7 +80,8 @@ void Painter::renderFillExtrusion(PaintParameters& parameters, bucket.triangleSegments, bucket.paintPropertyBinders.at(layer.getID()), properties, - state.getZoom()); + state.getZoom(), + layer.getID()); }; } diff --git a/src/mbgl/renderer/painters/painter_line.cpp b/src/mbgl/renderer/painters/painter_line.cpp index 58f4131d96..667e19283d 100644 --- a/src/mbgl/renderer/painters/painter_line.cpp +++ b/src/mbgl/renderer/painters/painter_line.cpp @@ -36,7 +36,8 @@ void Painter::renderLine(PaintParameters& parameters, bucket.segments, bucket.paintPropertyBinders.at(layer.getID()), properties, - state.getZoom() + state.getZoom(), + layer.getID() ); }; diff --git a/src/mbgl/renderer/painters/painter_raster.cpp b/src/mbgl/renderer/painters/painter_raster.cpp index 56e38ae8f4..d0ab480616 100644 --- a/src/mbgl/renderer/painters/painter_raster.cpp +++ b/src/mbgl/renderer/painters/painter_raster.cpp @@ -82,7 +82,8 @@ void Painter::renderRaster(PaintParameters& parameters, useBucketBuffers ? bucket.segments : rasterSegments, paintAttributeData, properties, - state.getZoom() + state.getZoom(), + layer.getID() ); } diff --git a/src/mbgl/renderer/painters/painter_symbol.cpp b/src/mbgl/renderer/painters/painter_symbol.cpp index 51c3967ae7..183d09fa86 100644 --- a/src/mbgl/renderer/painters/painter_symbol.cpp +++ b/src/mbgl/renderer/painters/painter_symbol.cpp @@ -59,7 +59,8 @@ void Painter::renderSymbol(PaintParameters& parameters, buffers.segments, binders, paintProperties, - state.getZoom() + state.getZoom(), + layer.getID() ); }; @@ -181,7 +182,8 @@ void Painter::renderSymbol(PaintParameters& parameters, bucket.collisionBox.segments, paintAttributeData, properties, - state.getZoom() + state.getZoom(), + layer.getID() ); } } |