rename stroke=>line, add line painter classes

This commit is contained in:
Konstantin Käfer
2014-01-28 14:09:07 +01:00
parent 31fca20c16
commit f19d5c95db
14 changed files with 104 additions and 66 deletions

View File

@@ -58,6 +58,7 @@ public:
void parseStyleLayers(const std::vector<LayerDescription>& layers);
std::shared_ptr<Bucket> createBucket(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);
void cancel();

View File

@@ -1,5 +1,5 @@
#ifndef LLMR_GEOMETRY_BUCKET
#define LLMR_GEOMETRY_BUCKET
#ifndef LLMR_RENDERER_BUCKET
#define LLMR_RENDERER_BUCKET
#include <string>

View File

@@ -1,5 +1,5 @@
#ifndef LLMR_GEOMETRY_FILLBUCKET
#define LLMR_GEOMETRY_FILLBUCKET
#ifndef LLMR_RENDERER_FILLBUCKET
#define LLMR_RENDERER_FILLBUCKET
#include "bucket.hpp"

View File

@@ -0,0 +1,29 @@
#ifndef LLMR_RENDERER_LINEBUCKET
#define LLMR_RENDERER_LINEBUCKET
#include "bucket.hpp"
#include <vector>
namespace llmr {
class Style;
class LineBuffer;
struct pbf;
class LineBucket : public Bucket {
public:
LineBucket(const std::shared_ptr<LineBuffer>& buffer);
virtual void render(Painter& painter, const std::string& layer_name);
void addGeometry(pbf& data);
private:
std::shared_ptr<LineBuffer> buffer;
};
}
#endif

View File

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

View File

@@ -1,27 +0,0 @@
#ifndef LLMR_GEOMETRY_STROKEBUCKET
#define LLMR_GEOMETRY_STROKEBUCKET
#include "bucket.hpp"
#include <string>
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<StrokeBuffer> buffer;
// hold information on where the vertices are located in the StrokeBuffer
uint32_t vertex_start;
uint32_t length;
};
}
#endif

View File

@@ -11,7 +11,7 @@ namespace llmr {
class ClassDescription {
public:
std::map<std::string, FillClass> fill;
std::map<std::string, StrokeClass> stroke;
std::map<std::string, LineClass> line;
};

View File

@@ -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<bool> hidden;
FunctionProperty<float> width;
FunctionProperty<float> 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;

View File

@@ -28,7 +28,7 @@ private:
static LayerDescription parseLayer(pbf data);
static std::pair<std::string, ClassDescription> parseClass(pbf data);
static std::pair<std::string, FillClass> parseFillClass(pbf data);
static std::pair<std::string, StrokeClass> parseStrokeClass(pbf data);
static std::pair<std::string, LineClass> parseLineClass(pbf data);
template <typename T> static FunctionProperty<T> parseProperty(pbf data);
static Color parseColor(pbf& data);
@@ -43,7 +43,7 @@ public:
std::set<std::string> appliedClasses;
struct {
std::map<std::string, FillProperties> fills;
std::map<std::string, StrokeProperties> strokes;
std::map<std::string, LineProperties> lines;
} computed;
};

View File

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

View File

@@ -9,6 +9,7 @@
#include <llmr/util/string.hpp>
#include <llmr/geometry/geometry.hpp>
#include <llmr/renderer/fill_bucket.hpp>
#include <llmr/renderer/line_bucket.hpp>
#include <llmr/style/style.hpp>
#include <cmath>
@@ -149,6 +150,8 @@ std::shared_ptr<Bucket> 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<Bucket> Tile::createBucket(const BucketDescription& bucket_desc)
return NULL;
}
enum geom_type {
Unknown = 0,
Point = 1,
LineString = 2,
Polygon = 3
};
std::shared_ptr<Bucket> Tile::createFillBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc) {
std::shared_ptr<FillBucket> bucket = std::make_shared<FillBucket>(fillBuffer);
@@ -173,22 +169,27 @@ std::shared_ptr<Bucket> 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<Bucket> Tile::createLineBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc) {
std::shared_ptr<LineBucket> bucket = std::make_shared<LineBucket>(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;
}

View File

@@ -0,0 +1,28 @@
#include <llmr/renderer/line_bucket.hpp>
#include <llmr/geometry/line_buffer.hpp>
#include <llmr/geometry/geometry.hpp>
#include <llmr/renderer/painter.hpp>
#include <llmr/style/style.hpp>
#include <llmr/platform/gl.hpp>
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
#include <cassert>
struct geometry_too_long_exception : std::exception {};
using namespace llmr;
LineBucket::LineBucket(const std::shared_ptr<LineBuffer>& buffer)
: buffer(buffer) {
}
void LineBucket::addGeometry(pbf& geom) {
}
void LineBucket::render(Painter& painter, const std::string& layer_name) {
painter.renderLine(*this, layer_name);
}

View File

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

View File

@@ -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<std::string, ClassDescription> 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<std::string, FillClass> Style::parseFillClass(pbf data) {
}
std::pair<std::string, StrokeClass> Style::parseStrokeClass(pbf data) {
StrokeClass stroke;
std::pair<std::string, LineClass> 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);