summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Morris <michael.patrick.morris@gmail.com>2014-07-10 16:29:49 -0700
committerMike Morris <michael.patrick.morris@gmail.com>2014-07-10 16:29:49 -0700
commit53e995acae1266131070252802cb3901880e3355 (patch)
tree62f610f2e58a1122d9087a3a5c396cdda93d1f74
parent1268fafe0bab09816d2373db8ca9abbcdb702fc3 (diff)
downloadqtlocation-mapboxgl-53e995acae1266131070252802cb3901880e3355.tar.gz
break out StyleSource from Source, move getActiveSources and updateSources into Map::Map
-rw-r--r--include/llmr/map/map.hpp6
-rw-r--r--include/llmr/map/source.hpp2
-rw-r--r--include/llmr/style/style.hpp9
-rw-r--r--include/llmr/style/style_bucket.hpp5
-rw-r--r--include/llmr/style/style_parser.hpp4
-rw-r--r--include/llmr/style/style_source.hpp27
-rw-r--r--src/map/map.cpp42
-rw-r--r--src/map/source.cpp10
-rw-r--r--src/renderer/painter_framebuffers.cpp2
-rw-r--r--src/style/style.cpp27
-rw-r--r--src/style/style_layer.cpp5
-rw-r--r--src/style/style_parser.cpp4
12 files changed, 88 insertions, 55 deletions
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<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;
@@ -121,6 +122,9 @@ private:
// Setup
void setup();
+ void updateSources();
+ void updateSources(const std::shared_ptr<StyleLayerGroup> &group);
+
void updateTiles();
void updateRenderState();
@@ -172,6 +176,8 @@ private:
int indent = 0;
+ std::set<std::shared_ptr<Source>> activeSources;
+
private:
bool async = false;
std::shared_ptr<uv::loop> 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 <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);
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 <llmr/style/property_transition.hpp>
+#include <llmr/style/style_source.hpp>
#include <llmr/util/time.hpp>
#include <llmr/util/uv.hpp>
@@ -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<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);
@@ -57,13 +55,8 @@ public:
std::string sprite_url;
std::string glyph_url;
-private:
- void updateSources();
- void updateSources(const std::shared_ptr<StyleLayerGroup> &group);
-
private:
- std::set<std::shared_ptr<Source>> 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 <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();
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 <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>
@@ -94,7 +94,7 @@ private:
private:
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;
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 <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
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<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));
+ }
+ } 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);
}
}
@@ -414,14 +439,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);
}
}
@@ -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> &source : style->getActiveSources()) {
+ for (const std::shared_ptr<Source> &source : getActiveSources()) {
source->finishRender(painter);
}
@@ -593,7 +619,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;
}
@@ -629,6 +655,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);
+ 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<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);
- }
- }
-}
-
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 <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>
@@ -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<Source>(type, url, tile_size, min_zoom, max_zoom));
+ 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");
@@ -731,7 +731,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());