add style object

This commit is contained in:
Konstantin Käfer
2014-01-23 15:33:00 +01:00
parent dba3be9829
commit d153bdeff4
9 changed files with 56 additions and 30 deletions

View File

@@ -6,6 +6,7 @@
#include "transform.hpp"
#include <llmr/map/tile.hpp>
#include "settings.hpp"
#include "../style/style.hpp"
#include <forward_list>
@@ -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;

View File

@@ -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<Bucket> createFillBucket(const pbf data);
@@ -72,8 +68,6 @@ public:
std::forward_list<Layer> layers;
// std::vector<fill_index> fillIndices;
private:
// Source data
uint8_t *data;

View File

@@ -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>& tile);
void renderBackground();
void renderFill(const FillBucket& bucket, const FillStyle& style);
void renderFill(const FillBucket& bucket, const FillProperties& style);
void drawClippingMask();

View File

@@ -2,6 +2,7 @@
#define LLMR_STYLE_STYLE
#include <array>
#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;
};
}

View File

@@ -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
)

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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

15
src/style/style.cpp Normal file
View File

@@ -0,0 +1,15 @@
#include <llmr/style/style.hpp>
using namespace llmr;
Style::Style() {
}
void Style::reset() {
}
void Style::load(pbf data) {
}