From d153bdeff459cf1acc9b76e894386a15e79a976f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 23 Jan 2014 15:33:00 +0100 Subject: [PATCH] add style object --- include/llmr/map/map.hpp | 3 +++ include/llmr/map/tile.hpp | 6 ------ include/llmr/renderer/painter.hpp | 4 ++-- include/llmr/style/style.hpp | 29 ++++++++++++++++++----------- src/CMakeLists.txt | 1 + src/map/map.cpp | 6 ++++++ src/renderer/fill_bucket.cpp | 8 ++++---- src/renderer/painter.cpp | 14 +++++++------- src/style/style.cpp | 15 +++++++++++++++ 9 files changed, 56 insertions(+), 30 deletions(-) create mode 100644 src/style/style.cpp diff --git a/include/llmr/map/map.hpp b/include/llmr/map/map.hpp index b5eef2487..d8babcef6 100644 --- a/include/llmr/map/map.hpp +++ b/include/llmr/map/map.hpp @@ -6,6 +6,7 @@ #include "transform.hpp" #include #include "settings.hpp" +#include "../style/style.hpp" #include @@ -24,6 +25,7 @@ public: Map &operator=(const Map&&) = delete; void setup(); + void loadStyle(const uint8_t *data, uint32_t bytes); void loadSettings(); void resize(uint32_t width, uint32_t height, uint32_t fb_width, uint32_t fb_height); @@ -59,6 +61,7 @@ private: Settings& settings; Transform transform; Painter painter; + Style style; int32_t min_zoom; int32_t max_zoom; diff --git a/include/llmr/map/tile.hpp b/include/llmr/map/tile.hpp index b1aac9a67..5cc806599 100644 --- a/include/llmr/map/tile.hpp +++ b/include/llmr/map/tile.hpp @@ -48,10 +48,6 @@ public: void setData(uint8_t *data, uint32_t bytes); bool parse(); void parseLayer(const pbf layer); - // void parseFeature(const uint8_t *data, uint32_t bytes); - - // void addLineGeometry(pbf& geom); - // void addFillGeometry(pbf& geom); std::shared_ptr createFillBucket(const pbf data); @@ -72,8 +68,6 @@ public: std::forward_list layers; - // std::vector fillIndices; - private: // Source data uint8_t *data; diff --git a/include/llmr/renderer/painter.hpp b/include/llmr/renderer/painter.hpp index b4c35e6dc..13d4017ef 100644 --- a/include/llmr/renderer/painter.hpp +++ b/include/llmr/renderer/painter.hpp @@ -13,7 +13,7 @@ class Settings; class Transform; class FillBucket; -struct FillStyle; +struct FillProperties; class Painter { public: @@ -34,7 +34,7 @@ public: void renderDebug(const std::shared_ptr& tile); void renderBackground(); - void renderFill(const FillBucket& bucket, const FillStyle& style); + void renderFill(const FillBucket& bucket, const FillProperties& style); void drawClippingMask(); diff --git a/include/llmr/style/style.hpp b/include/llmr/style/style.hpp index fd0e4a06e..6aea83d30 100644 --- a/include/llmr/style/style.hpp +++ b/include/llmr/style/style.hpp @@ -2,6 +2,7 @@ #define LLMR_STYLE_STYLE #include +#include "../util/pbf.hpp" namespace llmr { @@ -12,21 +13,22 @@ enum Winding { NonZero = 2 }; -enum LineCap { - Round = 1 -}; +// enum LineCap { +// Round = 1 +// }; -enum LineJoin { - Butt = 1, - Bevel = 2 -}; +// enum LineJoin { +// Butt = 1, +// Bevel = 2 +// }; -struct StrokeStyle { + +struct StrokeProperties { Color line_color = {{ 0, 0, 0, 1 }}; float line_width = 1; }; -struct FillStyle { +struct FillProperties { Winding winding = NonZero; bool antialiasing = true; Color fill_color = {{ 0, 0, 0, 1 }}; @@ -36,8 +38,13 @@ struct FillStyle { class Style { public: - StrokeStyle strokeStyle(const std::string& layer_name) const; - FillStyle fillStyle(const std::string& layer_name) const; + Style(); + + void reset(); + void load(pbf data); + + // StrokeStyle strokeStyle(const std::string& layer_name) const; + // FillProperties fillStyle(const std::string& layer_name) const; }; } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b4e355764..7593877d9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,7 @@ SET(llmr_SOURCES renderer/shader.cpp renderer/fill_bucket.cpp shader/shaders.cpp + style/style.cpp util/animation.cpp util/mat4.cpp ) diff --git a/src/map/map.cpp b/src/map/map.cpp index 913dd7e4a..8470af8a4 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -14,6 +14,7 @@ Map::Map(Settings& settings) : settings(settings), transform(), painter(transform, settings), + style(), min_zoom(0), max_zoom(14) { } @@ -25,6 +26,11 @@ void Map::setup() { painter.setup(); } +void Map::loadStyle(const uint8_t *data, uint32_t bytes) { + style.load(pbf(data, bytes)); + update(); +} + void Map::loadSettings() { transform.setAngle(settings.angle); transform.setScale(settings.scale); diff --git a/src/renderer/fill_bucket.cpp b/src/renderer/fill_bucket.cpp index 24de51df5..3af3495c9 100644 --- a/src/renderer/fill_bucket.cpp +++ b/src/renderer/fill_bucket.cpp @@ -91,9 +91,9 @@ void FillBucket::addGeometry(pbf& geom) { void FillBucket::render(Painter& painter) { // TODO: obtain the correct style information for this layer - FillStyle style; - style.fill_color = {{ 0, 0, 1, 0.5 }}; - style.stroke_color = style.fill_color; + FillProperties properties; + properties.fill_color = {{ 0, 0, 1, 0.5 }}; + properties.stroke_color = properties.fill_color; - painter.renderFill(*this, style); + painter.renderFill(*this, properties); } diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index 8f1d4f1c9..b1fd196d0 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -179,7 +179,7 @@ void Painter::render(const Tile::Ptr& tile) { renderBackground(); } -void Painter::renderFill(const FillBucket& bucket, const FillStyle& style) { +void Painter::renderFill(const FillBucket& bucket, const FillProperties& properties) { // Draw the stencil mask. { // We're only drawing to the first seven bits (== support a maximum of @@ -193,7 +193,7 @@ void Painter::renderFill(const FillBucket& bucket, const FillStyle& style) { // orientation, while all holes (see below) are in CW orientation. glStencilFunc(GL_NOTEQUAL, 0x80, 0x80); - if (style.winding == EvenOdd) { + if (properties.winding == EvenOdd) { // When we draw an even/odd winding fill, we just invert all the bits. glStencilOp(GL_INVERT, GL_KEEP, GL_KEEP); } else { @@ -234,17 +234,17 @@ void Painter::renderFill(const FillBucket& bucket, const FillStyle& style) { // Because we're drawing top-to-bottom, and we update the stencil mask // below, we have to draw the outline first (!) - if (style.antialiasing) { + if (properties.antialiasing) { switchShader(outlineShader); glUniformMatrix4fv(outlineShader->u_matrix, 1, GL_FALSE, matrix); glLineWidth(2); - if (style.stroke_color != style.fill_color) { + if (properties.stroke_color != properties.fill_color) { // If we defined a different color for the fill outline, we are // going to ignore the bits in 0x3F and just care about the global // clipping mask. glStencilFunc(GL_EQUAL, 0x80, 0x80); - glUniform4fv(outlineShader->u_color, 1, style.stroke_color.data()); + glUniform4fv(outlineShader->u_color, 1, properties.stroke_color.data()); } else { // Otherwise, we only want to draw the antialiased parts that are // *outside* the current shape. This is important in case the fill @@ -252,7 +252,7 @@ void Painter::renderFill(const FillBucket& bucket, const FillStyle& style) { // the current shape, some pixels from the outline stroke overlapped // the (non-antialiased) fill. glStencilFunc(GL_EQUAL, 0x80, 0xBF); - glUniform4fv(outlineShader->u_color, 1, style.fill_color.data()); + glUniform4fv(outlineShader->u_color, 1, properties.fill_color.data()); } glUniform2f(outlineShader->u_world, transform.fb_width, transform.fb_height); @@ -292,7 +292,7 @@ void Painter::renderFill(const FillBucket& bucket, const FillStyle& style) { // Draw filling rectangle. switchShader(fillShader); glUniformMatrix4fv(fillShader->u_matrix, 1, GL_FALSE, matrix); - glUniform4fv(fillShader->u_color, 1, style.fill_color.data()); + glUniform4fv(fillShader->u_color, 1, properties.fill_color.data()); } // Only draw regions that we marked diff --git a/src/style/style.cpp b/src/style/style.cpp new file mode 100644 index 000000000..a999289a0 --- /dev/null +++ b/src/style/style.cpp @@ -0,0 +1,15 @@ +#include + +using namespace llmr; + +Style::Style() { + +} + +void Style::reset() { + +} + +void Style::load(pbf data) { + +}