From f19d5c95dbc2784c53e47e869bef3bbde15c4c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Tue, 28 Jan 2014 14:09:07 +0100 Subject: [PATCH] rename stroke=>line, add line painter classes --- include/llmr/map/tile.hpp | 1 + include/llmr/renderer/bucket.hpp | 4 +-- include/llmr/renderer/fill_bucket.hpp | 4 +-- include/llmr/renderer/line_bucket.hpp | 29 ++++++++++++++++++ include/llmr/renderer/painter.hpp | 3 +- include/llmr/renderer/stroke_bucket.hpp | 27 ---------------- include/llmr/style/class_description.hpp | 2 +- include/llmr/style/properties.hpp | 8 ++--- include/llmr/style/style.hpp | 4 +-- src/CMakeLists.txt | 1 + src/map/tile.cpp | 39 ++++++++++++------------ src/renderer/line_bucket.cpp | 28 +++++++++++++++++ src/renderer/painter.cpp | 4 +++ src/style/style.cpp | 16 +++++----- 14 files changed, 104 insertions(+), 66 deletions(-) create mode 100644 include/llmr/renderer/line_bucket.hpp delete mode 100644 include/llmr/renderer/stroke_bucket.hpp create mode 100644 src/renderer/line_bucket.cpp diff --git a/include/llmr/map/tile.hpp b/include/llmr/map/tile.hpp index 05e872a0a..bd5d667f8 100644 --- a/include/llmr/map/tile.hpp +++ b/include/llmr/map/tile.hpp @@ -58,6 +58,7 @@ public: void parseStyleLayers(const std::vector& layers); std::shared_ptr createBucket(const BucketDescription& bucket_desc); std::shared_ptr createFillBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc); + std::shared_ptr createLineBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc); void cancel(); diff --git a/include/llmr/renderer/bucket.hpp b/include/llmr/renderer/bucket.hpp index 45d9574cc..95db9e017 100644 --- a/include/llmr/renderer/bucket.hpp +++ b/include/llmr/renderer/bucket.hpp @@ -1,5 +1,5 @@ -#ifndef LLMR_GEOMETRY_BUCKET -#define LLMR_GEOMETRY_BUCKET +#ifndef LLMR_RENDERER_BUCKET +#define LLMR_RENDERER_BUCKET #include diff --git a/include/llmr/renderer/fill_bucket.hpp b/include/llmr/renderer/fill_bucket.hpp index e90f51772..a64350a7e 100644 --- a/include/llmr/renderer/fill_bucket.hpp +++ b/include/llmr/renderer/fill_bucket.hpp @@ -1,5 +1,5 @@ -#ifndef LLMR_GEOMETRY_FILLBUCKET -#define LLMR_GEOMETRY_FILLBUCKET +#ifndef LLMR_RENDERER_FILLBUCKET +#define LLMR_RENDERER_FILLBUCKET #include "bucket.hpp" diff --git a/include/llmr/renderer/line_bucket.hpp b/include/llmr/renderer/line_bucket.hpp new file mode 100644 index 000000000..8feff69b3 --- /dev/null +++ b/include/llmr/renderer/line_bucket.hpp @@ -0,0 +1,29 @@ +#ifndef LLMR_RENDERER_LINEBUCKET +#define LLMR_RENDERER_LINEBUCKET + +#include "bucket.hpp" + +#include + +namespace llmr { + +class Style; +class LineBuffer; +struct pbf; + +class LineBucket : public Bucket { +public: + LineBucket(const std::shared_ptr& buffer); + + virtual void render(Painter& painter, const std::string& layer_name); + + void addGeometry(pbf& data); + +private: + std::shared_ptr buffer; + +}; + +} + +#endif diff --git a/include/llmr/renderer/painter.hpp b/include/llmr/renderer/painter.hpp index c2e7b8d61..a20f4f1db 100644 --- a/include/llmr/renderer/painter.hpp +++ b/include/llmr/renderer/painter.hpp @@ -15,7 +15,7 @@ class Style; class LayerDescription; class FillBucket; -struct FillProperties; +class LineBucket; class Painter { public: @@ -38,6 +38,7 @@ public: void renderBackground(); void renderFill(FillBucket& bucket, const std::string& layer_name); + void renderLine(LineBucket& bucket, const std::string& layer_name); void drawClippingMask(); diff --git a/include/llmr/renderer/stroke_bucket.hpp b/include/llmr/renderer/stroke_bucket.hpp deleted file mode 100644 index c9cb0fb56..000000000 --- a/include/llmr/renderer/stroke_bucket.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef LLMR_GEOMETRY_STROKEBUCKET -#define LLMR_GEOMETRY_STROKEBUCKET - -#include "bucket.hpp" - -#include - -namespace llmr { - -class Style; -class StrokeBuffer; - -class StrokeBucket : public Bucket { -public: - virtual void draw(const Style& style, const std::string& layerName); - -private: - std::shared_ptr buffer; - - // hold information on where the vertices are located in the StrokeBuffer - uint32_t vertex_start; - uint32_t length; -}; - -} - -#endif diff --git a/include/llmr/style/class_description.hpp b/include/llmr/style/class_description.hpp index 3130f8d78..ce5b172b2 100644 --- a/include/llmr/style/class_description.hpp +++ b/include/llmr/style/class_description.hpp @@ -11,7 +11,7 @@ namespace llmr { class ClassDescription { public: std::map fill; - std::map stroke; + std::map line; }; diff --git a/include/llmr/style/properties.hpp b/include/llmr/style/properties.hpp index 71b3b3aa9..5b4f7d627 100644 --- a/include/llmr/style/properties.hpp +++ b/include/llmr/style/properties.hpp @@ -53,16 +53,16 @@ struct FunctionProperty { }; -// StrokeClass is the information we parse from the stylesheet -struct StrokeClass { +// LineClass is the information we parse from the stylesheet +struct LineClass { FunctionProperty hidden; FunctionProperty width; FunctionProperty offset; Color color = {{ 0, 0, 0, 1 }}; }; -// StrokeProperties is the one we resolve this to. -struct StrokeProperties { +// LineProperties is the one we resolve this to. +struct LineProperties { bool hidden = false; float width = 0; float offset = 0; diff --git a/include/llmr/style/style.hpp b/include/llmr/style/style.hpp index a690a31e5..13cf18cb3 100644 --- a/include/llmr/style/style.hpp +++ b/include/llmr/style/style.hpp @@ -28,7 +28,7 @@ private: static LayerDescription parseLayer(pbf data); static std::pair parseClass(pbf data); static std::pair parseFillClass(pbf data); - static std::pair parseStrokeClass(pbf data); + static std::pair parseLineClass(pbf data); template static FunctionProperty parseProperty(pbf data); static Color parseColor(pbf& data); @@ -43,7 +43,7 @@ public: std::set appliedClasses; struct { std::map fills; - std::map strokes; + std::map lines; } computed; }; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 81d365733..cc1a52b77 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,7 @@ SET(llmr_SOURCES renderer/shader-outline.cpp renderer/shader.cpp renderer/fill_bucket.cpp + renderer/line_bucket.cpp resources/style.cpp shader/shaders.cpp style/style.cpp diff --git a/src/map/tile.cpp b/src/map/tile.cpp index 4bfd0b527..71b01d15b 100644 --- a/src/map/tile.cpp +++ b/src/map/tile.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -149,6 +150,8 @@ std::shared_ptr Tile::createBucket(const BucketDescription& bucket_desc) const VectorTileLayer& layer = layer_it->second; if (bucket_desc.type == BucketType::Fill) { return createFillBucket(layer, bucket_desc); + } else if (bucket_desc.type == BucketType::Line) { + return createLineBucket(layer, bucket_desc); } else { // TODO: create other bucket types. } @@ -159,13 +162,6 @@ std::shared_ptr Tile::createBucket(const BucketDescription& bucket_desc) return NULL; } -enum geom_type { - Unknown = 0, - Point = 1, - LineString = 2, - Polygon = 3 -}; - std::shared_ptr Tile::createFillBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc) { std::shared_ptr bucket = std::make_shared(fillBuffer); @@ -173,22 +169,27 @@ std::shared_ptr Tile::createFillBucket(const VectorTileLayer& layer, con for (pbf feature : filtered_layer) { while (feature.next(4)) { // geometry pbf geometry_pbf = feature.message(); - bucket->addGeometry(geometry_pbf); + if (geometry_pbf) { + bucket->addGeometry(geometry_pbf); + } } } return bucket; } -// void Tile::addLineGeometry(pbf& geom) { -// Geometry geometry(geom); +std::shared_ptr Tile::createLineBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc) { + std::shared_ptr bucket = std::make_shared(lineBuffer); -// Geometry::command cmd; -// int32_t x, y; -// while ((cmd = geometry.next(x, y)) != Geometry::end) { -// if (cmd == Geometry::move_to) { -// lineVertex.addDegenerate(); -// } -// lineVertex.addCoordinate(x, y); -// } -// } + FilteredVectorTileLayer filtered_layer(layer, bucket_desc); + for (pbf feature : filtered_layer) { + while (feature.next(4)) { // geometry + pbf geometry_pbf = feature.message(); + if (geometry_pbf) { + bucket->addGeometry(geometry_pbf); + } + } + } + + return bucket; +} diff --git a/src/renderer/line_bucket.cpp b/src/renderer/line_bucket.cpp new file mode 100644 index 000000000..b4efa2f0b --- /dev/null +++ b/src/renderer/line_bucket.cpp @@ -0,0 +1,28 @@ +#include +#include +#include + +#include +#include + +#include + +#define BUFFER_OFFSET(i) ((char *)NULL + (i)) + +#include + +struct geometry_too_long_exception : std::exception {}; + +using namespace llmr; + +LineBucket::LineBucket(const std::shared_ptr& buffer) + : buffer(buffer) { +} + +void LineBucket::addGeometry(pbf& geom) { + +} + +void LineBucket::render(Painter& painter, const std::string& layer_name) { + painter.renderLine(*this, layer_name); +} diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index 853ae5558..3323ddcbb 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -328,6 +328,10 @@ void Painter::renderFill(FillBucket& bucket, const std::string& layer_name) { glStencilFunc(GL_EQUAL, 0x80, 0x80); } +void Painter::renderLine(LineBucket& bucket, const std::string& layer_name) { + const LineProperties& properties = style.computed.lines[layer_name]; +} + void Painter::renderDebug(const Tile::Ptr& tile) { // Blend to the front, not the back. glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); diff --git a/src/style/style.cpp b/src/style/style.cpp index dc60d93a8..6e468962b 100644 --- a/src/style/style.cpp +++ b/src/style/style.cpp @@ -10,7 +10,7 @@ Style::Style() { void Style::reset() { computed.fills.clear(); - computed.strokes.clear(); + computed.lines.clear(); } void Style::load(const uint8_t *const data, uint32_t bytes) { @@ -91,7 +91,7 @@ std::pair Style::parseClass(pbf data) { } else if (data.tag == 2) { // fill_style klass.fill.insert(parseFillClass(data.message())); } else if (data.tag == 3) { // stroke_style - klass.stroke.insert(parseStrokeClass(data.message())); + klass.line.insert(parseLineClass(data.message())); } else { data.skip(); } @@ -131,8 +131,8 @@ std::pair Style::parseFillClass(pbf data) { } -std::pair Style::parseStrokeClass(pbf data) { - StrokeClass stroke; +std::pair Style::parseLineClass(pbf data) { + LineClass stroke; std::string name; while (data.next()) { @@ -216,11 +216,11 @@ void Style::cascade(float z) { } // Cascade line classes - for (const auto& stroke_pair : sheetClass.stroke) { - const std::string& layer_name = stroke_pair.first; - const llmr::StrokeClass& layer = stroke_pair.second; + for (const auto& line_pair : sheetClass.line) { + const std::string& layer_name = line_pair.first; + const llmr::LineClass& layer = line_pair.second; - llmr::StrokeProperties& stroke = computed.strokes[layer_name]; + llmr::LineProperties& stroke = computed.lines[layer_name]; stroke.hidden = layer.hidden(z); stroke.width = layer.width(z); stroke.offset = layer.offset(z);