diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-02-17 17:49:02 -0800 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-02-17 18:27:51 -0800 |
commit | 89c0ff5f3955ecd4316a7b4280e995b7b431817d (patch) | |
tree | 7ca855869e5d851ff2e8669c5526a5acab44bc97 /src/mbgl/renderer | |
parent | df23a6b7d7fc88ac90d0fe034a7e40c8aff928f8 (diff) | |
download | qtlocation-mapboxgl-89c0ff5f3955ecd4316a7b4280e995b7b431817d.tar.gz |
make StyleBucket mutable
refs #881
Diffstat (limited to 'src/mbgl/renderer')
-rw-r--r-- | src/mbgl/renderer/fill_bucket.cpp | 27 | ||||
-rw-r--r-- | src/mbgl/renderer/fill_bucket.hpp | 10 | ||||
-rw-r--r-- | src/mbgl/renderer/line_bucket.cpp | 16 | ||||
-rw-r--r-- | src/mbgl/renderer/line_bucket.hpp | 10 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_line.cpp | 7 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_symbol.cpp | 19 | ||||
-rw-r--r-- | src/mbgl/renderer/symbol_bucket.cpp | 10 | ||||
-rw-r--r-- | src/mbgl/renderer/symbol_bucket.hpp | 4 |
8 files changed, 58 insertions, 45 deletions
diff --git a/src/mbgl/renderer/fill_bucket.cpp b/src/mbgl/renderer/fill_bucket.cpp index b58e860b46..6544e43f09 100644 --- a/src/mbgl/renderer/fill_bucket.cpp +++ b/src/mbgl/renderer/fill_bucket.cpp @@ -31,18 +31,22 @@ void FillBucket::free(void *, void *ptr) { ::free(ptr); } -FillBucket::FillBucket(FillVertexBuffer &vertexBuffer_, +FillBucket::FillBucket(std::unique_ptr<const StyleBucketFill> layout_, + FillVertexBuffer &vertexBuffer_, TriangleElementsBuffer &triangleElementsBuffer_, - LineElementsBuffer &lineElementsBuffer_, - const StyleBucketFill &properties_) - : properties(properties_), - allocator(new TESSalloc{&alloc, &realloc, &free, nullptr, // userData - 64, // meshEdgeBucketSize - 64, // meshVertexBucketSize - 32, // meshFaceBucketSize - 64, // dictNodeBucketSize - 8, // regionBucketSize - 128, // extraVertices allocated for the priority queue. + LineElementsBuffer &lineElementsBuffer_) + : layout(std::move(layout_)), + allocator(new TESSalloc{ + &alloc, + &realloc, + &free, + nullptr, // userData + 64, // meshEdgeBucketSize + 64, // meshVertexBucketSize + 32, // meshFaceBucketSize + 64, // dictNodeBucketSize + 8, // regionBucketSize + 128, // extraVertices allocated for the priority queue. }), tesselator(tessNewTess(allocator)), vertexBuffer(vertexBuffer_), @@ -52,6 +56,7 @@ FillBucket::FillBucket(FillVertexBuffer &vertexBuffer_, triangle_elements_start(triangleElementsBuffer_.index()), line_elements_start(lineElementsBuffer.index()) { assert(tesselator); + assert(layout); } FillBucket::~FillBucket() { diff --git a/src/mbgl/renderer/fill_bucket.hpp b/src/mbgl/renderer/fill_bucket.hpp index e9762b7628..06ac5cc29d 100644 --- a/src/mbgl/renderer/fill_bucket.hpp +++ b/src/mbgl/renderer/fill_bucket.hpp @@ -38,10 +38,10 @@ class FillBucket : public Bucket { typedef ElementGroup<1> line_group_type; public: - FillBucket(FillVertexBuffer& vertexBuffer, - TriangleElementsBuffer& triangleElementsBuffer, - LineElementsBuffer& lineElementsBuffer, - const StyleBucketFill& properties); + FillBucket(std::unique_ptr<const StyleBucketFill> layout, + FillVertexBuffer &vertexBuffer, + TriangleElementsBuffer &triangleElementsBuffer, + LineElementsBuffer &lineElementsBuffer); ~FillBucket(); virtual void render(Painter& painter, util::ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); @@ -55,7 +55,7 @@ public: void drawVertices(OutlineShader& shader); public: - const StyleBucketFill &properties; + const std::unique_ptr<const StyleBucketFill> layout; private: TESSalloc *allocator; diff --git a/src/mbgl/renderer/line_bucket.cpp b/src/mbgl/renderer/line_bucket.cpp index 8141e68e24..106ea3e112 100644 --- a/src/mbgl/renderer/line_bucket.cpp +++ b/src/mbgl/renderer/line_bucket.cpp @@ -18,18 +18,18 @@ struct geometry_too_long_exception : std::exception {}; using namespace mbgl; -LineBucket::LineBucket(LineVertexBuffer& vertexBuffer_, - TriangleElementsBuffer& triangleElementsBuffer_, - PointElementsBuffer& pointElementsBuffer_, - const StyleBucketLine& properties_) - : properties(properties_), +LineBucket::LineBucket(std::unique_ptr<const StyleBucketLine> layout_, + LineVertexBuffer &vertexBuffer_, + TriangleElementsBuffer &triangleElementsBuffer_, + PointElementsBuffer &pointElementsBuffer_) + : layout(std::move(layout_)), vertexBuffer(vertexBuffer_), triangleElementsBuffer(triangleElementsBuffer_), pointElementsBuffer(pointElementsBuffer_), vertex_start(vertexBuffer_.index()), triangle_elements_start(triangleElementsBuffer_.index()), - point_elements_start(pointElementsBuffer_.index()) -{ + point_elements_start(pointElementsBuffer_.index()) { + assert(layout); } void LineBucket::addGeometry(pbf& geom) { @@ -61,6 +61,8 @@ struct TriangleElement { typedef uint16_t PointElement; void LineBucket::addGeometry(const std::vector<Coordinate>& vertices) { + assert(layout); + auto &properties = *layout; // TODO: use roundLimit // const float roundLimit = geometry.round_limit; diff --git a/src/mbgl/renderer/line_bucket.hpp b/src/mbgl/renderer/line_bucket.hpp index 3bc8bf399d..271d950223 100644 --- a/src/mbgl/renderer/line_bucket.hpp +++ b/src/mbgl/renderer/line_bucket.hpp @@ -25,10 +25,10 @@ class LineBucket : public Bucket { typedef ElementGroup<1> point_group_type; public: - LineBucket(LineVertexBuffer& vertexBuffer, - TriangleElementsBuffer& triangleElementsBuffer, - PointElementsBuffer& pointElementsBuffer, - const StyleBucketLine& properties); + LineBucket(std::unique_ptr<const StyleBucketLine> layout, + LineVertexBuffer &vertexBuffer, + TriangleElementsBuffer &triangleElementsBuffer, + PointElementsBuffer &pointElementsBuffer); virtual void render(Painter& painter, util::ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); virtual bool hasData() const; @@ -44,7 +44,7 @@ public: void drawPoints(LinejoinShader& shader); public: - const StyleBucketLine &properties; + const std::unique_ptr<const StyleBucketLine> layout; private: LineVertexBuffer& vertexBuffer; diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index a66da1fcd6..2bdfb26a47 100644 --- a/src/mbgl/renderer/painter_line.cpp +++ b/src/mbgl/renderer/painter_line.cpp @@ -14,7 +14,8 @@ void Painter::renderLine(LineBucket& bucket, util::ptr<StyleLayer> layer_desc, c if (pass == RenderPass::Opaque) return; if (!bucket.hasData()) return; - const LineProperties &properties = layer_desc->getProperties<LineProperties>(); + const auto &properties = layer_desc->getProperties<LineProperties>(); + const auto &layout = *bucket.layout; // the distance over which the line edge fades out. // Retina devices need a smaller distance to avoid aliasing. @@ -81,8 +82,8 @@ void Painter::renderLine(LineBucket& bucket, util::ptr<StyleLayer> layer_desc, c linesdfShader->u_blur = blur; linesdfShader->u_color = color; - LinePatternPos posA = lineAtlas.getDashPosition(properties.dash_array.from, bucket.properties.cap == CapType::Round); - LinePatternPos posB = lineAtlas.getDashPosition(properties.dash_array.to, bucket.properties.cap == CapType::Round); + LinePatternPos posA = lineAtlas.getDashPosition(properties.dash_array.from, layout.cap == CapType::Round); + LinePatternPos posB = lineAtlas.getDashPosition(properties.dash_array.to, layout.cap == CapType::Round); lineAtlas.bind(); float patternratio = std::pow(2.0, std::floor(std::log2(state.getScale())) - id.z) / 8.0; diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp index 579a6d2e06..fb0dd9fbf2 100644 --- a/src/mbgl/renderer/painter_symbol.cpp +++ b/src/mbgl/renderer/painter_symbol.cpp @@ -117,7 +117,8 @@ void Painter::renderSymbol(SymbolBucket &bucket, util::ptr<StyleLayer> layer_des return; } - const SymbolProperties &properties = layer_desc->getProperties<SymbolProperties>(); + const auto &properties = layer_desc->getProperties<SymbolProperties>(); + const auto &layout = *bucket.layout; MBGL_CHECK_ERROR(glDisable(GL_STENCIL_TEST)); @@ -125,21 +126,21 @@ void Painter::renderSymbol(SymbolBucket &bucket, util::ptr<StyleLayer> layer_des bool sdf = bucket.sdfIcons; const float angleOffset = - bucket.properties.icon.rotation_alignment == RotationAlignmentType::Map + layout.icon.rotation_alignment == RotationAlignmentType::Map ? state.getAngle() : 0; // If layerStyle.size > bucket.info.fontSize then labels may collide - const float fontSize = properties.icon.size != 0 ? properties.icon.size : bucket.properties.icon.max_size; + const float fontSize = properties.icon.size != 0 ? properties.icon.size : layout.icon.max_size; const float fontScale = fontSize / 1.0f; - spriteAtlas.bind(state.isChanging() || bucket.properties.placement == PlacementType::Line || angleOffset != 0 || fontScale != 1 || sdf); + spriteAtlas.bind(state.isChanging() || layout.placement == PlacementType::Line || angleOffset != 0 || fontScale != 1 || sdf); if (sdf) { renderSDF(bucket, id, matrix, - bucket.properties.icon, + layout.icon, properties.icon, 1.0f, {{ float(spriteAtlas.getWidth()) / 4.0f, float(spriteAtlas.getHeight()) / 4.0f }}, @@ -166,12 +167,12 @@ void Painter::renderSymbol(SymbolBucket &bucket, util::ptr<StyleLayer> layer_des const float angle = std::round(state.getAngle() / M_PI * 128); // adjust min/max zooms for variable font sies - float zoomAdjust = std::log(fontSize / bucket.properties.icon.max_size) / std::log(2); + float zoomAdjust = std::log(fontSize / layout.icon.max_size) / std::log(2); iconShader->u_angle = (int32_t)(angle + 256) % 256; - bool flip = (bucket.properties.icon.rotation_alignment == RotationAlignmentType::Map) - && bucket.properties.icon.keep_upright; + bool flip = (layout.icon.rotation_alignment == RotationAlignmentType::Map) + && layout.icon.keep_upright; iconShader->u_flip = flip ? 1 : 0; iconShader->u_zoom = (state.getNormalizedZoom() - zoomAdjust) * 10; // current zoom level @@ -192,7 +193,7 @@ void Painter::renderSymbol(SymbolBucket &bucket, util::ptr<StyleLayer> layer_des renderSDF(bucket, id, matrix, - bucket.properties.text, + layout.text, properties.text, 24.0f, {{ float(glyphAtlas.width) / 4, float(glyphAtlas.height) / 4 }}, diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp index 44cc3816a3..27a7c8e351 100644 --- a/src/mbgl/renderer/symbol_bucket.cpp +++ b/src/mbgl/renderer/symbol_bucket.cpp @@ -20,8 +20,10 @@ namespace mbgl { -SymbolBucket::SymbolBucket(const StyleBucketSymbol &properties_, Collision &collision_) - : properties(properties_), collision(collision_) {} +SymbolBucket::SymbolBucket(std::unique_ptr<const StyleBucketSymbol> layout_, Collision &collision_) + : layout(std::move(layout_)), collision(collision_) { + assert(layout); +} void SymbolBucket::render(Painter &painter, util::ptr<StyleLayer> layer_desc, const Tile::ID &id, const mat4 &matrix) { @@ -44,6 +46,7 @@ std::vector<SymbolFeature> SymbolBucket::processFeatures(const VectorTileLayer & const FilterExpression &filter, GlyphStore &glyphStore, const Sprite &sprite) { + auto &properties = *layout; const bool has_text = properties.text.field.size(); const bool has_icon = properties.icon.image.size(); @@ -120,7 +123,7 @@ std::vector<SymbolFeature> SymbolBucket::processFeatures(const VectorTileLayer & void SymbolBucket::addFeatures(const VectorTileLayer &layer, const FilterExpression &filter, const Tile::ID &id, SpriteAtlas &spriteAtlas, Sprite &sprite, GlyphAtlas & glyphAtlas, GlyphStore &glyphStore) { - + auto &properties = *layout; const std::vector<SymbolFeature> features = processFeatures(layer, filter, glyphStore, sprite); float horizontalAlign = 0.5; @@ -220,6 +223,7 @@ const PlacementRange fullRange{{2 * M_PI, 0}}; void SymbolBucket::addFeature(const std::vector<Coordinate> &line, const Shaping &shaping, const GlyphPositions &face, const Rect<uint16_t> &image) { assert(line.size()); + auto &properties = *layout; const float minScale = 0.5f; const float glyphSize = 24.0f; diff --git a/src/mbgl/renderer/symbol_bucket.hpp b/src/mbgl/renderer/symbol_bucket.hpp index 537c6d2097..5b3ea092af 100644 --- a/src/mbgl/renderer/symbol_bucket.hpp +++ b/src/mbgl/renderer/symbol_bucket.hpp @@ -54,7 +54,7 @@ class SymbolBucket : public Bucket { typedef ElementGroup<2> IconElementGroup; public: - SymbolBucket(const StyleBucketSymbol &properties, Collision &collision); + SymbolBucket(std::unique_ptr<const StyleBucketSymbol> layout, Collision &collision); virtual void render(Painter &painter, util::ptr<StyleLayer> layer_desc, const Tile::ID &id, const mat4 &matrix); virtual bool hasData() const; @@ -89,7 +89,7 @@ private: const FontStack &fontStack, GlyphAtlas &glyphAtlas, GlyphPositions &face); public: - const StyleBucketSymbol &properties; + const std::unique_ptr<const StyleBucketSymbol> layout; bool sdfIcons = false; private: |