break out StyleSource from Source, move getActiveSources and
updateSources into Map::Map, move getAccessToken from Style to Map Conflicts: include/llmr/style/style.hpp src/map/source.cpp src/style/style_layer.cpp src/style/style_parser.cpp
This commit is contained in:
@@ -52,6 +52,7 @@ public:
|
||||
void resize(uint16_t width, uint16_t height, float ratio, uint16_t fb_width, uint16_t fb_height);
|
||||
|
||||
// Styling
|
||||
const std::set<std::shared_ptr<Source>> getActiveSources() const;
|
||||
void setAppliedClasses(const std::vector<std::string> &classes);
|
||||
void toggleClass(const std::string &name);
|
||||
const std::vector<std::string> &getAppliedClasses() const;
|
||||
@@ -123,6 +124,9 @@ private:
|
||||
// Setup
|
||||
void setup();
|
||||
|
||||
void updateSources();
|
||||
void updateSources(const std::shared_ptr<StyleLayerGroup> &group);
|
||||
|
||||
void updateTiles();
|
||||
void updateRenderState();
|
||||
|
||||
@@ -175,6 +179,8 @@ private:
|
||||
|
||||
int indent = 0;
|
||||
|
||||
std::set<std::shared_ptr<Source>> activeSources;
|
||||
|
||||
private:
|
||||
bool async = false;
|
||||
std::shared_ptr<uv::loop> loop;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <llmr/map/tile_data.hpp>
|
||||
#include <llmr/util/noncopyable.hpp>
|
||||
#include <llmr/util/time.hpp>
|
||||
#include <llmr/style/style_source.hpp>
|
||||
#include <llmr/style/types.hpp>
|
||||
|
||||
#include <list>
|
||||
@@ -22,6 +23,7 @@ class Texturepool;
|
||||
|
||||
class Source : public std::enable_shared_from_this<Source>, private util::noncopyable {
|
||||
public:
|
||||
Source(StyleSource style_source, const std::string &access_token = "");
|
||||
Source(SourceType type = SourceType::Vector, const std::string &url = "",
|
||||
uint32_t tile_size = 512, uint32_t min_zoom = 0, uint32_t max_zoom = 22,
|
||||
const std::string &access_token = "");
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define LLMR_STYLE_STYLE
|
||||
|
||||
#include <llmr/style/property_transition.hpp>
|
||||
#include <llmr/style/style_source.hpp>
|
||||
|
||||
#include <llmr/util/time.hpp>
|
||||
#include <llmr/util/uv.hpp>
|
||||
@@ -16,9 +17,7 @@
|
||||
|
||||
namespace llmr {
|
||||
|
||||
class Map;
|
||||
class Sprite;
|
||||
class Source;
|
||||
class StyleLayer;
|
||||
class StyleLayerGroup;
|
||||
struct BackgroundProperties;
|
||||
@@ -28,7 +27,7 @@ public:
|
||||
struct exception : std::runtime_error { exception(const char *msg) : std::runtime_error(msg) {} };
|
||||
|
||||
public:
|
||||
Style(Map &map);
|
||||
Style();
|
||||
|
||||
void loadJSON(const uint8_t *const data);
|
||||
|
||||
@@ -37,8 +36,6 @@ public:
|
||||
|
||||
void setDefaultTransitionDuration(uint16_t duration_milliseconds = 0);
|
||||
|
||||
const std::set<std::shared_ptr<Source>> getActiveSources() const;
|
||||
|
||||
void setAppliedClasses(const std::vector<std::string> &classes);
|
||||
const std::vector<std::string> &getAppliedClasses() const;
|
||||
void toggleClass(const std::string &name);
|
||||
@@ -58,14 +55,8 @@ public:
|
||||
std::string sprite_url;
|
||||
std::string glyph_url;
|
||||
|
||||
private:
|
||||
void updateSources();
|
||||
void updateSources(const std::shared_ptr<StyleLayerGroup> &group);
|
||||
|
||||
|
||||
private:
|
||||
Map ↦
|
||||
std::set<std::shared_ptr<Source>> activeSources;
|
||||
PropertyTransition defaultTransition;
|
||||
bool initial_render_complete = false;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <llmr/style/types.hpp>
|
||||
#include <llmr/style/filter_expression.hpp>
|
||||
#include <llmr/style/style_source.hpp>
|
||||
#include <llmr/util/vec.hpp>
|
||||
#include <llmr/util/variant.hpp>
|
||||
|
||||
@@ -11,8 +12,6 @@
|
||||
|
||||
namespace llmr {
|
||||
|
||||
class Source;
|
||||
|
||||
class StyleBucketFill {
|
||||
public:
|
||||
WindingType winding = WindingType::Default;
|
||||
@@ -74,7 +73,7 @@ public:
|
||||
StyleBucket(StyleLayerType type);
|
||||
|
||||
std::string name;
|
||||
std::shared_ptr<Source> source;
|
||||
std::shared_ptr<StyleSource> style_source;
|
||||
std::string source_layer;
|
||||
FilterExpression filter;
|
||||
StyleBucketRender render = std::false_type();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <rapidjson/document.h>
|
||||
#include <llmr/style/style.hpp>
|
||||
#include <llmr/map/source.hpp>
|
||||
#include <llmr/style/style_source.hpp>
|
||||
#include <llmr/style/filter_expression.hpp>
|
||||
#include <llmr/style/class_properties.hpp>
|
||||
#include <llmr/style/rasterize_properties.hpp>
|
||||
@@ -17,7 +17,6 @@ namespace llmr {
|
||||
|
||||
enum class ClassID : uint32_t;
|
||||
|
||||
class Map;
|
||||
class StyleLayer;
|
||||
class StyleLayerGroup;
|
||||
|
||||
@@ -25,7 +24,7 @@ class StyleParser {
|
||||
public:
|
||||
using JSVal = const rapidjson::Value&;
|
||||
|
||||
StyleParser(Map &map);
|
||||
StyleParser();
|
||||
|
||||
void parse(JSVal document);
|
||||
|
||||
@@ -95,11 +94,9 @@ private:
|
||||
std::forward_list<Value> parseValues(JSVal values);
|
||||
|
||||
private:
|
||||
Map ↦
|
||||
|
||||
std::unordered_map<std::string, const rapidjson::Value *> constants;
|
||||
|
||||
std::unordered_map<std::string, const std::shared_ptr<Source>> sources;
|
||||
std::unordered_map<std::string, const std::shared_ptr<StyleSource>> sources;
|
||||
|
||||
// This stores the root layer.
|
||||
std::shared_ptr<StyleLayerGroup> root;
|
||||
|
||||
27
include/llmr/style/style_source.hpp
Normal file
27
include/llmr/style/style_source.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef LLMR_STYLE_STYLE_SOURCE
|
||||
#define LLMR_STYLE_STYLE_SOURCE
|
||||
|
||||
#include <llmr/style/types.hpp>
|
||||
|
||||
namespace llmr {
|
||||
|
||||
struct StyleSource {
|
||||
const SourceType type;
|
||||
const std::string url;
|
||||
const uint32_t tile_size;
|
||||
const int32_t min_zoom;
|
||||
const int32_t max_zoom;
|
||||
|
||||
StyleSource(SourceType type = SourceType::Vector,
|
||||
const std::string &url = "",
|
||||
uint32_t tile_size = 512, uint32_t min_zoom = 0,
|
||||
uint32_t max_zoom = 22)
|
||||
: type(type),
|
||||
url(url),
|
||||
tile_size(tile_size),
|
||||
min_zoom(min_zoom),
|
||||
max_zoom(max_zoom) {}
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -22,7 +22,7 @@ using namespace llmr;
|
||||
Map::Map(View& view)
|
||||
: view(view),
|
||||
transform(),
|
||||
style(std::make_shared<Style>(*this)),
|
||||
style(std::make_shared<Style>()),
|
||||
glyphAtlas(std::make_shared<GlyphAtlas>(1024, 1024)),
|
||||
spriteAtlas(std::make_shared<SpriteAtlas>(512, 512)),
|
||||
texturepool(std::make_shared<Texturepool>()),
|
||||
@@ -413,8 +413,33 @@ void Map::setDefaultTransitionDuration(uint64_t duration_milliseconds) {
|
||||
style->setDefaultTransitionDuration(duration_milliseconds);
|
||||
}
|
||||
|
||||
void Map::updateSources() {
|
||||
activeSources.clear();
|
||||
updateSources(style->layers);
|
||||
}
|
||||
|
||||
const std::set<std::shared_ptr<Source>> Map::getActiveSources() const {
|
||||
return activeSources;
|
||||
}
|
||||
|
||||
void Map::updateSources(const std::shared_ptr<StyleLayerGroup> &group) {
|
||||
if (!group) {
|
||||
return;
|
||||
}
|
||||
for (const std::shared_ptr<StyleLayer> &layer : group->layers) {
|
||||
if (!layer) continue;
|
||||
if (layer->bucket) {
|
||||
if (layer->bucket->style_source) {
|
||||
activeSources.emplace(std::make_shared<Source>(*layer->bucket->style_source, this->getAccessToken()));
|
||||
}
|
||||
} else if (layer->layers) {
|
||||
updateSources(layer->layers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Map::updateTiles() {
|
||||
for (const std::shared_ptr<Source> &source : style->getActiveSources()) {
|
||||
for (const std::shared_ptr<Source> &source : getActiveSources()) {
|
||||
source->update(*this);
|
||||
}
|
||||
}
|
||||
@@ -422,14 +447,14 @@ void Map::updateTiles() {
|
||||
void Map::updateRenderState() {
|
||||
std::forward_list<Tile::ID> ids;
|
||||
|
||||
for (const std::shared_ptr<Source> &source : style->getActiveSources()) {
|
||||
for (const std::shared_ptr<Source> &source : getActiveSources()) {
|
||||
ids.splice_after(ids.before_begin(), source->getIDs());
|
||||
source->updateMatrices(painter.projMatrix, state);
|
||||
}
|
||||
|
||||
const std::map<Tile::ID, ClipID> clipIDs = computeClipIDs(ids);
|
||||
|
||||
for (const std::shared_ptr<Source> &source : style->getActiveSources()) {
|
||||
for (const std::shared_ptr<Source> &source : getActiveSources()) {
|
||||
source->updateClipIDs(clipIDs);
|
||||
}
|
||||
}
|
||||
@@ -473,6 +498,7 @@ void Map::prepare() {
|
||||
}
|
||||
|
||||
animationTime = util::now();
|
||||
updateSources();
|
||||
style->updateProperties(state.getNormalizedZoom(), animationTime);
|
||||
|
||||
// Allow the sprite atlas to potentially pull new sprite images if needed.
|
||||
@@ -497,7 +523,7 @@ void Map::render() {
|
||||
|
||||
updateRenderState();
|
||||
|
||||
painter.drawClippingMasks(style->getActiveSources());
|
||||
painter.drawClippingMasks(getActiveSources());
|
||||
|
||||
// Actually render the layers
|
||||
if (debug::renderTree) { std::cout << "{" << std::endl; indent++; }
|
||||
@@ -508,7 +534,7 @@ void Map::render() {
|
||||
// This guarantees that we have at least one function per tile called.
|
||||
// When only rendering layers via the stylesheet, it's possible that we don't
|
||||
// ever visit a tile during rendering.
|
||||
for (const std::shared_ptr<Source> &source : style->getActiveSources()) {
|
||||
for (const std::shared_ptr<Source> &source : getActiveSources()) {
|
||||
source->finishRender(painter);
|
||||
}
|
||||
|
||||
@@ -601,7 +627,7 @@ void Map::renderLayer(std::shared_ptr<StyleLayer> layer_desc, RenderPass pass) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!layer_desc->bucket->source) {
|
||||
if (!layer_desc->bucket->style_source) {
|
||||
fprintf(stderr, "[WARNING] can't find source for layer '%s'\n", layer_desc->id.c_str());
|
||||
return;
|
||||
}
|
||||
@@ -637,6 +663,8 @@ void Map::renderLayer(std::shared_ptr<StyleLayer> layer_desc, RenderPass pass) {
|
||||
<< layer_desc->type << ")" << std::endl;
|
||||
}
|
||||
|
||||
layer_desc->bucket->source->render(painter, layer_desc);
|
||||
// TODO: THIS IS BAD, FIXME
|
||||
Source source(*layer_desc->bucket->style_source, this->getAccessToken());
|
||||
source.render(painter, layer_desc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,13 @@
|
||||
|
||||
namespace llmr {
|
||||
|
||||
Source::Source(StyleSource style_source, const std::string &access_token)
|
||||
: type(style_source.type),
|
||||
url(normalizeSourceURL(style_source.url, access_token)),
|
||||
tile_size(style_source.tile_size),
|
||||
min_zoom(style_source.min_zoom),
|
||||
max_zoom(style_source.max_zoom) {}
|
||||
|
||||
Source::Source(SourceType type, const std::string &url,
|
||||
uint32_t tile_size, uint32_t min_zoom, uint32_t max_zoom,
|
||||
const std::string &access_token)
|
||||
|
||||
@@ -108,7 +108,7 @@ void Painter::pushFramebuffer() {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
glColorMask(false, false, false, false);
|
||||
|
||||
drawClippingMasks(map.getStyle()->getActiveSources());
|
||||
drawClippingMasks(map.getActiveSources());
|
||||
|
||||
glColorMask(true, true, true, true);
|
||||
fbo_depth_stencil_valid = true;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <llmr/map/map.hpp>
|
||||
#include <llmr/style/style.hpp>
|
||||
#include <llmr/style/style_layer_group.hpp>
|
||||
#include <llmr/style/style_parser.hpp>
|
||||
@@ -13,40 +12,12 @@
|
||||
|
||||
namespace llmr {
|
||||
|
||||
Style::Style(Map &map)
|
||||
: map(map) {
|
||||
}
|
||||
|
||||
void Style::updateSources() {
|
||||
activeSources.clear();
|
||||
updateSources(layers);
|
||||
}
|
||||
|
||||
const std::set<std::shared_ptr<Source>> Style::getActiveSources() const {
|
||||
return activeSources;
|
||||
}
|
||||
|
||||
void Style::updateSources(const std::shared_ptr<StyleLayerGroup> &group) {
|
||||
if (!group) {
|
||||
return;
|
||||
}
|
||||
for (const std::shared_ptr<StyleLayer> &layer : group->layers) {
|
||||
if (!layer) continue;
|
||||
if (layer->bucket) {
|
||||
if (layer->bucket->source) {
|
||||
activeSources.emplace(layer->bucket->source);
|
||||
}
|
||||
} else if (layer->layers) {
|
||||
updateSources(layer->layers);
|
||||
}
|
||||
}
|
||||
Style::Style() {
|
||||
}
|
||||
|
||||
void Style::updateProperties(float z, timestamp now) {
|
||||
uv::writelock lock(mtx);
|
||||
|
||||
updateSources();
|
||||
|
||||
if (layers) {
|
||||
layers->updateProperties(z, now);
|
||||
}
|
||||
@@ -109,7 +80,7 @@ void Style::loadJSON(const uint8_t *const data) {
|
||||
throw error::style_parse(doc.GetErrorOffset(), doc.GetParseError());
|
||||
}
|
||||
|
||||
StyleParser parser(map);
|
||||
StyleParser parser;
|
||||
parser.parse(const_cast<const rapidjson::Document &>(doc));
|
||||
|
||||
layers = parser.getLayers();
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include <llmr/style/style_layer.hpp>
|
||||
#include <llmr/style/style_bucket.hpp>
|
||||
#include <llmr/map/source.hpp>
|
||||
#include <llmr/style/style_layer_group.hpp>
|
||||
#include <llmr/style/property_fallback.hpp>
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <llmr/map/map.hpp>
|
||||
#include <llmr/style/style_parser.hpp>
|
||||
#include <llmr/style/style_layer_group.hpp>
|
||||
#include <llmr/util/constants.hpp>
|
||||
@@ -9,8 +8,7 @@ namespace llmr {
|
||||
|
||||
using JSVal = const rapidjson::Value&;
|
||||
|
||||
StyleParser::StyleParser(Map &map)
|
||||
: map(map) {
|
||||
StyleParser::StyleParser() {
|
||||
}
|
||||
|
||||
void StyleParser::parse(JSVal document) {
|
||||
@@ -176,7 +174,7 @@ void StyleParser::parseSources(JSVal value) {
|
||||
parseRenderProperty(itr->value, min_zoom, "minZoom");
|
||||
parseRenderProperty(itr->value, max_zoom, "maxZoom");
|
||||
|
||||
sources.emplace(std::move(name), std::make_shared<Source>(type, url, tile_size, min_zoom, max_zoom, map.getAccessToken()));
|
||||
sources.emplace(std::move(name), std::make_shared<StyleSource>(type, url, tile_size, min_zoom, max_zoom));
|
||||
}
|
||||
} else {
|
||||
throw Style::exception("sources must be an object");
|
||||
@@ -727,7 +725,7 @@ void StyleParser::parseBucket(JSVal value, std::shared_ptr<StyleLayer> &layer) {
|
||||
const std::string source_name = { value_source.GetString(), value_source.GetStringLength() };
|
||||
auto source_it = sources.find(source_name);
|
||||
if (source_it != sources.end()) {
|
||||
layer->bucket->source = source_it->second;
|
||||
layer->bucket->style_source = source_it->second;
|
||||
} else {
|
||||
fprintf(stderr, "[WARNING] can't find source '%s' required for layer '%s'\n",
|
||||
source_name.c_str(), layer->id.c_str());
|
||||
|
||||
Reference in New Issue
Block a user