diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-03-11 12:55:04 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-03-14 11:36:10 +0100 |
commit | f8a096a4fa720e0573b1c22d471d34a976383248 (patch) | |
tree | 68abfff355fa765d4b10291f76b99a62de961a20 | |
parent | f0b821dff9cc0e74744640e5069e67e01909c59d (diff) | |
download | qtlocation-mapboxgl-f8a096a4fa720e0573b1c22d471d34a976383248.tar.gz |
use templated function to reduce code
-rw-r--r-- | include/llmr/map/tile_data.hpp | 1 | ||||
-rw-r--r-- | src/map/tile_data.cpp | 46 | ||||
-rw-r--r-- | src/renderer/fill_bucket.cpp | 2 |
3 files changed, 15 insertions, 34 deletions
diff --git a/include/llmr/map/tile_data.hpp b/include/llmr/map/tile_data.hpp index 98709ad322..e8cbb6793f 100644 --- a/include/llmr/map/tile_data.hpp +++ b/include/llmr/map/tile_data.hpp @@ -62,6 +62,7 @@ public: bool parse(); void parseStyleLayers(const VectorTile& tile, const std::vector<LayerDescription>& layers); std::shared_ptr<Bucket> createBucket(const VectorTile& tile, const BucketDescription& bucket_desc); + template <class Bucket> void addBucketFeatures(Bucket& bucket, const VectorTileLayer& layer, const BucketDescription& bucket_desc); std::shared_ptr<Bucket> createFillBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc); std::shared_ptr<Bucket> createLineBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc); std::shared_ptr<Bucket> createPointBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc); diff --git a/src/map/tile_data.cpp b/src/map/tile_data.cpp index d62b323dbd..16c1e461f8 100644 --- a/src/map/tile_data.cpp +++ b/src/map/tile_data.cpp @@ -162,57 +162,35 @@ std::shared_ptr<Bucket> TileData::createBucket(const VectorTile& tile, const Buc return nullptr; } -std::shared_ptr<Bucket> TileData::createFillBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc) { - std::shared_ptr<FillBucket> bucket = std::make_shared<FillBucket>(fillVertexBuffer, triangleElementsBuffer, lineElementsBuffer, bucket_desc); - +template <class Bucket> +void TileData::addBucketFeatures(Bucket& bucket, const VectorTileLayer& layer, const BucketDescription& bucket_desc) { FilteredVectorTileLayer filtered_layer(layer, bucket_desc); for (pbf feature : filtered_layer) { - if (state == State::obsolete) return nullptr; + if (state == State::obsolete) return; while (feature.next(4)) { // geometry pbf geometry_pbf = feature.message(); if (geometry_pbf) { bucket->addGeometry(geometry_pbf); - bucket->tessellate(); } } } +} - return bucket; +std::shared_ptr<Bucket> TileData::createFillBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc) { + std::shared_ptr<FillBucket> bucket = std::make_shared<FillBucket>(fillVertexBuffer, triangleElementsBuffer, lineElementsBuffer, bucket_desc); + addBucketFeatures(bucket, layer, bucket_desc); + return state == State::obsolete ? nullptr : bucket; } std::shared_ptr<Bucket> TileData::createLineBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc) { std::shared_ptr<LineBucket> bucket = std::make_shared<LineBucket>(lineVertexBuffer, triangleElementsBuffer, pointElementsBuffer, bucket_desc); - - FilteredVectorTileLayer filtered_layer(layer, bucket_desc); - for (pbf feature : filtered_layer) { - if (state == State::obsolete) return nullptr; - - while (feature.next(4)) { // geometry - pbf geometry_pbf = feature.message(); - if (geometry_pbf) { - bucket->addGeometry(geometry_pbf); - } - } - } - - return bucket; + addBucketFeatures(bucket, layer, bucket_desc); + return state == State::obsolete ? nullptr : bucket; } std::shared_ptr<Bucket> TileData::createPointBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc) { std::shared_ptr<PointBucket> bucket = std::make_shared<PointBucket>(pointVertexBuffer, bucket_desc); - - FilteredVectorTileLayer filtered_layer(layer, bucket_desc); - for (pbf feature : filtered_layer) { - if (state == State::obsolete) return nullptr; - - while (feature.next(4)) { // geometry - pbf geometry_pbf = feature.message(); - if (geometry_pbf) { - bucket->addGeometry(geometry_pbf); - } - } - } - - return bucket; + addBucketFeatures(bucket, layer, bucket_desc); + return state == State::obsolete ? nullptr : bucket; } diff --git a/src/renderer/fill_bucket.cpp b/src/renderer/fill_bucket.cpp index f1d699214d..92d654d14d 100644 --- a/src/renderer/fill_bucket.cpp +++ b/src/renderer/fill_bucket.cpp @@ -88,6 +88,8 @@ void FillBucket::addGeometry(pbf& geom) { line.clear(); hasVertices = true; } + + tessellate(); } void FillBucket::tessellate() { |