Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Refactor Painter away
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Jul 19, 2017
1 parent 72b7e39 commit 64203ba
Show file tree
Hide file tree
Showing 42 changed files with 814 additions and 872 deletions.
5 changes: 3 additions & 2 deletions cmake/core-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/mbgl/annotation/render_annotation_source.cpp
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/annotation/render_annotation_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class RenderAnnotationSource : public RenderSource {
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;

Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/buckets/debug_bucket.cpp
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
54 changes: 27 additions & 27 deletions src/mbgl/renderer/layers/render_background_layer.cpp
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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.

Expand All @@ -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()
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/layers/render_background_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RenderBackgroundLayer: public RenderLayer {
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;

Expand Down
27 changes: 13 additions & 14 deletions src/mbgl/renderer/layers/render_circle_layer.cpp
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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;
}

Expand All @@ -61,34 +60,34 @@ 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,
*bucket.indexBuffer,
bucket.segments,
bucket.paintPropertyBinders.at(getID()),
evaluated,
painter.state.getZoom(),
parameters.state.getZoom(),
getID()
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/layers/render_circle_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RenderCircleLayer: public RenderLayer {
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&,
Expand Down
15 changes: 8 additions & 7 deletions src/mbgl/renderer/layers/render_custom_layer.cpp
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/layers/render_custom_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RenderCustomLayer: public RenderLayer {
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;

Expand Down
Loading

0 comments on commit 64203ba

Please sign in to comment.