diff options
42 files changed, 814 insertions, 872 deletions
diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index f064890b48..94eb321ddf 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -175,11 +175,10 @@ set(MBGL_CORE_FILES src/mbgl/renderer/image_atlas.hpp src/mbgl/renderer/image_manager.cpp src/mbgl/renderer/image_manager.hpp + src/mbgl/renderer/paint_parameters.cpp src/mbgl/renderer/paint_parameters.hpp src/mbgl/renderer/paint_property_binder.hpp src/mbgl/renderer/paint_property_statistics.hpp - src/mbgl/renderer/painter.cpp - src/mbgl/renderer/painter.hpp src/mbgl/renderer/possibly_evaluated_property_value.hpp src/mbgl/renderer/property_evaluation_parameters.hpp src/mbgl/renderer/property_evaluator.hpp @@ -192,6 +191,8 @@ set(MBGL_CORE_FILES src/mbgl/renderer/render_source.cpp src/mbgl/renderer/render_source.hpp src/mbgl/renderer/render_source_observer.hpp + src/mbgl/renderer/render_static_data.cpp + src/mbgl/renderer/render_static_data.hpp src/mbgl/renderer/render_style.cpp src/mbgl/renderer/render_style.hpp src/mbgl/renderer/render_style_observer.hpp diff --git a/src/mbgl/annotation/render_annotation_source.cpp b/src/mbgl/annotation/render_annotation_source.cpp index 0d0427b7a7..de38b596d5 100644 --- a/src/mbgl/annotation/render_annotation_source.cpp +++ b/src/mbgl/annotation/render_annotation_source.cpp @@ -1,7 +1,7 @@ #include <mbgl/annotation/render_annotation_source.hpp> #include <mbgl/annotation/annotation_tile.hpp> #include <mbgl/renderer/render_tile.hpp> -#include <mbgl/renderer/painter.hpp> +#include <mbgl/renderer/paint_parameters.hpp> #include <mbgl/algorithm/generate_clip_ids.hpp> #include <mbgl/algorithm/generate_clip_ids_impl.hpp> @@ -44,13 +44,13 @@ void RenderAnnotationSource::update(Immutable<style::Source::Impl> baseImpl_, }); } -void RenderAnnotationSource::startRender(Painter& painter) { - painter.clipIDGenerator.update(tilePyramid.getRenderTiles()); - tilePyramid.startRender(painter); +void RenderAnnotationSource::startRender(PaintParameters& parameters) { + parameters.clipIDGenerator.update(tilePyramid.getRenderTiles()); + tilePyramid.startRender(parameters); } -void RenderAnnotationSource::finishRender(Painter& painter) { - tilePyramid.finishRender(painter); +void RenderAnnotationSource::finishRender(PaintParameters& parameters) { + tilePyramid.finishRender(parameters); } std::vector<std::reference_wrapper<RenderTile>> RenderAnnotationSource::getRenderTiles() { diff --git a/src/mbgl/annotation/render_annotation_source.hpp b/src/mbgl/annotation/render_annotation_source.hpp index 621298a112..4000c4b04a 100644 --- a/src/mbgl/annotation/render_annotation_source.hpp +++ b/src/mbgl/annotation/render_annotation_source.hpp @@ -18,8 +18,8 @@ public: bool needsRelayout, const TileParameters&) final; - void startRender(Painter&) final; - void finishRender(Painter&) final; + void startRender(PaintParameters&) final; + void finishRender(PaintParameters&) final; std::vector<std::reference_wrapper<RenderTile>> getRenderTiles() final; diff --git a/src/mbgl/renderer/buckets/debug_bucket.cpp b/src/mbgl/renderer/buckets/debug_bucket.cpp index acfe15d2fb..53c751c443 100644 --- a/src/mbgl/renderer/buckets/debug_bucket.cpp +++ b/src/mbgl/renderer/buckets/debug_bucket.cpp @@ -1,7 +1,7 @@ #include <mbgl/renderer/buckets/debug_bucket.hpp> -#include <mbgl/renderer/painter.hpp> #include <mbgl/programs/fill_program.hpp> #include <mbgl/geometry/debug_font_data.hpp> +#include <mbgl/tile/tile_id.hpp> #include <mbgl/util/string.hpp> #include <cmath> diff --git a/src/mbgl/renderer/layers/render_background_layer.cpp b/src/mbgl/renderer/layers/render_background_layer.cpp index cbf8d2f074..9fddba3f74 100644 --- a/src/mbgl/renderer/layers/render_background_layer.cpp +++ b/src/mbgl/renderer/layers/render_background_layer.cpp @@ -1,9 +1,9 @@ #include <mbgl/renderer/layers/render_background_layer.hpp> #include <mbgl/style/layers/background_layer_impl.hpp> #include <mbgl/renderer/bucket.hpp> -#include <mbgl/renderer/painter.hpp> #include <mbgl/renderer/paint_parameters.hpp> #include <mbgl/renderer/image_manager.hpp> +#include <mbgl/renderer/render_static_data.hpp> #include <mbgl/programs/programs.hpp> #include <mbgl/programs/fill_program.hpp> #include <mbgl/util/tile_cover.hpp> @@ -42,7 +42,7 @@ bool RenderBackgroundLayer::hasTransition() const { return unevaluated.hasTransition(); } -void RenderBackgroundLayer::render(Painter& painter, PaintParameters& parameters, RenderSource*) { +void RenderBackgroundLayer::render(PaintParameters& parameters, RenderSource*) { // Note that for bottommost layers without a pattern, the background color is drawn with // glClear rather than this method. @@ -54,58 +54,58 @@ void RenderBackgroundLayer::render(Painter& painter, PaintParameters& parameters const FillProgram::PaintPropertyBinders paintAttibuteData(properties, 0); if (!evaluated.get<BackgroundPattern>().to.empty()) { - optional<ImagePosition> imagePosA = painter.imageManager->getPattern(evaluated.get<BackgroundPattern>().from); - optional<ImagePosition> imagePosB = painter.imageManager->getPattern(evaluated.get<BackgroundPattern>().to); + optional<ImagePosition> imagePosA = parameters.imageManager.getPattern(evaluated.get<BackgroundPattern>().from); + optional<ImagePosition> imagePosB = parameters.imageManager.getPattern(evaluated.get<BackgroundPattern>().to); if (!imagePosA || !imagePosB) return; - painter.imageManager->bind(painter.context, 0); + parameters.imageManager.bind(parameters.context, 0); - for (const auto& tileID : util::tileCover(painter.state, painter.state.getIntegerZoom())) { + for (const auto& tileID : util::tileCover(parameters.state, parameters.state.getIntegerZoom())) { parameters.programs.fillPattern.get(properties).draw( - painter.context, + parameters.context, gl::Triangles(), - painter.depthModeForSublayer(0, gl::DepthMode::ReadOnly), + parameters.depthModeForSublayer(0, gl::DepthMode::ReadOnly), gl::StencilMode::disabled(), - painter.colorModeForRenderPass(), + parameters.colorModeForRenderPass(), FillPatternUniforms::values( - painter.matrixForTile(tileID), - painter.context.viewport.getCurrentValue().size, - painter.imageManager->getPixelSize(), + parameters.matrixForTile(tileID), + parameters.context.viewport.getCurrentValue().size, + parameters.imageManager.getPixelSize(), *imagePosA, *imagePosB, evaluated.get<BackgroundPattern>(), tileID, - painter.state + parameters.state ), - painter.tileVertexBuffer, - painter.quadTriangleIndexBuffer, - painter.tileTriangleSegments, + parameters.staticData.tileVertexBuffer, + parameters.staticData.quadTriangleIndexBuffer, + parameters.staticData.tileTriangleSegments, paintAttibuteData, properties, - painter.state.getZoom(), + parameters.state.getZoom(), getID() ); } } else { - for (const auto& tileID : util::tileCover(painter.state, painter.state.getIntegerZoom())) { + for (const auto& tileID : util::tileCover(parameters.state, parameters.state.getIntegerZoom())) { parameters.programs.fill.get(properties).draw( - painter.context, + parameters.context, gl::Triangles(), - painter.depthModeForSublayer(0, gl::DepthMode::ReadOnly), + parameters.depthModeForSublayer(0, gl::DepthMode::ReadOnly), gl::StencilMode::disabled(), - painter.colorModeForRenderPass(), + parameters.colorModeForRenderPass(), FillProgram::UniformValues { - uniforms::u_matrix::Value{ painter.matrixForTile(tileID) }, - uniforms::u_world::Value{ painter.context.viewport.getCurrentValue().size }, + uniforms::u_matrix::Value{ parameters.matrixForTile(tileID) }, + uniforms::u_world::Value{ parameters.context.viewport.getCurrentValue().size }, }, - painter.tileVertexBuffer, - painter.quadTriangleIndexBuffer, - painter.tileTriangleSegments, + parameters.staticData.tileVertexBuffer, + parameters.staticData.quadTriangleIndexBuffer, + parameters.staticData.tileTriangleSegments, paintAttibuteData, properties, - painter.state.getZoom(), + parameters.state.getZoom(), getID() ); } diff --git a/src/mbgl/renderer/layers/render_background_layer.hpp b/src/mbgl/renderer/layers/render_background_layer.hpp index a7b15ab178..a619670ee4 100644 --- a/src/mbgl/renderer/layers/render_background_layer.hpp +++ b/src/mbgl/renderer/layers/render_background_layer.hpp @@ -14,7 +14,7 @@ public: void transition(const TransitionParameters&) override; void evaluate(const PropertyEvaluationParameters&) override; bool hasTransition() const override; - void render(Painter&, PaintParameters&, RenderSource*) override; + void render(PaintParameters&, RenderSource*) override; std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const override; diff --git a/src/mbgl/renderer/layers/render_circle_layer.cpp b/src/mbgl/renderer/layers/render_circle_layer.cpp index 22e515e603..e7b022f3ee 100644 --- a/src/mbgl/renderer/layers/render_circle_layer.cpp +++ b/src/mbgl/renderer/layers/render_circle_layer.cpp @@ -1,6 +1,5 @@ #include <mbgl/renderer/layers/render_circle_layer.hpp> #include <mbgl/renderer/buckets/circle_bucket.hpp> -#include <mbgl/renderer/painter.hpp> #include <mbgl/renderer/render_tile.hpp> #include <mbgl/renderer/paint_parameters.hpp> #include <mbgl/programs/programs.hpp> @@ -48,8 +47,8 @@ bool RenderCircleLayer::hasTransition() const { return unevaluated.hasTransition(); } -void RenderCircleLayer::render(Painter& painter, PaintParameters& parameters, RenderSource*) { - if (painter.pass == RenderPass::Opaque) { +void RenderCircleLayer::render(PaintParameters& parameters, RenderSource*) { + if (parameters.pass == RenderPass::Opaque) { return; } @@ -61,26 +60,26 @@ void RenderCircleLayer::render(Painter& painter, PaintParameters& parameters, Re CircleBucket& bucket = *reinterpret_cast<CircleBucket*>(tile.tile.getBucket(*baseImpl)); parameters.programs.circle.get(evaluated).draw( - painter.context, + parameters.context, gl::Triangles(), - painter.depthModeForSublayer(0, gl::DepthMode::ReadOnly), - painter.frame.mapMode == MapMode::Still - ? painter.stencilModeForClipping(tile.clip) + parameters.depthModeForSublayer(0, gl::DepthMode::ReadOnly), + parameters.mapMode == MapMode::Still + ? parameters.stencilModeForClipping(tile.clip) : gl::StencilMode::disabled(), - painter.colorModeForRenderPass(), + parameters.colorModeForRenderPass(), CircleProgram::UniformValues { uniforms::u_matrix::Value{ tile.translatedMatrix(evaluated.get<CircleTranslate>(), evaluated.get<CircleTranslateAnchor>(), - painter.state) + parameters.state) }, uniforms::u_scale_with_map::Value{ scaleWithMap }, uniforms::u_extrude_scale::Value{ pitchWithMap ? std::array<float, 2> {{ - tile.id.pixelsToTileUnits(1, painter.state.getZoom()), - tile.id.pixelsToTileUnits(1, painter.state.getZoom()) }} - : painter.pixelsToGLUnits }, - uniforms::u_camera_to_center_distance::Value{ painter.state.getCameraToCenterDistance() }, + tile.id.pixelsToTileUnits(1, parameters.state.getZoom()), + tile.id.pixelsToTileUnits(1, parameters.state.getZoom()) }} + : parameters.pixelsToGLUnits }, + uniforms::u_camera_to_center_distance::Value{ parameters.state.getCameraToCenterDistance() }, uniforms::u_pitch_with_map::Value{ pitchWithMap } }, *bucket.vertexBuffer, @@ -88,7 +87,7 @@ void RenderCircleLayer::render(Painter& painter, PaintParameters& parameters, Re bucket.segments, bucket.paintPropertyBinders.at(getID()), evaluated, - painter.state.getZoom(), + parameters.state.getZoom(), getID() ); } diff --git a/src/mbgl/renderer/layers/render_circle_layer.hpp b/src/mbgl/renderer/layers/render_circle_layer.hpp index 7c3c19d21a..f31715f98f 100644 --- a/src/mbgl/renderer/layers/render_circle_layer.hpp +++ b/src/mbgl/renderer/layers/render_circle_layer.hpp @@ -14,7 +14,7 @@ public: void transition(const TransitionParameters&) override; void evaluate(const PropertyEvaluationParameters&) override; bool hasTransition() const override; - void render(Painter&, PaintParameters&, RenderSource*) override; + void render(PaintParameters&, RenderSource*) override; bool queryIntersectsFeature( const GeometryCoordinates&, diff --git a/src/mbgl/renderer/layers/render_custom_layer.cpp b/src/mbgl/renderer/layers/render_custom_layer.cpp index 30649137c7..49f94a699a 100644 --- a/src/mbgl/renderer/layers/render_custom_layer.cpp +++ b/src/mbgl/renderer/layers/render_custom_layer.cpp @@ -1,9 +1,10 @@ #include <mbgl/renderer/layers/render_custom_layer.hpp> -#include <mbgl/renderer/painter.hpp> #include <mbgl/renderer/paint_parameters.hpp> +#include <mbgl/renderer/backend_scope.hpp> +#include <mbgl/renderer/bucket.hpp> #include <mbgl/style/layers/custom_layer_impl.hpp> #include <mbgl/map/transform_state.hpp> -#include <mbgl/renderer/backend_scope.hpp> +#include <mbgl/map/view.hpp> namespace mbgl { @@ -37,21 +38,21 @@ std::unique_ptr<Bucket> RenderCustomLayer::createBucket(const BucketParameters&, return nullptr; } -void RenderCustomLayer::render(Painter& painter, PaintParameters& paintParameters, RenderSource*) { +void RenderCustomLayer::render(PaintParameters& paintParameters, RenderSource*) { if (!initialized) { assert(impl().initializeFn); impl().initializeFn(impl().context); initialized = true; } - gl::Context& context = painter.context; - const TransformState& state = painter.state; + gl::Context& context = paintParameters.context; + const TransformState& state = paintParameters.state; // Reset GL state to a known state so the CustomLayer always has a clean slate. context.bindVertexArray = 0; - context.setDepthMode(painter.depthModeForSublayer(0, gl::DepthMode::ReadOnly)); + context.setDepthMode(paintParameters.depthModeForSublayer(0, gl::DepthMode::ReadOnly)); context.setStencilMode(gl::StencilMode::disabled()); - context.setColorMode(painter.colorModeForRenderPass()); + context.setColorMode(paintParameters.colorModeForRenderPass()); CustomLayerRenderParameters parameters; diff --git a/src/mbgl/renderer/layers/render_custom_layer.hpp b/src/mbgl/renderer/layers/render_custom_layer.hpp index dd52d315cf..d8e9d93811 100644 --- a/src/mbgl/renderer/layers/render_custom_layer.hpp +++ b/src/mbgl/renderer/layers/render_custom_layer.hpp @@ -15,7 +15,7 @@ public: bool hasTransition() const override; std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const final; - void render(Painter&, PaintParameters&, RenderSource*) final; + void render(PaintParameters&, RenderSource*) final; const style::CustomLayer::Impl& impl() const; diff --git a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp index e06c43c112..27ed4d8084 100644 --- a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp @@ -1,12 +1,13 @@ #include <mbgl/renderer/layers/render_fill_extrusion_layer.hpp> #include <mbgl/renderer/buckets/fill_extrusion_bucket.hpp> -#include <mbgl/renderer/painter.hpp> #include <mbgl/renderer/render_tile.hpp> #include <mbgl/renderer/paint_parameters.hpp> #include <mbgl/renderer/image_manager.hpp> +#include <mbgl/renderer/render_static_data.hpp> #include <mbgl/programs/programs.hpp> #include <mbgl/programs/fill_extrusion_program.hpp> #include <mbgl/tile/tile.hpp> +#include <mbgl/map/view.hpp> #include <mbgl/style/layers/fill_extrusion_layer_impl.hpp> #include <mbgl/geometry/feature_index.hpp> #include <mbgl/util/math.hpp> @@ -44,22 +45,22 @@ bool RenderFillExtrusionLayer::hasTransition() const { return unevaluated.hasTransition(); } -void RenderFillExtrusionLayer::render(Painter& painter, PaintParameters& parameters, RenderSource*) { - if (painter.pass == RenderPass::Opaque) { +void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource*) { + if (parameters.pass == RenderPass::Opaque) { return; } - const auto size = painter.context.viewport.getCurrentValue().size; + const auto size = parameters.context.viewport.getCurrentValue().size; - if (!painter.extrusionTexture || painter.extrusionTexture->getSize() != size) { - painter.extrusionTexture = OffscreenTexture(painter.context, size, OffscreenTextureAttachment::Depth); + if (!parameters.staticData.extrusionTexture || parameters.staticData.extrusionTexture->getSize() != size) { + parameters.staticData.extrusionTexture = OffscreenTexture(parameters.context, size, OffscreenTextureAttachment::Depth); } - painter.extrusionTexture->bind(); + parameters.staticData.extrusionTexture->bind(); - painter.context.setStencilMode(gl::StencilMode::disabled()); - painter.context.setDepthMode(painter.depthModeForSublayer(0, gl::DepthMode::ReadWrite)); - painter.context.clear(Color{ 0.0f, 0.0f, 0.0f, 0.0f }, 1.0f, {}); + parameters.context.setStencilMode(gl::StencilMode::disabled()); + parameters.context.setDepthMode(parameters.depthModeForSublayer(0, gl::DepthMode::ReadWrite)); + parameters.context.clear(Color{ 0.0f, 0.0f, 0.0f, 0.0f }, 1.0f, {}); if (evaluated.get<FillExtrusionPattern>().from.empty()) { for (const RenderTile& tile : renderTiles) { @@ -67,71 +68,71 @@ void RenderFillExtrusionLayer::render(Painter& painter, PaintParameters& paramet FillExtrusionBucket& bucket = *reinterpret_cast<FillExtrusionBucket*>(tile.tile.getBucket(*baseImpl)); parameters.programs.fillExtrusion.get(evaluated).draw( - painter.context, + parameters.context, gl::Triangles(), - painter.depthModeForSublayer(0, gl::DepthMode::ReadWrite), + parameters.depthModeForSublayer(0, gl::DepthMode::ReadWrite), gl::StencilMode::disabled(), - painter.colorModeForRenderPass(), + parameters.colorModeForRenderPass(), FillExtrusionUniforms::values( tile.translatedClipMatrix(evaluated.get<FillExtrusionTranslate>(), evaluated.get<FillExtrusionTranslateAnchor>(), - painter.state), - painter.state, - painter.evaluatedLight + parameters.state), + parameters.state, + parameters.evaluatedLight ), *bucket.vertexBuffer, *bucket.indexBuffer, bucket.triangleSegments, bucket.paintPropertyBinders.at(getID()), evaluated, - painter.state.getZoom(), + parameters.state.getZoom(), getID()); } } else { - optional<ImagePosition> imagePosA = painter.imageManager->getPattern(evaluated.get<FillExtrusionPattern>().from); - optional<ImagePosition> imagePosB = painter.imageManager->getPattern(evaluated.get<FillExtrusionPattern>().to); + optional<ImagePosition> imagePosA = parameters.imageManager.getPattern(evaluated.get<FillExtrusionPattern>().from); + optional<ImagePosition> imagePosB = parameters.imageManager.getPattern(evaluated.get<FillExtrusionPattern>().to); if (!imagePosA || !imagePosB) { return; } - painter.imageManager->bind(painter.context, 0); + parameters.imageManager.bind(parameters.context, 0); for (const RenderTile& tile : renderTiles) { assert(dynamic_cast<FillExtrusionBucket*>(tile.tile.getBucket(*baseImpl))); FillExtrusionBucket& bucket = *reinterpret_cast<FillExtrusionBucket*>(tile.tile.getBucket(*baseImpl)); parameters.programs.fillExtrusionPattern.get(evaluated).draw( - painter.context, + parameters.context, gl::Triangles(), - painter.depthModeForSublayer(0, gl::DepthMode::ReadWrite), + parameters.depthModeForSublayer(0, gl::DepthMode::ReadWrite), gl::StencilMode::disabled(), - painter.colorModeForRenderPass(), + parameters.colorModeForRenderPass(), FillExtrusionPatternUniforms::values( tile.translatedClipMatrix(evaluated.get<FillExtrusionTranslate>(), evaluated.get<FillExtrusionTranslateAnchor>(), - painter.state), - painter.imageManager->getPixelSize(), + parameters.state), + parameters.imageManager.getPixelSize(), *imagePosA, *imagePosB, evaluated.get<FillExtrusionPattern>(), tile.id, - painter.state, + parameters.state, -std::pow(2, tile.id.canonical.z) / util::tileSize / 8.0f, - painter.evaluatedLight + parameters.evaluatedLight ), *bucket.vertexBuffer, *bucket.indexBuffer, bucket.triangleSegments, bucket.paintPropertyBinders.at(getID()), evaluated, - painter.state.getZoom(), + parameters.state.getZoom(), getID()); } } parameters.view.bind(); - painter.context.bindTexture(painter.extrusionTexture->getTexture()); + parameters.context.bindTexture(parameters.staticData.extrusionTexture->getTexture()); mat4 viewportMat; matrix::ortho(viewportMat, 0, size.width, size.height, 0, 0, 1); @@ -139,22 +140,22 @@ void RenderFillExtrusionLayer::render(Painter& painter, PaintParameters& paramet const Properties<>::PossiblyEvaluated properties; parameters.programs.extrusionTexture.draw( - painter.context, + parameters.context, gl::Triangles(), gl::DepthMode::disabled(), gl::StencilMode::disabled(), - painter.colorModeForRenderPass(), + parameters.colorModeForRenderPass(), ExtrusionTextureProgram::UniformValues{ uniforms::u_matrix::Value{ viewportMat }, uniforms::u_world::Value{ size }, uniforms::u_image::Value{ 0 }, uniforms::u_opacity::Value{ evaluated.get<FillExtrusionOpacity>() } }, - painter.extrusionTextureVertexBuffer, - painter.quadTriangleIndexBuffer, - painter.extrusionTextureSegments, + parameters.staticData.extrusionTextureVertexBuffer, + parameters.staticData.quadTriangleIndexBuffer, + parameters.staticData.extrusionTextureSegments, ExtrusionTextureProgram::PaintPropertyBinders{ properties, 0 }, properties, - painter.state.getZoom(), + parameters.state.getZoom(), getID()); } diff --git a/src/mbgl/renderer/layers/render_fill_extrusion_layer.hpp b/src/mbgl/renderer/layers/render_fill_extrusion_layer.hpp index b3f1115790..a53e00ca6f 100644 --- a/src/mbgl/renderer/layers/render_fill_extrusion_layer.hpp +++ b/src/mbgl/renderer/layers/render_fill_extrusion_layer.hpp @@ -14,7 +14,7 @@ public: void transition(const TransitionParameters&) override; void evaluate(const PropertyEvaluationParameters&) override; bool hasTransition() const override; - void render(Painter&, PaintParameters&, RenderSource*) override; + void render(PaintParameters&, RenderSource*) override; bool queryIntersectsFeature( const GeometryCoordinates&, diff --git a/src/mbgl/renderer/layers/render_fill_layer.cpp b/src/mbgl/renderer/layers/render_fill_layer.cpp index 973b08dd1f..2a61a9e993 100644 --- a/src/mbgl/renderer/layers/render_fill_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_layer.cpp @@ -1,6 +1,5 @@ #include <mbgl/renderer/layers/render_fill_layer.hpp> #include <mbgl/renderer/buckets/fill_bucket.hpp> -#include <mbgl/renderer/painter.hpp> #include <mbgl/renderer/render_tile.hpp> #include <mbgl/renderer/paint_parameters.hpp> #include <mbgl/renderer/image_manager.hpp> @@ -59,7 +58,7 @@ bool RenderFillLayer::hasTransition() const { return unevaluated.hasTransition(); } -void RenderFillLayer::render(Painter& painter, PaintParameters& parameters, RenderSource*) { +void RenderFillLayer::render(PaintParameters& parameters, RenderSource*) { if (evaluated.get<FillPattern>().from.empty()) { for (const RenderTile& tile : renderTiles) { assert(dynamic_cast<FillBucket*>(tile.tile.getBucket(*baseImpl))); @@ -71,30 +70,30 @@ void RenderFillLayer::render(Painter& painter, PaintParameters& parameters, Rend const auto& indexBuffer, const auto& segments) { program.get(evaluated).draw( - painter.context, + parameters.context, drawMode, - painter.depthModeForSublayer(sublayer, gl::DepthMode::ReadWrite), - painter.stencilModeForClipping(tile.clip), - painter.colorModeForRenderPass(), + parameters.depthModeForSublayer(sublayer, gl::DepthMode::ReadWrite), + parameters.stencilModeForClipping(tile.clip), + parameters.colorModeForRenderPass(), FillProgram::UniformValues { uniforms::u_matrix::Value{ tile.translatedMatrix(evaluated.get<FillTranslate>(), evaluated.get<FillTranslateAnchor>(), - painter.state) + parameters.state) }, - uniforms::u_world::Value{ painter.context.viewport.getCurrentValue().size }, + uniforms::u_world::Value{ parameters.context.viewport.getCurrentValue().size }, }, *bucket.vertexBuffer, indexBuffer, segments, bucket.paintPropertyBinders.at(getID()), evaluated, - painter.state.getZoom(), + parameters.state.getZoom(), getID() ); }; - if (evaluated.get<FillAntialias>() && !unevaluated.get<FillOutlineColor>().isUndefined() && painter.pass == RenderPass::Translucent) { + if (evaluated.get<FillAntialias>() && !unevaluated.get<FillOutlineColor>().isUndefined() && parameters.pass == RenderPass::Translucent) { draw(2, parameters.programs.fillOutline, gl::Lines { 2.0f }, @@ -105,7 +104,7 @@ void RenderFillLayer::render(Painter& painter, PaintParameters& parameters, Rend // Only draw the fill when it's opaque and we're drawing opaque fragments, // or when it's translucent and we're drawing translucent fragments. if ((evaluated.get<FillColor>().constantOr(Color()).a >= 1.0f - && evaluated.get<FillOpacity>().constantOr(0) >= 1.0f) == (painter.pass == RenderPass::Opaque)) { + && evaluated.get<FillOpacity>().constantOr(0) >= 1.0f) == (parameters.pass == RenderPass::Opaque)) { draw(1, parameters.programs.fill, gl::Triangles(), @@ -113,7 +112,7 @@ void RenderFillLayer::render(Painter& painter, PaintParameters& parameters, Rend bucket.triangleSegments); } - if (evaluated.get<FillAntialias>() && unevaluated.get<FillOutlineColor>().isUndefined() && painter.pass == RenderPass::Translucent) { + if (evaluated.get<FillAntialias>() && unevaluated.get<FillOutlineColor>().isUndefined() && parameters.pass == RenderPass::Translucent) { draw(2, parameters.programs.fillOutline, gl::Lines { 2.0f }, @@ -122,18 +121,18 @@ void RenderFillLayer::render(Painter& painter, PaintParameters& parameters, Rend } } } else { - if (painter.pass != RenderPass::Translucent) { + if (parameters.pass != RenderPass::Translucent) { return; } - optional<ImagePosition> imagePosA = painter.imageManager->getPattern(evaluated.get<FillPattern>().from); - optional<ImagePosition> imagePosB = painter.imageManager->getPattern(evaluated.get<FillPattern>().to); + optional<ImagePosition> imagePosA = parameters.imageManager.getPattern(evaluated.get<FillPattern>().from); + optional<ImagePosition> imagePosB = parameters.imageManager.getPattern(evaluated.get<FillPattern>().to); if (!imagePosA || !imagePosB) { return; } - painter.imageManager->bind(painter.context, 0); + parameters.imageManager.bind(parameters.context, 0); for (const RenderTile& tile : renderTiles) { assert(dynamic_cast<FillBucket*>(tile.tile.getBucket(*baseImpl))); @@ -145,29 +144,29 @@ void RenderFillLayer::render(Painter& painter, PaintParameters& parameters, Rend const auto& indexBuffer, const auto& segments) { program.get(evaluated).draw( - painter.context, + parameters.context, drawMode, - painter.depthModeForSublayer(sublayer, gl::DepthMode::ReadWrite), - painter.stencilModeForClipping(tile.clip), - painter.colorModeForRenderPass(), + parameters.depthModeForSublayer(sublayer, gl::DepthMode::ReadWrite), + parameters.stencilModeForClipping(tile.clip), + parameters.colorModeForRenderPass(), FillPatternUniforms::values( tile.translatedMatrix(evaluated.get<FillTranslate>(), evaluated.get<FillTranslateAnchor>(), - painter.state), - painter.context.viewport.getCurrentValue().size, - painter.imageManager->getPixelSize(), + parameters.state), + parameters.context.viewport.getCurrentValue().size, + parameters.imageManager.getPixelSize(), *imagePosA, *imagePosB, evaluated.get<FillPattern>(), tile.id, - painter.state + parameters.state ), *bucket.vertexBuffer, indexBuffer, segments, bucket.paintPropertyBinders.at(getID()), evaluated, - painter.state.getZoom(), + parameters.state.getZoom(), getID() ); }; diff --git a/src/mbgl/renderer/layers/render_fill_layer.hpp b/src/mbgl/renderer/layers/render_fill_layer.hpp index 0dc5dd0b1d..a51865698f 100644 --- a/src/mbgl/renderer/layers/render_fill_layer.hpp +++ b/src/mbgl/renderer/layers/render_fill_layer.hpp @@ -14,7 +14,7 @@ public: void transition(const TransitionParameters&) override; void evaluate(const PropertyEvaluationParameters&) override; bool hasTransition() const override; - void render(Painter&, PaintParameters&, RenderSource*) override; + void render(PaintParameters&, RenderSource*) override; bool queryIntersectsFeature( const GeometryCoordinates&, diff --git a/src/mbgl/renderer/layers/render_line_layer.cpp b/src/mbgl/renderer/layers/render_line_layer.cpp index b40066f4c4..1b4a1c0ff7 100644 --- a/src/mbgl/renderer/layers/render_line_layer.cpp +++ b/src/mbgl/renderer/layers/render_line_layer.cpp @@ -1,6 +1,5 @@ #include <mbgl/renderer/layers/render_line_layer.hpp> #include <mbgl/renderer/buckets/line_bucket.hpp> -#include <mbgl/renderer/painter.hpp> #include <mbgl/renderer/render_tile.hpp> #include <mbgl/renderer/paint_parameters.hpp> #include <mbgl/renderer/image_manager.hpp> @@ -53,8 +52,8 @@ bool RenderLineLayer::hasTransition() const { return unevaluated.hasTransition(); } -void RenderLineLayer::render(Painter& painter, PaintParameters& parameters, RenderSource*) { - if (painter.pass == RenderPass::Opaque) { +void RenderLineLayer::render(PaintParameters& parameters, RenderSource*) { + if (parameters.pass == RenderPass::Opaque) { return; } @@ -64,18 +63,18 @@ void RenderLineLayer::render(Painter& painter, PaintParameters& parameters, Rend auto draw = [&] (auto& program, auto&& uniformValues) { program.get(evaluated).draw( - painter.context, + parameters.context, gl::Triangles(), - painter.depthModeForSublayer(0, gl::DepthMode::ReadOnly), - painter.stencilModeForClipping(tile.clip), - painter.colorModeForRenderPass(), + parameters.depthModeForSublayer(0, gl::DepthMode::ReadOnly), + parameters.stencilModeForClipping(tile.clip), + parameters.colorModeForRenderPass(), std::move(uniformValues), *bucket.vertexBuffer, *bucket.indexBuffer, bucket.segments, bucket.paintPropertyBinders.at(getID()), evaluated, - painter.state.getZoom(), + parameters.state.getZoom(), getID() ); }; @@ -83,38 +82,38 @@ void RenderLineLayer::render(Painter& painter, PaintParameters& parameters, Rend if (!evaluated.get<LineDasharray>().from.empty()) { const LinePatternCap cap = bucket.layout.get<LineCap>() == LineCapType::Round ? LinePatternCap::Round : LinePatternCap::Square; - LinePatternPos posA = painter.lineAtlas->getDashPosition(evaluated.get<LineDasharray>().from, cap); - LinePatternPos posB = painter.lineAtlas->getDashPosition(evaluated.get<LineDasharray>().to, cap); + LinePatternPos posA = parameters.lineAtlas.getDashPosition(evaluated.get<LineDasharray>().from, cap); + LinePatternPos posB = parameters.lineAtlas.getDashPosition(evaluated.get<LineDasharray>().to, cap); - painter.lineAtlas->bind(painter.context, 0); + parameters.lineAtlas.bind(parameters.context, 0); draw(parameters.programs.lineSDF, LineSDFProgram::uniformValues( evaluated, - painter.frame.pixelRatio, + parameters.pixelRatio, tile, - painter.state, - painter.pixelsToGLUnits, + parameters.state, + parameters.pixelsToGLUnits, posA, posB, - painter.lineAtlas->getSize().width)); + parameters.lineAtlas.getSize().width)); } else if (!evaluated.get<LinePattern>().from.empty()) { - optional<ImagePosition> posA = painter.imageManager->getPattern(evaluated.get<LinePattern>().from); - optional<ImagePosition> posB = painter.imageManager->getPattern(evaluated.get<LinePattern>().to); + optional<ImagePosition> posA = parameters.imageManager.getPattern(evaluated.get<LinePattern>().from); + optional<ImagePosition> posB = parameters.imageManager.getPattern(evaluated.get<LinePattern>().to); if (!posA || !posB) return; - painter.imageManager->bind(painter.context, 0); + parameters.imageManager.bind(parameters.context, 0); draw(parameters.programs.linePattern, LinePatternProgram::uniformValues( evaluated, tile, - painter.state, - painter.pixelsToGLUnits, - painter.imageManager->getPixelSize(), + parameters.state, + parameters.pixelsToGLUnits, + parameters.imageManager.getPixelSize(), *posA, *posB)); @@ -123,8 +122,8 @@ void RenderLineLayer::render(Painter& painter, PaintParameters& parameters, Rend LineProgram::uniformValues( evaluated, tile, - painter.state, - painter.pixelsToGLUnits)); + parameters.state, + parameters.pixelsToGLUnits)); } } } diff --git a/src/mbgl/renderer/layers/render_line_layer.hpp b/src/mbgl/renderer/layers/render_line_layer.hpp index 47c526fd1e..8bf7e2329d 100644 --- a/src/mbgl/renderer/layers/render_line_layer.hpp +++ b/src/mbgl/renderer/layers/render_line_layer.hpp @@ -23,7 +23,7 @@ public: void transition(const TransitionParameters&) override; void evaluate(const PropertyEvaluationParameters&) override; bool hasTransition() const override; - void render(Painter&, PaintParameters&, RenderSource*) override; + void render(PaintParameters&, RenderSource*) override; bool queryIntersectsFeature( const GeometryCoordinates&, diff --git a/src/mbgl/renderer/layers/render_raster_layer.cpp b/src/mbgl/renderer/layers/render_raster_layer.cpp index 349646c281..367fd91fa5 100644 --- a/src/mbgl/renderer/layers/render_raster_layer.cpp +++ b/src/mbgl/renderer/layers/render_raster_layer.cpp @@ -1,9 +1,9 @@ #include <mbgl/renderer/layers/render_raster_layer.hpp> #include <mbgl/renderer/buckets/raster_bucket.hpp> -#include <mbgl/renderer/painter.hpp> #include <mbgl/renderer/render_tile.hpp> #include <mbgl/renderer/paint_parameters.hpp> #include <mbgl/renderer/sources/render_image_source.hpp> +#include <mbgl/renderer/render_static_data.hpp> #include <mbgl/programs/programs.hpp> #include <mbgl/programs/raster_program.hpp> #include <mbgl/tile/tile.hpp> @@ -69,8 +69,8 @@ static std::array<float, 3> spinWeights(float spin) { return spin_weights; } -void RenderRasterLayer::render(Painter& painter, PaintParameters& parameters, RenderSource* source) { - if (painter.pass != RenderPass::Translucent) +void RenderRasterLayer::render(PaintParameters& parameters, RenderSource* source) { + if (parameters.pass != RenderPass::Translucent) return; auto draw = [&] (const mat4& matrix, @@ -78,11 +78,11 @@ void RenderRasterLayer::render(Painter& painter, PaintParameters& parameters, Re const auto& indexBuffer, const auto& segments) { parameters.programs.raster.draw( - painter.context, + parameters.context, gl::Triangles(), - painter.depthModeForSublayer(0, gl::DepthMode::ReadOnly), + parameters.depthModeForSublayer(0, gl::DepthMode::ReadOnly), gl::StencilMode::disabled(), - painter.colorModeForRenderPass(), + parameters.colorModeForRenderPass(), RasterProgram::UniformValues { uniforms::u_matrix::Value{ matrix }, uniforms::u_image0::Value{ 0 }, @@ -103,7 +103,7 @@ void RenderRasterLayer::render(Painter& painter, PaintParameters& parameters, Re segments, RasterProgram::PaintPropertyBinders { evaluated, 0 }, evaluated, - painter.state.getZoom(), + parameters.state.getZoom(), getID() ); }; @@ -113,8 +113,8 @@ void RenderRasterLayer::render(Painter& painter, PaintParameters& parameters, Re RasterBucket& bucket = *imageSource->bucket; assert(bucket.texture); - painter.context.bindTexture(*bucket.texture, 0, gl::TextureFilter::Linear); - painter.context.bindTexture(*bucket.texture, 1, gl::TextureFilter::Linear); + parameters.context.bindTexture(*bucket.texture, 0, gl::TextureFilter::Linear); + parameters.context.bindTexture(*bucket.texture, 1, gl::TextureFilter::Linear); for (auto matrix_ : imageSource->matrices) { draw(matrix_, @@ -132,13 +132,13 @@ void RenderRasterLayer::render(Painter& painter, PaintParameters& parameters, Re continue; assert(bucket.texture); - painter.context.bindTexture(*bucket.texture, 0, gl::TextureFilter::Linear); - painter.context.bindTexture(*bucket.texture, 1, gl::TextureFilter::Linear); + parameters.context.bindTexture(*bucket.texture, 0, gl::TextureFilter::Linear); + parameters.context.bindTexture(*bucket.texture, 1, gl::TextureFilter::Linear); draw(tile.matrix, - painter.rasterVertexBuffer, - painter.quadTriangleIndexBuffer, - painter.rasterSegments); + parameters.staticData.rasterVertexBuffer, + parameters.staticData.quadTriangleIndexBuffer, + parameters.staticData.rasterSegments); } } } diff --git a/src/mbgl/renderer/layers/render_raster_layer.hpp b/src/mbgl/renderer/layers/render_raster_layer.hpp index ce46152a95..87de316f7c 100644 --- a/src/mbgl/renderer/layers/render_raster_layer.hpp +++ b/src/mbgl/renderer/layers/render_raster_layer.hpp @@ -15,7 +15,7 @@ public: void evaluate(const PropertyEvaluationParameters&) override; bool hasTransition() const override; - void render(Painter&, PaintParameters&, RenderSource*) override; + void render(PaintParameters&, RenderSource*) override; std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const override; diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp index a87dd3c535..1376e8a3d8 100644 --- a/src/mbgl/renderer/layers/render_symbol_layer.cpp +++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp @@ -2,9 +2,9 @@ #include <mbgl/renderer/buckets/symbol_bucket.hpp> #include <mbgl/renderer/bucket_parameters.hpp> #include <mbgl/renderer/property_evaluation_parameters.hpp> -#include <mbgl/renderer/painter.hpp> #include <mbgl/renderer/render_tile.hpp> #include <mbgl/renderer/paint_parameters.hpp> +#include <mbgl/renderer/frame_history.hpp> #include <mbgl/text/glyph_atlas.hpp> #include <mbgl/programs/programs.hpp> #include <mbgl/programs/symbol_program.hpp> @@ -70,8 +70,8 @@ bool RenderSymbolLayer::hasTransition() const { return unevaluated.hasTransition(); } -void RenderSymbolLayer::render(Painter& painter, PaintParameters& parameters, RenderSource*) { - if (painter.pass == RenderPass::Opaque) { +void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) { + if (parameters.pass == RenderPass::Opaque) { return; } @@ -81,7 +81,7 @@ void RenderSymbolLayer::render(Painter& painter, PaintParameters& parameters, Re const auto& layout = bucket.layout; - painter.frameHistory.bind(painter.context, 1); + parameters.frameHistory.bind(parameters.context, 1); auto draw = [&] (auto& program, auto&& uniformValues, @@ -92,18 +92,18 @@ void RenderSymbolLayer::render(Painter& painter, PaintParameters& parameters, Re const auto& paintProperties) { // We clip symbols to their tile extent in still mode. - const bool needsClipping = painter.frame.mapMode == MapMode::Still; + const bool needsClipping = parameters.mapMode == MapMode::Still; program.get(paintProperties).draw( - painter.context, + parameters.context, gl::Triangles(), values_.pitchAlignment == AlignmentType::Map - ? painter.depthModeForSublayer(0, gl::DepthMode::ReadOnly) + ? parameters.depthModeForSublayer(0, gl::DepthMode::ReadOnly) : gl::DepthMode::disabled(), needsClipping - ? painter.stencilModeForClipping(tile.clip) + ? parameters.stencilModeForClipping(tile.clip) : gl::StencilMode::disabled(), - painter.colorModeForRenderPass(), + parameters.colorModeForRenderPass(), std::move(uniformValues), *buffers.vertexBuffer, *buffers.dynamicVertexBuffer, @@ -112,7 +112,7 @@ void RenderSymbolLayer::render(Painter& painter, PaintParameters& parameters, Re buffers.segments, binders, paintProperties, - painter.state.getZoom(), + parameters.state.getZoom(), getID() ); }; @@ -134,17 +134,17 @@ void RenderSymbolLayer::render(Painter& painter, PaintParameters& parameters, Re values, tile, *bucket.iconSizeBinder, - painter.state, - painter.frameHistory); + parameters.state, + parameters.frameHistory); - painter.context.updateVertexBuffer(*bucket.icon.dynamicVertexBuffer, std::move(bucket.icon.dynamicVertices)); + parameters.context.updateVertexBuffer(*bucket.icon.dynamicVertexBuffer, std::move(bucket.icon.dynamicVertices)); } const bool iconScaled = layout.get<IconSize>().constantOr(1.0) != 1.0 || bucket.iconsNeedLinear; - const bool iconTransformed = values.rotationAlignment == AlignmentType::Map || painter.state.getPitch() != 0; + const bool iconTransformed = values.rotationAlignment == AlignmentType::Map || parameters.state.getPitch() != 0; - painter.context.bindTexture(*geometryTile.iconAtlasTexture, 0, - bucket.sdfIcons || painter.state.isChanging() || iconScaled || iconTransformed + parameters.context.bindTexture(*geometryTile.iconAtlasTexture, 0, + bucket.sdfIcons || parameters.state.isChanging() || iconScaled || iconTransformed ? gl::TextureFilter::Linear : gl::TextureFilter::Nearest); const Size texsize = geometryTile.iconAtlasTexture->size; @@ -152,7 +152,7 @@ void RenderSymbolLayer::render(Painter& painter, PaintParameters& parameters, Re if (bucket.sdfIcons) { if (values.hasHalo) { draw(parameters.programs.symbolIconSDF, - SymbolSDFIconProgram::uniformValues(false, values, texsize, painter.pixelsToGLUnits, alongLine, tile, painter.state, SymbolSDFPart::Halo), + SymbolSDFIconProgram::uniformValues(false, values, texsize, parameters.pixelsToGLUnits, alongLine, tile, parameters.state, SymbolSDFPart::Halo), bucket.icon, bucket.iconSizeBinder, values, @@ -162,7 +162,7 @@ void RenderSymbolLayer::render(Painter& painter, PaintParameters& parameters, Re if (values.hasFill) { draw(parameters.programs.symbolIconSDF, - SymbolSDFIconProgram::uniformValues(false, values, texsize, painter.pixelsToGLUnits, alongLine, tile, painter.state, SymbolSDFPart::Fill), + SymbolSDFIconProgram::uniformValues(false, values, texsize, parameters.pixelsToGLUnits, alongLine, tile, parameters.state, SymbolSDFPart::Fill), bucket.icon, bucket.iconSizeBinder, values, @@ -171,7 +171,7 @@ void RenderSymbolLayer::render(Painter& painter, PaintParameters& parameters, Re } } else { draw(parameters.programs.symbolIcon, - SymbolIconProgram::uniformValues(false, values, texsize, painter.pixelsToGLUnits, alongLine, tile, painter.state), + SymbolIconProgram::uniformValues(false, values, texsize, parameters.pixelsToGLUnits, alongLine, tile, parameters.state), bucket.icon, bucket.iconSizeBinder, values, @@ -181,7 +181,7 @@ void RenderSymbolLayer::render(Painter& painter, PaintParameters& parameters, Re } if (bucket.hasTextData()) { - painter.context.bindTexture(*geometryTile.glyphAtlasTexture, 0, gl::TextureFilter::Linear); + parameters.context.bindTexture(*geometryTile.glyphAtlasTexture, 0, gl::TextureFilter::Linear); auto values = textPropertyValues(layout); auto paintPropertyValues = textPaintProperties(); @@ -196,17 +196,17 @@ void RenderSymbolLayer::render(Painter& painter, PaintParameters& parameters, Re values, tile, *bucket.textSizeBinder, - painter.state, - painter.frameHistory); + parameters.state, + parameters.frameHistory); - painter.context.updateVertexBuffer(*bucket.text.dynamicVertexBuffer, std::move(bucket.text.dynamicVertices)); + parameters.context.updateVertexBuffer(*bucket.text.dynamicVertexBuffer, std::move(bucket.text.dynamicVertices)); } const Size texsize = geometryTile.glyphAtlasTexture->size; if (values.hasHalo) { draw(parameters.programs.symbolGlyph, - SymbolSDFTextProgram::uniformValues(true, values, texsize, painter.pixelsToGLUnits, alongLine, tile, painter.state, SymbolSDFPart::Halo), + SymbolSDFTextProgram::uniformValues(true, values, texsize, parameters.pixelsToGLUnits, alongLine, tile, parameters.state, SymbolSDFPart::Halo), bucket.text, bucket.textSizeBinder, values, @@ -216,7 +216,7 @@ void RenderSymbolLayer::render(Painter& painter, PaintParameters& parameters, Re if (values.hasFill) { draw(parameters.programs.symbolGlyph, - SymbolSDFTextProgram::uniformValues(true, values, texsize, painter.pixelsToGLUnits, alongLine, tile, painter.state, SymbolSDFPart::Fill), + SymbolSDFTextProgram::uniformValues(true, values, texsize, parameters.pixelsToGLUnits, alongLine, tile, parameters.state, SymbolSDFPart::Fill), bucket.text, bucket.textSizeBinder, values, @@ -229,20 +229,20 @@ void RenderSymbolLayer::render(Painter& painter, PaintParameters& parameters, Re static const style::Properties<>::PossiblyEvaluated properties {}; static const CollisionBoxProgram::PaintPropertyBinders paintAttributeData(properties, 0); - painter.programs->collisionBox.draw( - painter.context, + parameters.programs.collisionBox.draw( + parameters.context, gl::Lines { 1.0f }, gl::DepthMode::disabled(), - painter.stencilModeForClipping(tile.clip), - painter.colorModeForRenderPass(), + parameters.stencilModeForClipping(tile.clip), + parameters.colorModeForRenderPass(), CollisionBoxProgram::UniformValues { uniforms::u_matrix::Value{ tile.matrix }, - uniforms::u_scale::Value{ std::pow(2.0f, float(painter.state.getZoom() - tile.tile.id.overscaledZ)) }, - uniforms::u_zoom::Value{ float(painter.state.getZoom() * 10) }, + uniforms::u_scale::Value{ std::pow(2.0f, float(parameters.state.getZoom() - tile.tile.id.overscaledZ)) }, + uniforms::u_zoom::Value{ float(parameters.state.getZoom() * 10) }, uniforms::u_maxzoom::Value{ float((tile.id.canonical.z + 1) * 10) }, uniforms::u_collision_y_stretch::Value{ tile.tile.yStretch() }, - uniforms::u_camera_to_center_distance::Value{ painter.state.getCameraToCenterDistance() }, - uniforms::u_pitch::Value{ painter.state.getPitch() }, + uniforms::u_camera_to_center_distance::Value{ parameters.state.getCameraToCenterDistance() }, + uniforms::u_pitch::Value{ parameters.state.getPitch() }, uniforms::u_fadetexture::Value{ 1 } }, *bucket.collisionBox.vertexBuffer, @@ -250,7 +250,7 @@ void RenderSymbolLayer::render(Painter& painter, PaintParameters& parameters, Re bucket.collisionBox.segments, paintAttributeData, properties, - painter.state.getZoom(), + parameters.state.getZoom(), getID() ); } diff --git a/src/mbgl/renderer/layers/render_symbol_layer.hpp b/src/mbgl/renderer/layers/render_symbol_layer.hpp index f29ceb504c..83709b5122 100644 --- a/src/mbgl/renderer/layers/render_symbol_layer.hpp +++ b/src/mbgl/renderer/layers/render_symbol_layer.hpp @@ -66,7 +66,7 @@ public: void transition(const TransitionParameters&) override; void evaluate(const PropertyEvaluationParameters&) override; bool hasTransition() const override; - void render(Painter&, PaintParameters&, RenderSource*) override; + void render(PaintParameters&, RenderSource*) override; style::IconPaintProperties::PossiblyEvaluated iconPaintProperties() const; style::TextPaintProperties::PossiblyEvaluated textPaintProperties() const; diff --git a/src/mbgl/renderer/paint_parameters.cpp b/src/mbgl/renderer/paint_parameters.cpp new file mode 100644 index 0000000000..fc0bd40aeb --- /dev/null +++ b/src/mbgl/renderer/paint_parameters.cpp @@ -0,0 +1,93 @@ +#include <mbgl/renderer/paint_parameters.hpp> +#include <mbgl/renderer/update_parameters.hpp> +#include <mbgl/renderer/render_style.hpp> +#include <mbgl/renderer/render_static_data.hpp> +#include <mbgl/map/transform_state.hpp> + +namespace mbgl { + +PaintParameters::PaintParameters(gl::Context& context_, + float pixelRatio_, + GLContextMode contextMode_, + View& view_, + const UpdateParameters& updateParameters, + RenderStyle& style, + RenderStaticData& staticData_, + FrameHistory& frameHistory_) + : context(context_), + view(view_), + state(updateParameters.transformState), + evaluatedLight(style.getRenderLight().getEvaluated()), + staticData(staticData_), + frameHistory(frameHistory_), + imageManager(*style.imageManager), + lineAtlas(*style.lineAtlas), + mapMode(updateParameters.mode), + debugOptions(updateParameters.debugOptions), + contextMode(contextMode_), + timePoint(updateParameters.timePoint), + pixelRatio(pixelRatio_), +#ifndef NDEBUG + programs((debugOptions & MapDebugOptions::Overdraw) ? staticData_.overdrawPrograms : staticData_.programs) +#else + programs(staticData_.programs) +#endif +{ + // Update the default matrices to the current viewport dimensions. + state.getProjMatrix(projMatrix); + + // Calculate a second projection matrix with the near plane clipped to 100 so as + // not to waste lots of depth buffer precision on very close empty space, for layer + // types (fill-extrusion) that use the depth buffer to emulate real-world space. + state.getProjMatrix(nearClippedProjMatrix, 100); + + pixelsToGLUnits = {{ 2.0f / state.getSize().width, -2.0f / state.getSize().height }}; + + if (state.getViewportMode() == ViewportMode::FlippedY) { + pixelsToGLUnits[1] *= -1; + } +} + +mat4 PaintParameters::matrixForTile(const UnwrappedTileID& tileID) { + mat4 matrix; + state.matrixFor(matrix, tileID); + matrix::multiply(matrix, projMatrix, matrix); + return matrix; +} + +gl::DepthMode PaintParameters::depthModeForSublayer(uint8_t n, gl::DepthMode::Mask mask) const { + float nearDepth = ((1 + currentLayer) * numSublayers + n) * depthEpsilon; + float farDepth = nearDepth + depthRangeSize; + return gl::DepthMode { gl::DepthMode::LessEqual, mask, { nearDepth, farDepth } }; +} + +gl::StencilMode PaintParameters::stencilModeForClipping(const ClipID& id) const { + return gl::StencilMode { + gl::StencilMode::Equal { static_cast<uint32_t>(id.mask.to_ulong()) }, + static_cast<int32_t>(id.reference.to_ulong()), + 0, + gl::StencilMode::Keep, + gl::StencilMode::Keep, + gl::StencilMode::Replace + }; +} + +gl::ColorMode PaintParameters::colorModeForRenderPass() const { + if (debugOptions & MapDebugOptions::Overdraw) { + const float overdraw = 1.0f / 8.0f; + return gl::ColorMode { + gl::ColorMode::Add { + gl::ColorMode::ConstantColor, + gl::ColorMode::One + }, + Color { overdraw, overdraw, overdraw, 0.0f }, + gl::ColorMode::Mask { true, true, true, true } + }; + } else if (pass == RenderPass::Translucent) { + return gl::ColorMode::alphaBlended(); + } else { + return gl::ColorMode::unblended(); + } +} + +} // namespace mbgl diff --git a/src/mbgl/renderer/paint_parameters.hpp b/src/mbgl/renderer/paint_parameters.hpp index 213c01cfbd..811a99b58b 100644 --- a/src/mbgl/renderer/paint_parameters.hpp +++ b/src/mbgl/renderer/paint_parameters.hpp @@ -1,14 +1,76 @@ #pragma once +#include <mbgl/renderer/render_pass.hpp> +#include <mbgl/renderer/render_light.hpp> +#include <mbgl/map/mode.hpp> +#include <mbgl/gl/depth_mode.hpp> +#include <mbgl/gl/stencil_mode.hpp> +#include <mbgl/gl/color_mode.hpp> +#include <mbgl/util/mat4.hpp> +#include <mbgl/algorithm/generate_clip_ids.hpp> + +#include <array> + namespace mbgl { -class Programs; class View; +class UpdateParameters; +class RenderStyle; +class RenderStaticData; +class FrameHistory; +class Programs; +class TransformState; +class ImageManager; +class LineAtlas; +class UnwrappedTileID; class PaintParameters { public: - Programs& programs; + PaintParameters(gl::Context&, + float pixelRatio, + GLContextMode, + View&, + const UpdateParameters&, + RenderStyle&, + RenderStaticData&, + FrameHistory&); + + gl::Context& context; View& view; + + const TransformState& state; + const EvaluatedLight& evaluatedLight; + + RenderStaticData& staticData; + FrameHistory& frameHistory; + ImageManager& imageManager; + LineAtlas& lineAtlas; + + RenderPass pass = RenderPass::Opaque; + MapMode mapMode; + MapDebugOptions debugOptions; + GLContextMode contextMode; + TimePoint timePoint; + + float pixelRatio; + std::array<float, 2> pixelsToGLUnits; + algorithm::ClipIDGenerator clipIDGenerator; + + Programs& programs; + + gl::DepthMode depthModeForSublayer(uint8_t n, gl::DepthMode::Mask) const; + gl::StencilMode stencilModeForClipping(const ClipID&) const; + gl::ColorMode colorModeForRenderPass() const; + + mat4 matrixForTile(const UnwrappedTileID&); + + mat4 projMatrix; + mat4 nearClippedProjMatrix; + + int numSublayers = 3; + uint32_t currentLayer; + float depthRangeSize; + const float depthEpsilon = 1.0f / (1 << 16); }; } // namespace mbgl diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp deleted file mode 100644 index 7d101f1530..0000000000 --- a/src/mbgl/renderer/painter.cpp +++ /dev/null @@ -1,404 +0,0 @@ -#include <mbgl/renderer/painter.hpp> -#include <mbgl/renderer/paint_parameters.hpp> -#include <mbgl/renderer/render_tile.hpp> -#include <mbgl/renderer/render_source.hpp> -#include <mbgl/renderer/render_style.hpp> -#include <mbgl/renderer/image_manager.hpp> -#include <mbgl/renderer/layers/render_fill_extrusion_layer.hpp> - -#include <mbgl/style/source.hpp> -#include <mbgl/style/source_impl.hpp> -#include <mbgl/style/layer_impl.hpp> - -#include <mbgl/map/view.hpp> -#include <mbgl/gl/debugging.hpp> -#include <mbgl/tile/tile.hpp> -#include <mbgl/geometry/line_atlas.hpp> -#include <mbgl/programs/program_parameters.hpp> -#include <mbgl/programs/programs.hpp> - -#include <mbgl/util/constants.hpp> -#include <mbgl/util/mat3.hpp> -#include <mbgl/util/string.hpp> -#include <mbgl/util/stopwatch.hpp> -#include <mbgl/util/clip_id.hpp> -#include <mbgl/util/logging.hpp> -#include <mbgl/util/color.hpp> - -#include <cassert> -#include <algorithm> -#include <iostream> -#include <unordered_set> - -namespace mbgl { - -using namespace style; - -static gl::VertexVector<FillLayoutVertex> tileVertices() { - gl::VertexVector<FillLayoutVertex> result; - result.emplace_back(FillProgram::layoutVertex({ 0, 0 })); - result.emplace_back(FillProgram::layoutVertex({ util::EXTENT, 0 })); - result.emplace_back(FillProgram::layoutVertex({ 0, util::EXTENT })); - result.emplace_back(FillProgram::layoutVertex({ util::EXTENT, util::EXTENT })); - return result; -} - -static gl::IndexVector<gl::Triangles> quadTriangleIndices() { - gl::IndexVector<gl::Triangles> result; - result.emplace_back(0, 1, 2); - result.emplace_back(1, 2, 3); - return result; -} - -static gl::IndexVector<gl::LineStrip> tileLineStripIndices() { - gl::IndexVector<gl::LineStrip> result; - result.emplace_back(0); - result.emplace_back(1); - result.emplace_back(3); - result.emplace_back(2); - result.emplace_back(0); - return result; -} - -static gl::VertexVector<RasterLayoutVertex> rasterVertices() { - gl::VertexVector<RasterLayoutVertex> result; - result.emplace_back(RasterProgram::layoutVertex({ 0, 0 }, { 0, 0 })); - result.emplace_back(RasterProgram::layoutVertex({ util::EXTENT, 0 }, { 32767, 0 })); - result.emplace_back(RasterProgram::layoutVertex({ 0, util::EXTENT }, { 0, 32767 })); - result.emplace_back(RasterProgram::layoutVertex({ util::EXTENT, util::EXTENT }, { 32767, 32767 })); - return result; -} - -static gl::VertexVector<ExtrusionTextureLayoutVertex> extrusionTextureVertices() { - gl::VertexVector<ExtrusionTextureLayoutVertex> result; - result.emplace_back(ExtrusionTextureProgram::layoutVertex({ 0, 0 })); - result.emplace_back(ExtrusionTextureProgram::layoutVertex({ 1, 0 })); - result.emplace_back(ExtrusionTextureProgram::layoutVertex({ 0, 1 })); - result.emplace_back(ExtrusionTextureProgram::layoutVertex({ 1, 1 })); - return result; -} - - -Painter::Painter(gl::Context& context_, - float pixelRatio, - const optional<std::string>& programCacheDir) - : context(context_), - tileVertexBuffer(context.createVertexBuffer(tileVertices())), - rasterVertexBuffer(context.createVertexBuffer(rasterVertices())), - extrusionTextureVertexBuffer(context.createVertexBuffer(extrusionTextureVertices())), - quadTriangleIndexBuffer(context.createIndexBuffer(quadTriangleIndices())), - tileBorderIndexBuffer(context.createIndexBuffer(tileLineStripIndices())) { - - tileTriangleSegments.emplace_back(0, 0, 4, 6); - tileBorderSegments.emplace_back(0, 0, 4, 5); - rasterSegments.emplace_back(0, 0, 4, 6); - extrusionTextureSegments.emplace_back(0, 0, 4, 6); - - programs = std::make_unique<Programs>(context, - ProgramParameters{ pixelRatio, false, programCacheDir }); -#ifndef NDEBUG - overdrawPrograms = - std::make_unique<Programs>(context, ProgramParameters{ pixelRatio, true, programCacheDir }); -#endif -} - -Painter::~Painter() = default; - -bool Painter::needsAnimation() const { - return frameHistory.needsAnimation(util::DEFAULT_TRANSITION_DURATION); -} - -void Painter::cleanup() { - context.performCleanup(); -} - -void Painter::render(RenderStyle& style, const FrameData& frame_, View& view) { - frame = frame_; - if (frame.contextMode == GLContextMode::Shared) { - context.setDirtyState(); - } - - PaintParameters parameters { -#ifndef NDEBUG - paintMode() == PaintMode::Overdraw ? *overdrawPrograms : *programs, -#else - *programs, -#endif - view - }; - - imageManager = style.imageManager.get(); - lineAtlas = style.lineAtlas.get(); - - evaluatedLight = style.getRenderLight().getEvaluated(); - - RenderData renderData = style.getRenderData(frame.debugOptions, state.getAngle()); - const std::vector<RenderItem>& order = renderData.order; - const std::unordered_set<RenderSource*>& sources = renderData.sources; - - // Update the default matrices to the current viewport dimensions. - state.getProjMatrix(projMatrix); - // Calculate a second projection matrix with the near plane clipped to 100 so as - // not to waste lots of depth buffer precision on very close empty space, for layer - // types (fill-extrusion) that use the depth buffer to emulate real-world space. - state.getProjMatrix(nearClippedProjMatrix, 100); - - pixelsToGLUnits = {{ 2.0f / state.getSize().width, -2.0f / state.getSize().height }}; - if (state.getViewportMode() == ViewportMode::FlippedY) { - pixelsToGLUnits[1] *= -1; - } - - frameHistory.record(frame.timePoint, state.getZoom(), - frame.mapMode == MapMode::Continuous ? util::DEFAULT_TRANSITION_DURATION : Milliseconds(0)); - - - // - UPLOAD PASS ------------------------------------------------------------------------------- - // Uploads all required buffers and images before we do any actual rendering. - { - MBGL_DEBUG_GROUP(context, "upload"); - - imageManager->upload(context, 0); - lineAtlas->upload(context, 0); - frameHistory.upload(context, 0); - } - - // - CLEAR ------------------------------------------------------------------------------------- - // Renders the backdrop of the OpenGL view. This also paints in areas where we don't have any - // tiles whatsoever. - { - MBGL_DEBUG_GROUP(context, "clear"); - view.bind(); - context.clear(paintMode() == PaintMode::Overdraw - ? Color::black() - : renderData.backgroundColor, - 1.0f, - 0); - } - - // - CLIPPING MASKS ---------------------------------------------------------------------------- - // Draws the clipping masks to the stencil buffer. - { - MBGL_DEBUG_GROUP(context, "clip"); - - // Update all clipping IDs. - clipIDGenerator = algorithm::ClipIDGenerator(); - for (const auto& source : sources) { - source->startRender(*this); - } - - MBGL_DEBUG_GROUP(context, "clipping masks"); - - static const style::FillPaintProperties::PossiblyEvaluated properties {}; - static const FillProgram::PaintPropertyBinders paintAttibuteData(properties, 0); - - for (const auto& clipID : clipIDGenerator.getClipIDs()) { - programs->fill.get(properties).draw( - context, - gl::Triangles(), - gl::DepthMode::disabled(), - gl::StencilMode { - gl::StencilMode::Always(), - static_cast<int32_t>(clipID.second.reference.to_ulong()), - 0b11111111, - gl::StencilMode::Keep, - gl::StencilMode::Keep, - gl::StencilMode::Replace - }, - gl::ColorMode::disabled(), - FillProgram::UniformValues { - uniforms::u_matrix::Value{ matrixForTile(clipID.first) }, - uniforms::u_world::Value{ context.viewport.getCurrentValue().size }, - }, - tileVertexBuffer, - quadTriangleIndexBuffer, - tileTriangleSegments, - paintAttibuteData, - properties, - state.getZoom(), - "clipping" - ); - } - } - -#if not MBGL_USE_GLES2 and not defined(NDEBUG) - // Render tile clip boundaries, using stencil buffer to calculate fill color. - if (frame.debugOptions & MapDebugOptions::StencilClip) { - context.setStencilMode(gl::StencilMode::disabled()); - context.setDepthMode(gl::DepthMode::disabled()); - context.setColorMode(gl::ColorMode::unblended()); - context.program = 0; - - // Reset the value in case someone else changed it, or it's dirty. - context.pixelTransferStencil = gl::value::PixelTransferStencil::Default; - - // Read the stencil buffer - const auto viewport = context.viewport.getCurrentValue(); - auto image = - context.readFramebuffer<AlphaImage, gl::TextureFormat::Stencil>(viewport.size, false); - - // Scale the Stencil buffer to cover the entire color space. - auto it = image.data.get(); - auto end = it + viewport.size.width * viewport.size.height; - const auto factor = 255.0f / *std::max_element(it, end); - for (; it != end; ++it) { - *it *= factor; - } - - context.pixelZoom = { 1, 1 }; - context.rasterPos = { -1, -1, 0, 1 }; - context.drawPixels(image); - - return; - } -#endif - - // Actually render the layers - if (debug::renderTree) { Log::Info(Event::Render, "{"); indent++; } - - depthRangeSize = 1 - (order.size() + 2) * numSublayers * depthEpsilon; - - // - OPAQUE PASS ------------------------------------------------------------------------------- - // Render everything top-to-bottom by using reverse iterators. Render opaque objects first. - { - pass = RenderPass::Opaque; - MBGL_DEBUG_GROUP(context, "opaque"); - - if (debug::renderTree) { - Log::Info(Event::Render, "%*s%s {", indent++ * 4, "", "opaque"); - } - - uint32_t i = 0; - for (auto it = order.rbegin(); it != order.rend(); ++it, ++i) { - currentLayer = i; - if (it->layer.hasRenderPass(pass)) { - MBGL_DEBUG_GROUP(context, it->layer.getID()); - it->layer.render(*this, parameters, it->source); - } - } - - if (debug::renderTree) { - Log::Info(Event::Render, "%*s%s", --indent * 4, "", "}"); - } - } - - // - TRANSLUCENT PASS -------------------------------------------------------------------------- - // Make a second pass, rendering translucent objects. This time, we render bottom-to-top. - { - pass = RenderPass::Translucent; - MBGL_DEBUG_GROUP(context, "translucent"); - - if (debug::renderTree) { - Log::Info(Event::Render, "%*s%s {", indent++ * 4, "", "translucent"); - } - - uint32_t i = static_cast<uint32_t>(order.size()) - 1; - for (auto it = order.begin(); it != order.end(); ++it, --i) { - currentLayer = i; - if (it->layer.hasRenderPass(pass)) { - MBGL_DEBUG_GROUP(context, it->layer.getID()); - it->layer.render(*this, parameters, it->source); - } - } - - if (debug::renderTree) { - Log::Info(Event::Render, "%*s%s", --indent * 4, "", "}"); - } - } - - if (debug::renderTree) { Log::Info(Event::Render, "}"); indent--; } - - // - DEBUG PASS -------------------------------------------------------------------------------- - // Renders debug overlays. - { - MBGL_DEBUG_GROUP(context, "debug"); - - // Finalize the rendering, e.g. by calling debug render calls per tile. - // This guarantees that we have at least one function per tile called. - // When only rendering layers via the stylesheet, it's possible that we don't - // ever visit a tile during rendering. - for (const auto& source : sources) { - source->finishRender(*this); - } - } - -#if not MBGL_USE_GLES2 and not defined(NDEBUG) - // Render the depth buffer. - if (frame.debugOptions & MapDebugOptions::DepthBuffer) { - context.setStencilMode(gl::StencilMode::disabled()); - context.setDepthMode(gl::DepthMode::disabled()); - context.setColorMode(gl::ColorMode::unblended()); - context.program = 0; - - // Scales the values in the depth buffer so that they cover the entire grayscale range. This - // makes it easier to spot tiny differences. - const float base = 1.0f / (1.0f - depthRangeSize); - context.pixelTransferDepth = { base, 1.0f - base }; - - // Read the stencil buffer - auto viewport = context.viewport.getCurrentValue(); - auto image = - context.readFramebuffer<AlphaImage, gl::TextureFormat::Depth>(viewport.size, false); - - context.pixelZoom = { 1, 1 }; - context.rasterPos = { -1, -1, 0, 1 }; - context.drawPixels(image); - } -#endif - - // TODO: Find a better way to unbind VAOs after we're done with them without introducing - // unnecessary bind(0)/bind(N) sequences. - { - MBGL_DEBUG_GROUP(context, "cleanup"); - - context.activeTexture = 1; - context.texture[1] = 0; - context.activeTexture = 0; - context.texture[0] = 0; - - context.bindVertexArray = 0; - } -} - -mat4 Painter::matrixForTile(const UnwrappedTileID& tileID) { - mat4 matrix; - state.matrixFor(matrix, tileID); - matrix::multiply(matrix, projMatrix, matrix); - return matrix; -} - -gl::DepthMode Painter::depthModeForSublayer(uint8_t n, gl::DepthMode::Mask mask) const { - float nearDepth = ((1 + currentLayer) * numSublayers + n) * depthEpsilon; - float farDepth = nearDepth + depthRangeSize; - return gl::DepthMode { gl::DepthMode::LessEqual, mask, { nearDepth, farDepth } }; -} - -gl::StencilMode Painter::stencilModeForClipping(const ClipID& id) const { - return gl::StencilMode { - gl::StencilMode::Equal { static_cast<uint32_t>(id.mask.to_ulong()) }, - static_cast<int32_t>(id.reference.to_ulong()), - 0, - gl::StencilMode::Keep, - gl::StencilMode::Keep, - gl::StencilMode::Replace - }; -} - -gl::ColorMode Painter::colorModeForRenderPass() const { - if (paintMode() == PaintMode::Overdraw) { - const float overdraw = 1.0f / 8.0f; - return gl::ColorMode { - gl::ColorMode::Add { - gl::ColorMode::ConstantColor, - gl::ColorMode::One - }, - Color { overdraw, overdraw, overdraw, 0.0f }, - gl::ColorMode::Mask { true, true, true, true } - }; - } else if (pass == RenderPass::Translucent) { - return gl::ColorMode::alphaBlended(); - } else { - return gl::ColorMode::unblended(); - } -} - -} // namespace mbgl diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp deleted file mode 100644 index 0b4d9e5fa9..0000000000 --- a/src/mbgl/renderer/painter.hpp +++ /dev/null @@ -1,129 +0,0 @@ -#pragma once - -#include <mbgl/map/transform_state.hpp> - -#include <mbgl/tile/tile_id.hpp> - -#include <mbgl/renderer/frame_history.hpp> -#include <mbgl/renderer/render_item.hpp> -#include <mbgl/renderer/bucket.hpp> -#include <mbgl/renderer/render_light.hpp> -#include <mbgl/renderer/render_pass.hpp> - -#include <mbgl/gl/context.hpp> -#include <mbgl/programs/debug_program.hpp> -#include <mbgl/programs/fill_program.hpp> -#include <mbgl/programs/extrusion_texture_program.hpp> -#include <mbgl/programs/raster_program.hpp> - -#include <mbgl/util/noncopyable.hpp> -#include <mbgl/util/chrono.hpp> -#include <mbgl/util/offscreen_texture.hpp> - -#include <mbgl/algorithm/generate_clip_ids.hpp> - -#include <array> -#include <vector> - -namespace mbgl { - -class RenderStyle; -class ImageManager; -class View; -class LineAtlas; -class Programs; -class PaintParameters; -struct ClipID; - -struct FrameData { - TimePoint timePoint; - float pixelRatio; - MapMode mapMode; - GLContextMode contextMode; - MapDebugOptions debugOptions; -}; - -class Painter : private util::noncopyable { -public: - Painter(gl::Context&, float pixelRatio, const optional<std::string>& programCacheDir); - ~Painter(); - - void render(RenderStyle&, - const FrameData&, - View&); - - void cleanup(); - bool needsAnimation() const; - - mat4 matrixForTile(const UnwrappedTileID&); - gl::DepthMode depthModeForSublayer(uint8_t n, gl::DepthMode::Mask) const; - gl::StencilMode stencilModeForClipping(const ClipID&) const; - gl::ColorMode colorModeForRenderPass() const; - -#ifndef NDEBUG - PaintMode paintMode() const { - return frame.debugOptions & MapDebugOptions::Overdraw ? PaintMode::Overdraw - : PaintMode::Regular; - } -#else - PaintMode paintMode() const { - return PaintMode::Regular; - } -#endif - - gl::Context& context; - - TransformState state; - - algorithm::ClipIDGenerator clipIDGenerator; - - mat4 projMatrix; - mat4 nearClippedProjMatrix; - - std::array<float, 2> pixelsToGLUnits; - - const mat4 identityMatrix = []{ - mat4 identity; - matrix::identity(identity); - return identity; - }(); - - FrameData frame; - - int indent = 0; - - RenderPass pass = RenderPass::Opaque; - - int numSublayers = 3; - uint32_t currentLayer; - float depthRangeSize; - const float depthEpsilon = 1.0f / (1 << 16); - - ImageManager* imageManager = nullptr; - LineAtlas* lineAtlas = nullptr; - - optional<OffscreenTexture> extrusionTexture; - - EvaluatedLight evaluatedLight; - - FrameHistory frameHistory; - - std::unique_ptr<Programs> programs; -#ifndef NDEBUG - std::unique_ptr<Programs> overdrawPrograms; -#endif - - gl::VertexBuffer<FillLayoutVertex> tileVertexBuffer; - gl::VertexBuffer<RasterLayoutVertex> rasterVertexBuffer; - gl::VertexBuffer<ExtrusionTextureLayoutVertex> extrusionTextureVertexBuffer; - - gl::IndexBuffer<gl::Triangles> quadTriangleIndexBuffer; - gl::IndexBuffer<gl::LineStrip> tileBorderIndexBuffer; - - SegmentVector<FillAttributes> tileTriangleSegments; - SegmentVector<DebugAttributes> tileBorderSegments; - SegmentVector<RasterAttributes> rasterSegments; - SegmentVector<ExtrusionTextureAttributes> extrusionTextureSegments; -}; - -} // namespace mbgl diff --git a/src/mbgl/renderer/render_layer.hpp b/src/mbgl/renderer/render_layer.hpp index 79a292953b..dfc6bcf2fd 100644 --- a/src/mbgl/renderer/render_layer.hpp +++ b/src/mbgl/renderer/render_layer.hpp @@ -14,7 +14,6 @@ class Bucket; class BucketParameters; class TransitionParameters; class PropertyEvaluationParameters; -class Painter; class PaintParameters; class RenderSource; class RenderTile; @@ -62,7 +61,7 @@ public: // Checks whether this layer can be rendered. bool needsRendering(float zoom) const; - virtual void render(Painter&, PaintParameters&, RenderSource*) = 0; + virtual void render(PaintParameters&, RenderSource*) = 0; // Check wether the given geometry intersects // with the feature diff --git a/src/mbgl/renderer/render_source.hpp b/src/mbgl/renderer/render_source.hpp index f7c9a4e86f..f329035086 100644 --- a/src/mbgl/renderer/render_source.hpp +++ b/src/mbgl/renderer/render_source.hpp @@ -15,7 +15,7 @@ namespace mbgl { -class Painter; +class PaintParameters; class TransformState; class RenderTile; class RenderStyle; @@ -54,8 +54,8 @@ public: bool needsRelayout, const TileParameters&) = 0; - virtual void startRender(Painter&) = 0; - virtual void finishRender(Painter&) = 0; + virtual void startRender(PaintParameters&) = 0; + virtual void finishRender(PaintParameters&) = 0; // Returns an unsorted list of RenderTiles. virtual std::vector<std::reference_wrapper<RenderTile>> getRenderTiles() = 0; diff --git a/src/mbgl/renderer/render_static_data.cpp b/src/mbgl/renderer/render_static_data.cpp new file mode 100644 index 0000000000..4c6028d7b6 --- /dev/null +++ b/src/mbgl/renderer/render_static_data.cpp @@ -0,0 +1,67 @@ +#include <mbgl/renderer/render_static_data.hpp> +#include <mbgl/programs/program_parameters.hpp> + +namespace mbgl { + +static gl::VertexVector<FillLayoutVertex> tileVertices() { + gl::VertexVector<FillLayoutVertex> result; + result.emplace_back(FillProgram::layoutVertex({ 0, 0 })); + result.emplace_back(FillProgram::layoutVertex({ util::EXTENT, 0 })); + result.emplace_back(FillProgram::layoutVertex({ 0, util::EXTENT })); + result.emplace_back(FillProgram::layoutVertex({ util::EXTENT, util::EXTENT })); + return result; +} + +static gl::IndexVector<gl::Triangles> quadTriangleIndices() { + gl::IndexVector<gl::Triangles> result; + result.emplace_back(0, 1, 2); + result.emplace_back(1, 2, 3); + return result; +} + +static gl::IndexVector<gl::LineStrip> tileLineStripIndices() { + gl::IndexVector<gl::LineStrip> result; + result.emplace_back(0); + result.emplace_back(1); + result.emplace_back(3); + result.emplace_back(2); + result.emplace_back(0); + return result; +} + +static gl::VertexVector<RasterLayoutVertex> rasterVertices() { + gl::VertexVector<RasterLayoutVertex> result; + result.emplace_back(RasterProgram::layoutVertex({ 0, 0 }, { 0, 0 })); + result.emplace_back(RasterProgram::layoutVertex({ util::EXTENT, 0 }, { 32767, 0 })); + result.emplace_back(RasterProgram::layoutVertex({ 0, util::EXTENT }, { 0, 32767 })); + result.emplace_back(RasterProgram::layoutVertex({ util::EXTENT, util::EXTENT }, { 32767, 32767 })); + return result; +} + +static gl::VertexVector<ExtrusionTextureLayoutVertex> extrusionTextureVertices() { + gl::VertexVector<ExtrusionTextureLayoutVertex> result; + result.emplace_back(ExtrusionTextureProgram::layoutVertex({ 0, 0 })); + result.emplace_back(ExtrusionTextureProgram::layoutVertex({ 1, 0 })); + result.emplace_back(ExtrusionTextureProgram::layoutVertex({ 0, 1 })); + result.emplace_back(ExtrusionTextureProgram::layoutVertex({ 1, 1 })); + return result; +} + +RenderStaticData::RenderStaticData(gl::Context& context, float pixelRatio, const optional<std::string>& programCacheDir) + : tileVertexBuffer(context.createVertexBuffer(tileVertices())), + rasterVertexBuffer(context.createVertexBuffer(rasterVertices())), + extrusionTextureVertexBuffer(context.createVertexBuffer(extrusionTextureVertices())), + quadTriangleIndexBuffer(context.createIndexBuffer(quadTriangleIndices())), + tileBorderIndexBuffer(context.createIndexBuffer(tileLineStripIndices())), + programs(context, ProgramParameters { pixelRatio, false, programCacheDir }) +#ifndef NDEBUG + , overdrawPrograms(context, ProgramParameters { pixelRatio, true, programCacheDir }) +#endif +{ + tileTriangleSegments.emplace_back(0, 0, 4, 6); + tileBorderSegments.emplace_back(0, 0, 4, 5); + rasterSegments.emplace_back(0, 0, 4, 6); + extrusionTextureSegments.emplace_back(0, 0, 4, 6); +} + +} // namespace mbgl diff --git a/src/mbgl/renderer/render_static_data.hpp b/src/mbgl/renderer/render_static_data.hpp new file mode 100644 index 0000000000..07a47b4c8f --- /dev/null +++ b/src/mbgl/renderer/render_static_data.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include <mbgl/gl/vertex_buffer.hpp> +#include <mbgl/gl/index_buffer.hpp> +#include <mbgl/programs/programs.hpp> +#include <mbgl/util/optional.hpp> +#include <mbgl/util/offscreen_texture.hpp> + +#include <string> + +namespace mbgl { + +class RenderStaticData { +public: + RenderStaticData(gl::Context&, float pixelRatio, const optional<std::string>& programCacheDir); + + gl::VertexBuffer<FillLayoutVertex> tileVertexBuffer; + gl::VertexBuffer<RasterLayoutVertex> rasterVertexBuffer; + gl::VertexBuffer<ExtrusionTextureLayoutVertex> extrusionTextureVertexBuffer; + + gl::IndexBuffer<gl::Triangles> quadTriangleIndexBuffer; + gl::IndexBuffer<gl::LineStrip> tileBorderIndexBuffer; + + SegmentVector<FillAttributes> tileTriangleSegments; + SegmentVector<DebugAttributes> tileBorderSegments; + SegmentVector<RasterAttributes> rasterSegments; + SegmentVector<ExtrusionTextureAttributes> extrusionTextureSegments; + + optional<OffscreenTexture> extrusionTexture; + + Programs programs; + +#ifndef NDEBUG + Programs overdrawPrograms; +#endif +}; + +} // namespace mbgl diff --git a/src/mbgl/renderer/render_tile.cpp b/src/mbgl/renderer/render_tile.cpp index e28606633a..4e924331cc 100644 --- a/src/mbgl/renderer/render_tile.cpp +++ b/src/mbgl/renderer/render_tile.cpp @@ -1,6 +1,7 @@ #include <mbgl/renderer/render_tile.hpp> -#include <mbgl/renderer/painter.hpp> +#include <mbgl/renderer/paint_parameters.hpp> #include <mbgl/renderer/buckets/debug_bucket.hpp> +#include <mbgl/renderer/render_static_data.hpp> #include <mbgl/programs/programs.hpp> #include <mbgl/map/transform_state.hpp> #include <mbgl/tile/tile.hpp> @@ -51,30 +52,30 @@ mat4 RenderTile::translatedClipMatrix(const std::array<float, 2>& translation, return translateVtxMatrix(nearClippedMatrix, translation, anchor, state, false); } -void RenderTile::startRender(Painter& painter) { - tile.upload(painter.context); +void RenderTile::startRender(PaintParameters& parameters) { + tile.upload(parameters.context); // Calculate two matrices for this tile: matrix is the standard tile matrix; nearClippedMatrix // clips the near plane to 100 to save depth buffer precision - painter.state.matrixFor(matrix, id); - painter.state.matrixFor(nearClippedMatrix, id); - matrix::multiply(matrix, painter.projMatrix, matrix); - matrix::multiply(nearClippedMatrix, painter.nearClippedProjMatrix, nearClippedMatrix); + parameters.state.matrixFor(matrix, id); + parameters.state.matrixFor(nearClippedMatrix, id); + matrix::multiply(matrix, parameters.projMatrix, matrix); + matrix::multiply(nearClippedMatrix, parameters.nearClippedProjMatrix, nearClippedMatrix); } -void RenderTile::finishRender(Painter& painter) { - if (!used || painter.frame.debugOptions == MapDebugOptions::NoDebug) +void RenderTile::finishRender(PaintParameters& parameters) { + if (!used || parameters.debugOptions == MapDebugOptions::NoDebug) return; static const style::Properties<>::PossiblyEvaluated properties {}; static const DebugProgram::PaintPropertyBinders paintAttibuteData(properties, 0); auto draw = [&] (Color color, const auto& vertexBuffer, const auto& indexBuffer, const auto& segments, auto drawMode) { - painter.programs->debug.draw( - painter.context, + parameters.programs.debug.draw( + parameters.context, drawMode, gl::DepthMode::disabled(), - painter.stencilModeForClipping(clip), + parameters.stencilModeForClipping(clip), gl::ColorMode::unblended(), DebugProgram::UniformValues { uniforms::u_matrix::Value{ matrix }, @@ -85,41 +86,41 @@ void RenderTile::finishRender(Painter& painter) { segments, paintAttibuteData, properties, - painter.state.getZoom(), + parameters.state.getZoom(), "debug" ); }; - if (painter.frame.debugOptions & (MapDebugOptions::Timestamps | MapDebugOptions::ParseStatus)) { + if (parameters.debugOptions & (MapDebugOptions::Timestamps | MapDebugOptions::ParseStatus)) { if (!tile.debugBucket || tile.debugBucket->renderable != tile.isRenderable() || tile.debugBucket->complete != tile.isComplete() || !(tile.debugBucket->modified == tile.modified) || !(tile.debugBucket->expires == tile.expires) || - tile.debugBucket->debugMode != painter.frame.debugOptions) { + tile.debugBucket->debugMode != parameters.debugOptions) { tile.debugBucket = std::make_unique<DebugBucket>( tile.id, tile.isRenderable(), tile.isComplete(), tile.modified, - tile.expires, painter.frame.debugOptions, painter.context); + tile.expires, parameters.debugOptions, parameters.context); } draw(Color::white(), *tile.debugBucket->vertexBuffer, *tile.debugBucket->indexBuffer, tile.debugBucket->segments, - gl::Lines { 4.0f * painter.frame.pixelRatio }); + gl::Lines { 4.0f * parameters.pixelRatio }); draw(Color::black(), *tile.debugBucket->vertexBuffer, *tile.debugBucket->indexBuffer, tile.debugBucket->segments, - gl::Lines { 2.0f * painter.frame.pixelRatio }); + gl::Lines { 2.0f * parameters.pixelRatio }); } - if (painter.frame.debugOptions & MapDebugOptions::TileBorders) { + if (parameters.debugOptions & MapDebugOptions::TileBorders) { draw(Color::red(), - painter.tileVertexBuffer, - painter.tileBorderIndexBuffer, - painter.tileBorderSegments, - gl::LineStrip { 4.0f * painter.frame.pixelRatio }); + parameters.staticData.tileVertexBuffer, + parameters.staticData.tileBorderIndexBuffer, + parameters.staticData.tileBorderSegments, + gl::LineStrip { 4.0f * parameters.pixelRatio }); } } diff --git a/src/mbgl/renderer/render_tile.hpp b/src/mbgl/renderer/render_tile.hpp index 98db111002..d5ed4f0018 100644 --- a/src/mbgl/renderer/render_tile.hpp +++ b/src/mbgl/renderer/render_tile.hpp @@ -11,7 +11,7 @@ namespace mbgl { class Tile; class TransformState; -class Painter; +class PaintParameters; class RenderTile final { public: @@ -36,8 +36,8 @@ public: style::TranslateAnchorType anchor, const TransformState&) const; - void startRender(Painter&); - void finishRender(Painter&); + void startRender(PaintParameters&); + void finishRender(PaintParameters&); mat4 translateVtxMatrix(const mat4& tileMatrix, const std::array<float, 2>& translation, diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp index 38aaf95671..981c09e806 100644 --- a/src/mbgl/renderer/renderer_impl.cpp +++ b/src/mbgl/renderer/renderer_impl.cpp @@ -1,14 +1,18 @@ #include <mbgl/renderer/renderer_impl.hpp> -#include <mbgl/actor/scheduler.hpp> -#include <mbgl/storage/file_source.hpp> #include <mbgl/renderer/render_style.hpp> -#include <mbgl/renderer/painter.hpp> +#include <mbgl/renderer/render_static_data.hpp> +#include <mbgl/renderer/render_item.hpp> #include <mbgl/renderer/update_parameters.hpp> -#include <mbgl/map/transform_state.hpp> +#include <mbgl/renderer/paint_parameters.hpp> #include <mbgl/renderer/backend_scope.hpp> +#include <mbgl/renderer/image_manager.hpp> +#include <mbgl/gl/debugging.hpp> +#include <mbgl/geometry/line_atlas.hpp> namespace mbgl { +using namespace style; + static RendererObserver& nullObserver() { static RendererObserver observer; return observer; @@ -23,8 +27,8 @@ Renderer::Impl::Impl(RendererBackend& backend_, : backend(backend_) , observer(&nullObserver()) , contextMode(contextMode_) - , pixelRatio(pixelRatio_), - programCacheDir(programCacheDir_) + , pixelRatio(pixelRatio_) + , programCacheDir(programCacheDir_) , renderStyle(std::make_unique<RenderStyle>(scheduler_, fileSource_)) { renderStyle->setObserver(this); @@ -33,6 +37,7 @@ Renderer::Impl::Impl(RendererBackend& backend_, Renderer::Impl::~Impl() { BackendScope guard { backend, backend.getScopeType()}; renderStyle.reset(); + staticData.reset(); }; void Renderer::Impl::setObserver(RendererObserver* observer_) { @@ -45,19 +50,23 @@ void Renderer::Impl::render(View& view, const UpdateParameters& updateParameters BackendScope guard { backend, backend.getScopeType() }; - // Update render style renderStyle->update(updateParameters); + transformState = updateParameters.transformState; - // Initialize painter - if (!painter) { - gl::Context& context = backend.getContext(); - painter = std::make_unique<Painter>(context, - pixelRatio, - programCacheDir); + if (!staticData) { + staticData = std::make_unique<RenderStaticData>(backend.getContext(), pixelRatio, programCacheDir); } - // Update transform state on painter. - painter->state = updateParameters.transformState; + PaintParameters parameters { + backend.getContext(), + pixelRatio, + contextMode, + view, + updateParameters, + *renderStyle, + *staticData, + frameHistory + }; bool loaded = updateParameters.styleLoaded && renderStyle->isLoaded(); @@ -68,20 +77,14 @@ void Renderer::Impl::render(View& view, const UpdateParameters& updateParameters observer->onWillStartRenderingFrame(); - FrameData frameData { updateParameters.timePoint, - pixelRatio, - updateParameters.mode, - contextMode, - updateParameters.debugOptions }; - backend.updateAssumedState(); - painter->render(*renderStyle, frameData, view); - painter->cleanup(); + doRender(parameters); + parameters.context.performCleanup(); observer->onDidFinishRenderingFrame( loaded ? RendererObserver::RenderMode::Full : RendererObserver::RenderMode::Partial, - renderStyle->hasTransitions() || painter->needsAnimation() + renderStyle->hasTransitions() || frameHistory.needsAnimation(util::DEFAULT_TRANSITION_DURATION) ); if (!loaded) { @@ -91,32 +94,242 @@ void Renderer::Impl::render(View& view, const UpdateParameters& updateParameters observer->onDidFinishRenderingMap(); } } else if (loaded) { - // We can render the map in still mode observer->onWillStartRenderingMap(); observer->onWillStartRenderingFrame(); - FrameData frameData { updateParameters.timePoint, - pixelRatio, - updateParameters.mode, - contextMode, - updateParameters.debugOptions }; - backend.updateAssumedState(); - painter->render(*renderStyle, frameData, view); + doRender(parameters); observer->onDidFinishRenderingFrame(RendererObserver::RenderMode::Full, false); observer->onDidFinishRenderingMap(); - + // Cleanup only after signaling completion - painter->cleanup(); + parameters.context.performCleanup(); } } -std::vector<Feature> Renderer::Impl::queryRenderedFeatures(const ScreenLineString& geometry, const RenderedQueryOptions& options) const { - if (!painter) return {}; +void Renderer::Impl::doRender(PaintParameters& parameters) { + if (parameters.contextMode == GLContextMode::Shared) { + parameters.context.setDirtyState(); + } + + RenderData renderData = renderStyle->getRenderData(parameters.debugOptions, parameters.state.getAngle()); + const std::vector<RenderItem>& order = renderData.order; + const std::unordered_set<RenderSource*>& sources = renderData.sources; + + frameHistory.record(parameters.timePoint, + parameters.state.getZoom(), + parameters.mapMode == MapMode::Continuous ? util::DEFAULT_TRANSITION_DURATION : Milliseconds(0)); + + // - UPLOAD PASS ------------------------------------------------------------------------------- + // Uploads all required buffers and images before we do any actual rendering. + { + MBGL_DEBUG_GROUP(parameters.context, "upload"); + + parameters.imageManager.upload(parameters.context, 0); + parameters.lineAtlas.upload(parameters.context, 0); + parameters.frameHistory.upload(parameters.context, 0); + } + + // - CLEAR ------------------------------------------------------------------------------------- + // Renders the backdrop of the OpenGL view. This also paints in areas where we don't have any + // tiles whatsoever. + { + MBGL_DEBUG_GROUP(parameters.context, "clear"); + parameters.view.bind(); + parameters.context.clear((parameters.debugOptions & MapDebugOptions::Overdraw) + ? Color::black() + : renderData.backgroundColor, + 1.0f, + 0); + } + + // - CLIPPING MASKS ---------------------------------------------------------------------------- + // Draws the clipping masks to the stencil buffer. + { + MBGL_DEBUG_GROUP(parameters.context, "clip"); + + // Update all clipping IDs. + for (const auto& source : sources) { + source->startRender(parameters); + } + + MBGL_DEBUG_GROUP(parameters.context, "clipping masks"); + + static const style::FillPaintProperties::PossiblyEvaluated properties {}; + static const FillProgram::PaintPropertyBinders paintAttibuteData(properties, 0); + + for (const auto& clipID : parameters.clipIDGenerator.getClipIDs()) { + parameters.staticData.programs.fill.get(properties).draw( + parameters.context, + gl::Triangles(), + gl::DepthMode::disabled(), + gl::StencilMode { + gl::StencilMode::Always(), + static_cast<int32_t>(clipID.second.reference.to_ulong()), + 0b11111111, + gl::StencilMode::Keep, + gl::StencilMode::Keep, + gl::StencilMode::Replace + }, + gl::ColorMode::disabled(), + FillProgram::UniformValues { + uniforms::u_matrix::Value{ parameters.matrixForTile(clipID.first) }, + uniforms::u_world::Value{ parameters.context.viewport.getCurrentValue().size }, + }, + parameters.staticData.tileVertexBuffer, + parameters.staticData.quadTriangleIndexBuffer, + parameters.staticData.tileTriangleSegments, + paintAttibuteData, + properties, + parameters.state.getZoom(), + "clipping" + ); + } + } + +#if not MBGL_USE_GLES2 and not defined(NDEBUG) + // Render tile clip boundaries, using stencil buffer to calculate fill color. + if (parameters.debugOptions & MapDebugOptions::StencilClip) { + parameters.context.setStencilMode(gl::StencilMode::disabled()); + parameters.context.setDepthMode(gl::DepthMode::disabled()); + parameters.context.setColorMode(gl::ColorMode::unblended()); + parameters.context.program = 0; + + // Reset the value in case someone else changed it, or it's dirty. + parameters.context.pixelTransferStencil = gl::value::PixelTransferStencil::Default; + + // Read the stencil buffer + const auto viewport = parameters.context.viewport.getCurrentValue(); + auto image = parameters.context.readFramebuffer<AlphaImage, gl::TextureFormat::Stencil>(viewport.size, false); + + // Scale the Stencil buffer to cover the entire color space. + auto it = image.data.get(); + auto end = it + viewport.size.width * viewport.size.height; + const auto factor = 255.0f / *std::max_element(it, end); + for (; it != end; ++it) { + *it *= factor; + } + + parameters.context.pixelZoom = { 1, 1 }; + parameters.context.rasterPos = { -1, -1, 0, 1 }; + parameters.context.drawPixels(image); + + return; + } +#endif + + int indent = 0; + + // Actually render the layers + if (debug::renderTree) { Log::Info(Event::Render, "{"); indent++; } + + parameters.depthRangeSize = 1 - (order.size() + 2) * parameters.numSublayers * parameters.depthEpsilon; + + // - OPAQUE PASS ------------------------------------------------------------------------------- + // Render everything top-to-bottom by using reverse iterators. Render opaque objects first. + { + parameters.pass = RenderPass::Opaque; + MBGL_DEBUG_GROUP(parameters.context, "opaque"); + + if (debug::renderTree) { + Log::Info(Event::Render, "%*s%s {", indent++ * 4, "", "opaque"); + } + + uint32_t i = 0; + for (auto it = order.rbegin(); it != order.rend(); ++it, ++i) { + parameters.currentLayer = i; + if (it->layer.hasRenderPass(parameters.pass)) { + MBGL_DEBUG_GROUP(parameters.context, it->layer.getID()); + it->layer.render(parameters, it->source); + } + } - return renderStyle->queryRenderedFeatures(geometry, painter->state, options); + if (debug::renderTree) { + Log::Info(Event::Render, "%*s%s", --indent * 4, "", "}"); + } + } + + // - TRANSLUCENT PASS -------------------------------------------------------------------------- + // Make a second pass, rendering translucent objects. This time, we render bottom-to-top. + { + parameters.pass = RenderPass::Translucent; + MBGL_DEBUG_GROUP(parameters.context, "translucent"); + + if (debug::renderTree) { + Log::Info(Event::Render, "%*s%s {", indent++ * 4, "", "translucent"); + } + + uint32_t i = static_cast<uint32_t>(order.size()) - 1; + for (auto it = order.begin(); it != order.end(); ++it, --i) { + parameters.currentLayer = i; + if (it->layer.hasRenderPass(parameters.pass)) { + MBGL_DEBUG_GROUP(parameters.context, it->layer.getID()); + it->layer.render(parameters, it->source); + } + } + + if (debug::renderTree) { + Log::Info(Event::Render, "%*s%s", --indent * 4, "", "}"); + } + } + + if (debug::renderTree) { Log::Info(Event::Render, "}"); indent--; } + + // - DEBUG PASS -------------------------------------------------------------------------------- + // Renders debug overlays. + { + MBGL_DEBUG_GROUP(parameters.context, "debug"); + + // Finalize the rendering, e.g. by calling debug render calls per tile. + // This guarantees that we have at least one function per tile called. + // When only rendering layers via the stylesheet, it's possible that we don't + // ever visit a tile during rendering. + for (const auto& source : sources) { + source->finishRender(parameters); + } + } + +#if not MBGL_USE_GLES2 and not defined(NDEBUG) + // Render the depth buffer. + if (parameters.debugOptions & MapDebugOptions::DepthBuffer) { + parameters.context.setStencilMode(gl::StencilMode::disabled()); + parameters.context.setDepthMode(gl::DepthMode::disabled()); + parameters.context.setColorMode(gl::ColorMode::unblended()); + parameters.context.program = 0; + + // Scales the values in the depth buffer so that they cover the entire grayscale range. This + // makes it easier to spot tiny differences. + const float base = 1.0f / (1.0f - parameters.depthRangeSize); + parameters.context.pixelTransferDepth = { base, 1.0f - base }; + + // Read the stencil buffer + auto viewport = parameters.context.viewport.getCurrentValue(); + auto image = parameters.context.readFramebuffer<AlphaImage, gl::TextureFormat::Depth>(viewport.size, false); + + parameters.context.pixelZoom = { 1, 1 }; + parameters.context.rasterPos = { -1, -1, 0, 1 }; + parameters.context.drawPixels(image); + } +#endif + + // TODO: Find a better way to unbind VAOs after we're done with them without introducing + // unnecessary bind(0)/bind(N) sequences. + { + MBGL_DEBUG_GROUP(parameters.context, "cleanup"); + + parameters.context.activeTexture = 1; + parameters.context.texture[1] = 0; + parameters.context.activeTexture = 0; + parameters.context.texture[0] = 0; + + parameters.context.bindVertexArray = 0; + } +} + +std::vector<Feature> Renderer::Impl::queryRenderedFeatures(const ScreenLineString& geometry, const RenderedQueryOptions& options) const { + return renderStyle->queryRenderedFeatures(geometry, transformState, options); } std::vector<Feature> Renderer::Impl::querySourceFeatures(const std::string& sourceID, const SourceQueryOptions& options) const { @@ -128,24 +341,21 @@ std::vector<Feature> Renderer::Impl::querySourceFeatures(const std::string& sour void Renderer::Impl::onInvalidate() { observer->onInvalidate(); -}; +} void Renderer::Impl::onResourceError(std::exception_ptr ptr) { observer->onResourceError(ptr); } void Renderer::Impl::onLowMemory() { - if (painter) { - BackendScope { backend, backend.getScopeType() }; - painter->cleanup(); - } + BackendScope guard { backend, backend.getScopeType() }; + backend.getContext().performCleanup(); renderStyle->onLowMemory(); observer->onInvalidate(); } void Renderer::Impl::dumDebugLogs() { renderStyle->dumpDebugLogs(); -}; - - } + +} // namespace mbgl diff --git a/src/mbgl/renderer/renderer_impl.hpp b/src/mbgl/renderer/renderer_impl.hpp index 2294dde91e..521df6ca63 100644 --- a/src/mbgl/renderer/renderer_impl.hpp +++ b/src/mbgl/renderer/renderer_impl.hpp @@ -1,26 +1,23 @@ #pragma once + #include <mbgl/renderer/renderer.hpp> #include <mbgl/renderer/renderer_backend.hpp> #include <mbgl/renderer/renderer_observer.hpp> #include <mbgl/renderer/render_style_observer.hpp> -#include <mbgl/style/style.hpp> +#include <mbgl/renderer/frame_history.hpp> +#include <mbgl/map/transform_state.hpp> #include <memory> #include <string> +#include <vector> namespace mbgl { -enum class RenderState : uint8_t { - Never, - Partial, - Fully, -}; - -class Painter; -class RenderStyle; -class TransformState; class View; - +class UpdateParameters; +class PaintParameters; +class RenderStyle; +class RenderStaticData; class Renderer::Impl : public RenderStyleObserver { public: @@ -36,29 +33,36 @@ public: std::vector<Feature> querySourceFeatures(const std::string& sourceID, const SourceQueryOptions&) const; void onLowMemory(); - - void dumDebugLogs() ; + void dumDebugLogs(); // RenderStyleObserver implementation - void onInvalidate()override; + void onInvalidate() override; void onResourceError(std::exception_ptr) override; private: + void doRender(PaintParameters&); + friend class Renderer; RendererBackend& backend; - RendererObserver* observer; const GLContextMode contextMode; const float pixelRatio; const optional<std::string> programCacheDir; + enum class RenderState { + Never, + Partial, + Fully, + }; + RenderState renderState = RenderState::Never; + FrameHistory frameHistory; + TransformState transformState; std::unique_ptr<RenderStyle> renderStyle; - std::unique_ptr<Painter> painter; - + std::unique_ptr<RenderStaticData> staticData; }; } // namespace mbgl diff --git a/src/mbgl/renderer/sources/render_geojson_source.cpp b/src/mbgl/renderer/sources/render_geojson_source.cpp index c45a62498d..df8bcc0ae7 100644 --- a/src/mbgl/renderer/sources/render_geojson_source.cpp +++ b/src/mbgl/renderer/sources/render_geojson_source.cpp @@ -1,6 +1,6 @@ #include <mbgl/renderer/sources/render_geojson_source.hpp> #include <mbgl/renderer/render_tile.hpp> -#include <mbgl/renderer/painter.hpp> +#include <mbgl/renderer/paint_parameters.hpp> #include <mbgl/tile/geojson_tile.hpp> #include <mbgl/algorithm/generate_clip_ids.hpp> @@ -59,13 +59,13 @@ void RenderGeoJSONSource::update(Immutable<style::Source::Impl> baseImpl_, }); } -void RenderGeoJSONSource::startRender(Painter& painter) { - painter.clipIDGenerator.update(tilePyramid.getRenderTiles()); - tilePyramid.startRender(painter); +void RenderGeoJSONSource::startRender(PaintParameters& parameters) { + parameters.clipIDGenerator.update(tilePyramid.getRenderTiles()); + tilePyramid.startRender(parameters); } -void RenderGeoJSONSource::finishRender(Painter& painter) { - tilePyramid.finishRender(painter); +void RenderGeoJSONSource::finishRender(PaintParameters& parameters) { + tilePyramid.finishRender(parameters); } std::vector<std::reference_wrapper<RenderTile>> RenderGeoJSONSource::getRenderTiles() { diff --git a/src/mbgl/renderer/sources/render_geojson_source.hpp b/src/mbgl/renderer/sources/render_geojson_source.hpp index bb390a71e3..b84156ab95 100644 --- a/src/mbgl/renderer/sources/render_geojson_source.hpp +++ b/src/mbgl/renderer/sources/render_geojson_source.hpp @@ -22,8 +22,8 @@ public: bool needsRelayout, const TileParameters&) final; - void startRender(Painter&) final; - void finishRender(Painter&) final; + void startRender(PaintParameters&) final; + void finishRender(PaintParameters&) final; std::vector<std::reference_wrapper<RenderTile>> getRenderTiles() final; diff --git a/src/mbgl/renderer/sources/render_image_source.cpp b/src/mbgl/renderer/sources/render_image_source.cpp index 738b8e8034..11ff8c26b1 100644 --- a/src/mbgl/renderer/sources/render_image_source.cpp +++ b/src/mbgl/renderer/sources/render_image_source.cpp @@ -1,10 +1,11 @@ #include <mbgl/map/transform_state.hpp> #include <mbgl/math/log2.hpp> #include <mbgl/renderer/buckets/raster_bucket.hpp> -#include <mbgl/renderer/painter.hpp> +#include <mbgl/renderer/paint_parameters.hpp> #include <mbgl/renderer/render_tile.hpp> #include <mbgl/renderer/sources/render_image_source.hpp> #include <mbgl/renderer/tile_parameters.hpp> +#include <mbgl/renderer/render_static_data.hpp> #include <mbgl/programs/programs.hpp> #include <mbgl/util/tile_coordinate.hpp> #include <mbgl/util/tile_cover.hpp> @@ -28,7 +29,7 @@ bool RenderImageSource::isLoaded() const { return !!bucket; } -void RenderImageSource::startRender(Painter& painter) { +void RenderImageSource::startRender(PaintParameters& parameters) { if (!isLoaded()) { return; } @@ -38,18 +39,18 @@ void RenderImageSource::startRender(Painter& painter) { for (size_t i = 0; i < tileIds.size(); i++) { mat4 matrix; matrix::identity(matrix); - painter.state.matrixFor(matrix, tileIds[i]); - matrix::multiply(matrix, painter.projMatrix, matrix); + parameters.state.matrixFor(matrix, tileIds[i]); + matrix::multiply(matrix, parameters.projMatrix, matrix); matrices.push_back(matrix); } if (bucket->needsUpload()) { - bucket->upload(painter.context); + bucket->upload(parameters.context); } } -void RenderImageSource::finishRender(Painter& painter) { - if (!isLoaded() || !(painter.frame.debugOptions & MapDebugOptions::TileBorders)) { +void RenderImageSource::finishRender(PaintParameters& parameters) { + if (!isLoaded() || !(parameters.debugOptions & MapDebugOptions::TileBorders)) { return; } @@ -57,9 +58,9 @@ void RenderImageSource::finishRender(Painter& painter) { static const DebugProgram::PaintPropertyBinders paintAttibuteData(properties, 0); for (auto matrix : matrices) { - painter.programs->debug.draw( - painter.context, - gl::LineStrip { 4.0f * painter.frame.pixelRatio }, + parameters.programs.debug.draw( + parameters.context, + gl::LineStrip { 4.0f * parameters.pixelRatio }, gl::DepthMode::disabled(), gl::StencilMode::disabled(), gl::ColorMode::unblended(), @@ -67,12 +68,12 @@ void RenderImageSource::finishRender(Painter& painter) { uniforms::u_matrix::Value{ matrix }, uniforms::u_color::Value{ Color::red() } }, - painter.tileVertexBuffer, - painter.tileBorderIndexBuffer, - painter.tileBorderSegments, + parameters.staticData.tileVertexBuffer, + parameters.staticData.tileBorderIndexBuffer, + parameters.staticData.tileBorderSegments, paintAttibuteData, properties, - painter.state.getZoom(), + parameters.state.getZoom(), "debug" ); } diff --git a/src/mbgl/renderer/sources/render_image_source.hpp b/src/mbgl/renderer/sources/render_image_source.hpp index 14e4696f5a..fc1a462090 100644 --- a/src/mbgl/renderer/sources/render_image_source.hpp +++ b/src/mbgl/renderer/sources/render_image_source.hpp @@ -15,8 +15,8 @@ public: bool isLoaded() const final; - void startRender(Painter&) final; - void finishRender(Painter&) final; + void startRender(PaintParameters&) final; + void finishRender(PaintParameters&) final; void update(Immutable<style::Source::Impl>, const std::vector<Immutable<style::Layer::Impl>>&, diff --git a/src/mbgl/renderer/sources/render_raster_source.cpp b/src/mbgl/renderer/sources/render_raster_source.cpp index 408f435a9d..910a812f05 100644 --- a/src/mbgl/renderer/sources/render_raster_source.cpp +++ b/src/mbgl/renderer/sources/render_raster_source.cpp @@ -56,12 +56,12 @@ void RenderRasterSource::update(Immutable<style::Source::Impl> baseImpl_, }); } -void RenderRasterSource::startRender(Painter& painter) { - tilePyramid.startRender(painter); +void RenderRasterSource::startRender(PaintParameters& parameters) { + tilePyramid.startRender(parameters); } -void RenderRasterSource::finishRender(Painter& painter) { - tilePyramid.finishRender(painter); +void RenderRasterSource::finishRender(PaintParameters& parameters) { + tilePyramid.finishRender(parameters); } std::vector<std::reference_wrapper<RenderTile>> RenderRasterSource::getRenderTiles() { diff --git a/src/mbgl/renderer/sources/render_raster_source.hpp b/src/mbgl/renderer/sources/render_raster_source.hpp index 73a2ac3b22..1f4678da9f 100644 --- a/src/mbgl/renderer/sources/render_raster_source.hpp +++ b/src/mbgl/renderer/sources/render_raster_source.hpp @@ -18,8 +18,8 @@ public: bool needsRelayout, const TileParameters&) final; - void startRender(Painter&) final; - void finishRender(Painter&) final; + void startRender(PaintParameters&) final; + void finishRender(PaintParameters&) final; std::vector<std::reference_wrapper<RenderTile>> getRenderTiles() final; diff --git a/src/mbgl/renderer/sources/render_vector_source.cpp b/src/mbgl/renderer/sources/render_vector_source.cpp index 0f44a64b63..47bccdaca8 100644 --- a/src/mbgl/renderer/sources/render_vector_source.cpp +++ b/src/mbgl/renderer/sources/render_vector_source.cpp @@ -1,6 +1,6 @@ #include <mbgl/renderer/sources/render_vector_source.hpp> #include <mbgl/renderer/render_tile.hpp> -#include <mbgl/renderer/painter.hpp> +#include <mbgl/renderer/paint_parameters.hpp> #include <mbgl/tile/vector_tile.hpp> #include <mbgl/algorithm/generate_clip_ids.hpp> @@ -60,13 +60,13 @@ void RenderVectorSource::update(Immutable<style::Source::Impl> baseImpl_, }); } -void RenderVectorSource::startRender(Painter& painter) { - painter.clipIDGenerator.update(tilePyramid.getRenderTiles()); - tilePyramid.startRender(painter); +void RenderVectorSource::startRender(PaintParameters& parameters) { + parameters.clipIDGenerator.update(tilePyramid.getRenderTiles()); + tilePyramid.startRender(parameters); } -void RenderVectorSource::finishRender(Painter& painter) { - tilePyramid.finishRender(painter); +void RenderVectorSource::finishRender(PaintParameters& parameters) { + tilePyramid.finishRender(parameters); } std::vector<std::reference_wrapper<RenderTile>> RenderVectorSource::getRenderTiles() { diff --git a/src/mbgl/renderer/sources/render_vector_source.hpp b/src/mbgl/renderer/sources/render_vector_source.hpp index 231a9071ab..256ad4e800 100644 --- a/src/mbgl/renderer/sources/render_vector_source.hpp +++ b/src/mbgl/renderer/sources/render_vector_source.hpp @@ -18,8 +18,8 @@ public: bool needsRelayout, const TileParameters&) final; - void startRender(Painter&) final; - void finishRender(Painter&) final; + void startRender(PaintParameters&) final; + void finishRender(PaintParameters&) final; std::vector<std::reference_wrapper<RenderTile>> getRenderTiles() final; diff --git a/src/mbgl/renderer/tile_pyramid.cpp b/src/mbgl/renderer/tile_pyramid.cpp index 8d15bd59ab..219f154675 100644 --- a/src/mbgl/renderer/tile_pyramid.cpp +++ b/src/mbgl/renderer/tile_pyramid.cpp @@ -1,6 +1,6 @@ #include <mbgl/renderer/tile_pyramid.hpp> #include <mbgl/renderer/render_tile.hpp> -#include <mbgl/renderer/painter.hpp> +#include <mbgl/renderer/paint_parameters.hpp> #include <mbgl/renderer/render_source.hpp> #include <mbgl/renderer/tile_parameters.hpp> #include <mbgl/renderer/query.hpp> @@ -39,15 +39,15 @@ bool TilePyramid::isLoaded() const { return true; } -void TilePyramid::startRender(Painter& painter) { +void TilePyramid::startRender(PaintParameters& parameters) { for (auto& tile : renderTiles) { - tile.startRender(painter); + tile.startRender(parameters); } } -void TilePyramid::finishRender(Painter& painter) { +void TilePyramid::finishRender(PaintParameters& parameters) { for (auto& tile : renderTiles) { - tile.finishRender(painter); + tile.finishRender(parameters); } } diff --git a/src/mbgl/renderer/tile_pyramid.hpp b/src/mbgl/renderer/tile_pyramid.hpp index ad2f5e1d52..4a77419c2c 100644 --- a/src/mbgl/renderer/tile_pyramid.hpp +++ b/src/mbgl/renderer/tile_pyramid.hpp @@ -18,7 +18,7 @@ namespace mbgl { -class Painter; +class PaintParameters; class TransformState; class RenderTile; class RenderStyle; @@ -42,8 +42,8 @@ public: Range<uint8_t> zoomRange, std::function<std::unique_ptr<Tile> (const OverscaledTileID&)> createTile); - void startRender(Painter&); - void finishRender(Painter&); + void startRender(PaintParameters&); + void finishRender(PaintParameters&); std::vector<std::reference_wrapper<RenderTile>> getRenderTiles(); |