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

Commit

Permalink
[core] Polymorphic bucket creation
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Oct 30, 2015
1 parent 440943e commit ca25594
Show file tree
Hide file tree
Showing 19 changed files with 247 additions and 162 deletions.
4 changes: 4 additions & 0 deletions src/mbgl/layer/background_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ void BackgroundLayer::recalculate(const StyleCalculationParameters& parameters)
passes = properties.isVisible() ? RenderPass::Translucent : RenderPass::None;
}

std::unique_ptr<Bucket> BackgroundLayer::createBucket(StyleBucketParameters&) const {
return nullptr;
}

}
2 changes: 2 additions & 0 deletions src/mbgl/layer/background_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class BackgroundLayer : public StyleLayer {

void recalculate(const StyleCalculationParameters&) override;

std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override;

BackgroundPaintProperties properties;
};

Expand Down
12 changes: 12 additions & 0 deletions src/mbgl/layer/circle_layer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <mbgl/layer/circle_layer.hpp>
#include <mbgl/style/property_parsing.hpp>
#include <mbgl/style/style_bucket_parameters.hpp>
#include <mbgl/renderer/circle_bucket.hpp>

namespace mbgl {

Expand Down Expand Up @@ -27,4 +29,14 @@ void CircleLayer::recalculate(const StyleCalculationParameters& parameters) {
passes = properties.isVisible() ? RenderPass::Translucent : RenderPass::None;
}

std::unique_ptr<Bucket> CircleLayer::createBucket(StyleBucketParameters& parameters) const {
auto bucket = std::make_unique<CircleBucket>();

parameters.eachFilteredFeature(filter, [&] (const auto& feature) {
bucket->addGeometry(feature.getGeometries());
});

return std::move(bucket);
}

}
2 changes: 2 additions & 0 deletions src/mbgl/layer/circle_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class CircleLayer : public StyleLayer {

void recalculate(const StyleCalculationParameters&) override;

std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override;

CirclePaintProperties properties;
};

Expand Down
12 changes: 12 additions & 0 deletions src/mbgl/layer/fill_layer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <mbgl/layer/fill_layer.hpp>
#include <mbgl/style/property_parsing.hpp>
#include <mbgl/style/style_bucket_parameters.hpp>
#include <mbgl/renderer/fill_bucket.hpp>

namespace mbgl {

Expand Down Expand Up @@ -43,4 +45,14 @@ void FillLayer::recalculate(const StyleCalculationParameters& parameters) {
}
}

std::unique_ptr<Bucket> FillLayer::createBucket(StyleBucketParameters& parameters) const {
auto bucket = std::make_unique<FillBucket>();

parameters.eachFilteredFeature(filter, [&] (const auto& feature) {
bucket->addGeometry(feature.getGeometries());
});

return std::move(bucket);
}

}
2 changes: 2 additions & 0 deletions src/mbgl/layer/fill_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class FillLayer : public StyleLayer {

void recalculate(const StyleCalculationParameters&) override;

std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override;

FillPaintProperties properties;
};

Expand Down
19 changes: 19 additions & 0 deletions src/mbgl/layer/line_layer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <mbgl/layer/line_layer.hpp>
#include <mbgl/style/property_parsing.hpp>
#include <mbgl/style/style_bucket_parameters.hpp>
#include <mbgl/renderer/line_bucket.hpp>
#include <mbgl/map/tile_id.hpp>

namespace mbgl {
Expand Down Expand Up @@ -52,4 +54,21 @@ void LineLayer::recalculate(const StyleCalculationParameters& parameters) {
passes = properties.isVisible() ? RenderPass::Translucent : RenderPass::None;
}

std::unique_ptr<Bucket> LineLayer::createBucket(StyleBucketParameters& parameters) const {
auto bucket = std::make_unique<LineBucket>();

const float z = parameters.tileID.z;

layout.calculate(PropertyKey::LineCap, bucket->layout.cap, z);
layout.calculate(PropertyKey::LineJoin, bucket->layout.join, z);
layout.calculate(PropertyKey::LineMiterLimit, bucket->layout.miter_limit, z);
layout.calculate(PropertyKey::LineRoundLimit, bucket->layout.round_limit, z);

parameters.eachFilteredFeature(filter, [&] (const auto& feature) {
bucket->addGeometry(feature.getGeometries());
});

return std::move(bucket);
}

}
2 changes: 2 additions & 0 deletions src/mbgl/layer/line_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class LineLayer : public StyleLayer {

void recalculate(const StyleCalculationParameters&) override;

std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override;

LinePaintProperties properties;
};

Expand Down
5 changes: 5 additions & 0 deletions src/mbgl/layer/raster_layer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <mbgl/layer/raster_layer.hpp>
#include <mbgl/style/property_parsing.hpp>
#include <mbgl/renderer/bucket.hpp>

namespace mbgl {

Expand Down Expand Up @@ -35,4 +36,8 @@ void RasterLayer::recalculate(const StyleCalculationParameters& parameters) {
passes = properties.isVisible() ? RenderPass::Translucent : RenderPass::None;
}

std::unique_ptr<Bucket> RasterLayer::createBucket(StyleBucketParameters&) const {
return nullptr;
}

}
2 changes: 2 additions & 0 deletions src/mbgl/layer/raster_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class RasterLayer : public StyleLayer {

void recalculate(const StyleCalculationParameters&) override;

std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override;

RasterPaintProperties properties;
};

