From 53e995acae1266131070252802cb3901880e3355 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Thu, 10 Jul 2014 16:29:49 -0700 Subject: break out StyleSource from Source, move getActiveSources and updateSources into Map::Map --- include/llmr/map/map.hpp | 6 +++++ include/llmr/map/source.hpp | 2 ++ include/llmr/style/style.hpp | 9 +------- include/llmr/style/style_bucket.hpp | 5 ++--- include/llmr/style/style_parser.hpp | 4 ++-- include/llmr/style/style_source.hpp | 27 ++++++++++++++++++++++ src/map/map.cpp | 42 +++++++++++++++++++++++++++++------ src/map/source.cpp | 10 +++++++-- src/renderer/painter_framebuffers.cpp | 2 +- src/style/style.cpp | 27 ---------------------- src/style/style_layer.cpp | 5 ++--- src/style/style_parser.cpp | 4 ++-- 12 files changed, 88 insertions(+), 55 deletions(-) create mode 100644 include/llmr/style/style_source.hpp diff --git a/include/llmr/map/map.hpp b/include/llmr/map/map.hpp index 1af6b3c540..1d64a124c7 100644 --- a/include/llmr/map/map.hpp +++ b/include/llmr/map/map.hpp @@ -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> getActiveSources() const; void setAppliedClasses(const std::vector &classes); void toggleClass(const std::string &name); const std::vector &getAppliedClasses() const; @@ -121,6 +122,9 @@ private: // Setup void setup(); + void updateSources(); + void updateSources(const std::shared_ptr &group); + void updateTiles(); void updateRenderState(); @@ -172,6 +176,8 @@ private: int indent = 0; + std::set> activeSources; + private: bool async = false; std::shared_ptr loop; diff --git a/include/llmr/map/source.hpp b/include/llmr/map/source.hpp index 2937a8f690..8ceb9ca076 100644 --- a/include/llmr/map/source.hpp +++ b/include/llmr/map/source.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -22,6 +23,7 @@ class Texturepool; class Source : public std::enable_shared_from_this, private util::noncopyable { public: + Source(StyleSource style_source); Source(SourceType type = SourceType::Vector, const std::string &url = "", uint32_t tile_size = 512, uint32_t min_zoom = 0, uint32_t max_zoom = 22); diff --git a/include/llmr/style/style.hpp b/include/llmr/style/style.hpp index 37a50485ba..cf091ad814 100644 --- a/include/llmr/style/style.hpp +++ b/include/llmr/style/style.hpp @@ -2,6 +2,7 @@ #define LLMR_STYLE_STYLE #include +#include #include #include @@ -17,7 +18,6 @@ namespace llmr { class Sprite; -class Source; class StyleLayer; class StyleLayerGroup; struct BackgroundProperties; @@ -36,8 +36,6 @@ public: void setDefaultTransitionDuration(uint16_t duration_milliseconds = 0); - const std::set> getActiveSources() const; - void setAppliedClasses(const std::vector &classes); const std::vector &getAppliedClasses() const; void toggleClass(const std::string &name); @@ -57,13 +55,8 @@ public: std::string sprite_url; std::string glyph_url; -private: - void updateSources(); - void updateSources(const std::shared_ptr &group); - private: - std::set> activeSources; PropertyTransition defaultTransition; bool initial_render_complete = false; diff --git a/include/llmr/style/style_bucket.hpp b/include/llmr/style/style_bucket.hpp index 55ffeeb18e..c8529fdd23 100644 --- a/include/llmr/style/style_bucket.hpp +++ b/include/llmr/style/style_bucket.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -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; + std::shared_ptr style_source; std::string source_layer; FilterExpression filter; StyleBucketRender render = std::false_type(); diff --git a/include/llmr/style/style_parser.hpp b/include/llmr/style/style_parser.hpp index 10cd3d2e88..da6f586a3f 100644 --- a/include/llmr/style/style_parser.hpp +++ b/include/llmr/style/style_parser.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include #include @@ -94,7 +94,7 @@ private: private: std::unordered_map constants; - std::unordered_map> sources; + std::unordered_map> sources; // This stores the root layer. std::shared_ptr root; diff --git a/include/llmr/style/style_source.hpp b/include/llmr/style/style_source.hpp new file mode 100644 index 0000000000..76a981a801 --- /dev/null +++ b/include/llmr/style/style_source.hpp @@ -0,0 +1,27 @@ +#ifndef LLMR_STYLE_STYLE_SOURCE +#define LLMR_STYLE_STYLE_SOURCE + +#include + +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 diff --git a/src/map/map.cpp b/src/map/map.cpp index 69bee92dc9..6e57e50bdf 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -405,8 +405,33 @@ void Map::setDefaultTransitionDuration(uint64_t duration_milliseconds) { style->setDefaultTransitionDuration(duration_milliseconds); } +void Map::updateSources() { + activeSources.clear(); + updateSources(style->layers); +} + +const std::set> Map::getActiveSources() const { + return activeSources; +} + +void Map::updateSources(const std::shared_ptr &group) { + if (!group) { + return; + } + for (const std::shared_ptr &layer : group->layers) { + if (!layer) continue; + if (layer->bucket) { + if (layer->bucket->style_source) { + activeSources.emplace(std::make_shared(*layer->bucket->style_source)); + } + } else if (layer->layers) { + updateSources(layer->layers); + } + } +} + void Map::updateTiles() { - for (const std::shared_ptr &source : style->getActiveSources()) { + for (const std::shared_ptr &source : getActiveSources()) { source->update(*this); } } @@ -414,14 +439,14 @@ void Map::updateTiles() { void Map::updateRenderState() { std::forward_list ids; - for (const std::shared_ptr &source : style->getActiveSources()) { + for (const std::shared_ptr &source : getActiveSources()) { ids.splice_after(ids.before_begin(), source->getIDs()); source->updateMatrices(painter.projMatrix, state); } const std::map clipIDs = computeClipIDs(ids); - for (const std::shared_ptr &source : style->getActiveSources()) { + for (const std::shared_ptr &source : getActiveSources()) { source->updateClipIDs(clipIDs); } } @@ -465,6 +490,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. @@ -489,7 +515,7 @@ void Map::render() { updateRenderState(); - painter.drawClippingMasks(style->getActiveSources()); + painter.drawClippingMasks(getActiveSources()); // Actually render the layers if (debug::renderTree) { std::cout << "{" << std::endl; indent++; } @@ -500,7 +526,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 : style->getActiveSources()) { + for (const std::shared_ptr &source : getActiveSources()) { source->finishRender(painter); } @@ -593,7 +619,7 @@ void Map::renderLayer(std::shared_ptr 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; } @@ -629,6 +655,8 @@ void Map::renderLayer(std::shared_ptr 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); + source.render(painter, layer_desc); } } diff --git a/src/map/source.cpp b/src/map/source.cpp index 8d1593f76c..c59a8fe2d4 100644 --- a/src/map/source.cpp +++ b/src/map/source.cpp @@ -18,6 +18,13 @@ namespace llmr { +Source::Source(StyleSource style_source) + : type(style_source.type), + url(normalizeSourceURL(style_source.url)), + 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) : type(type), @@ -33,8 +40,7 @@ std::string Source::normalizeSourceURL(const std::string &url) { } else { return url; } -} - +}; bool Source::update(Map &map) { if (map.getTime() > updated) { diff --git a/src/renderer/painter_framebuffers.cpp b/src/renderer/painter_framebuffers.cpp index c7d9059dd5..36c97ed15c 100644 --- a/src/renderer/painter_framebuffers.cpp +++ b/src/renderer/painter_framebuffers.cpp @@ -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; diff --git a/src/style/style.cpp b/src/style/style.cpp index 006376172c..c5204720ab 100644 --- a/src/style/style.cpp +++ b/src/style/style.cpp @@ -15,36 +15,9 @@ namespace llmr { Style::Style() { } -void Style::updateSources() { - activeSources.clear(); - updateSources(layers); -} - -const std::set> Style::getActiveSources() const { - return activeSources; -} - -void Style::updateSources(const std::shared_ptr &group) { - if (!group) { - return; - } - for (const std::shared_ptr &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); - } - } -} - void Style::updateProperties(float z, timestamp now) { uv::writelock lock(mtx); - updateSources(); - if (layers) { layers->updateProperties(z, now); } diff --git a/src/style/style_layer.cpp b/src/style/style_layer.cpp index 0c62872727..2cff19e479 100644 --- a/src/style/style_layer.cpp +++ b/src/style/style_layer.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include @@ -251,8 +250,8 @@ void StyleLayer::updateProperties(float z, const timestamp now) { } // Accomodate for different tile size. - if (bucket && bucket->source) { - z += std::log(bucket->source->tile_size / 256.0f) / M_LN2; + if (bucket && bucket->style_source) { + z += std::log(bucket->style_source->tile_size / 256.0f) / M_LN2; } cleanupAppliedStyleProperties(now); diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp index 1821a66bd6..0d98fd8b26 100644 --- a/src/style/style_parser.cpp +++ b/src/style/style_parser.cpp @@ -169,7 +169,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(type, url, tile_size, min_zoom, max_zoom)); + sources.emplace(std::move(name), std::make_shared(type, url, tile_size, min_zoom, max_zoom)); } } else { throw Style::exception("sources must be an object"); @@ -731,7 +731,7 @@ void StyleParser::parseBucket(JSVal value, std::shared_ptr &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()); -- cgit v1.2.1