Expand Down
69 changes: 69 additions & 0 deletions src/mbgl/layer/symbol_layer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include <mbgl/layer/symbol_layer.hpp>
#include <mbgl/renderer/symbol_bucket.hpp>
#include <mbgl/map/tile_id.hpp>
#include <mbgl/style/property_evaluator.hpp>
#include <mbgl/style/property_parsing.hpp>
#include <mbgl/style/style_bucket_parameters.hpp>

namespace mbgl {

Expand Down Expand Up @@ -108,4 +111,70 @@ void SymbolLayer::recalculate(const StyleCalculationParameters& parameters) {
passes = properties.isVisible() ? RenderPass::Translucent : RenderPass::None;
}

std::unique_ptr<Bucket> SymbolLayer::createBucket(StyleBucketParameters& parameters) const {
const float z = parameters.tileID.z;
auto bucket = std::make_unique<SymbolBucket>(parameters.tileID.overscaling, z);

layout.calculate(PropertyKey::SymbolPlacement, bucket->layout.placement, z);
if (bucket->layout.placement == PlacementType::Line) {
bucket->layout.icon.rotation_alignment = RotationAlignmentType::Map;
bucket->layout.text.rotation_alignment = RotationAlignmentType::Map;
};
layout.calculate(PropertyKey::SymbolSpacing, bucket->layout.spacing, z);
layout.calculate(PropertyKey::SymbolAvoidEdges, bucket->layout.avoid_edges, z);

layout.calculate(PropertyKey::IconAllowOverlap, bucket->layout.icon.allow_overlap, z);
layout.calculate(PropertyKey::IconIgnorePlacement, bucket->layout.icon.ignore_placement, z);
layout.calculate(PropertyKey::IconOptional, bucket->layout.icon.optional, z);
layout.calculate(PropertyKey::IconRotationAlignment, bucket->layout.icon.rotation_alignment, z);
layout.calculate(PropertyKey::IconImage, bucket->layout.icon.image, z);
layout.calculate(PropertyKey::IconPadding, bucket->layout.icon.padding, z);
layout.calculate(PropertyKey::IconRotate, bucket->layout.icon.rotate, z);
layout.calculate(PropertyKey::IconKeepUpright, bucket->layout.icon.keep_upright, z);
layout.calculate(PropertyKey::IconOffset, bucket->layout.icon.offset, z);

layout.calculate(PropertyKey::TextRotationAlignment, bucket->layout.text.rotation_alignment, z);
layout.calculate(PropertyKey::TextField, bucket->layout.text.field, z);
layout.calculate(PropertyKey::TextFont, bucket->layout.text.font, z);
layout.calculate(PropertyKey::TextMaxWidth, bucket->layout.text.max_width, z);
layout.calculate(PropertyKey::TextLineHeight, bucket->layout.text.line_height, z);
layout.calculate(PropertyKey::TextLetterSpacing, bucket->layout.text.letter_spacing, z);
layout.calculate(PropertyKey::TextMaxAngle, bucket->layout.text.max_angle, z);
layout.calculate(PropertyKey::TextRotate, bucket->layout.text.rotate, z);
layout.calculate(PropertyKey::TextPadding, bucket->layout.text.padding, z);
layout.calculate(PropertyKey::TextIgnorePlacement, bucket->layout.text.ignore_placement, z);
layout.calculate(PropertyKey::TextOptional, bucket->layout.text.optional, z);
layout.calculate(PropertyKey::TextJustify, bucket->layout.text.justify, z);
layout.calculate(PropertyKey::TextAnchor, bucket->layout.text.anchor, z);
layout.calculate(PropertyKey::TextKeepUpright, bucket->layout.text.keep_upright, z);
layout.calculate(PropertyKey::TextTransform, bucket->layout.text.transform, z);
layout.calculate(PropertyKey::TextOffset, bucket->layout.text.offset, z);
layout.calculate(PropertyKey::TextAllowOverlap, bucket->layout.text.allow_overlap, z);

layout.calculate(PropertyKey::IconSize, bucket->layout.icon.size, z + 1);
layout.calculate(PropertyKey::IconSize, bucket->layout.icon.max_size, 18);
layout.calculate(PropertyKey::TextSize, bucket->layout.text.size, z + 1);
layout.calculate(PropertyKey::TextSize, bucket->layout.text.max_size, 18);

bucket->parseFeatures(parameters.layer, filter);

if (bucket->needsDependencies(parameters.glyphStore, parameters.sprite)) {
parameters.partialParse = true;
}

// We do not add features if the parser is in a "partial" state because
// the layer ordering needs to be respected when calculating text
// collisions. Although, at this point, we requested all the resources
// needed by this tile.
if (!parameters.partialParse) {
bucket->addFeatures(parameters.tileUID,
parameters.spriteAtlas,
parameters.glyphAtlas,
parameters.glyphStore,
parameters.collisionTile);
}

return std::move(bucket);
}

}
2 changes: 2 additions & 0 deletions src/mbgl/layer/symbol_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class SymbolLayer : public StyleLayer {

void recalculate(const StyleCalculationParameters&) override;

std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override;

SymbolPaintProperties properties;
};

Expand Down
Loading

0 comments on commit ca25594

Please sign in to comment.