summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-06-01 13:53:09 -0700
committerAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-06-01 15:38:01 -0700
commit2652a4a677b83656a7b5c9a1e477f1b2f9e8c76d (patch)
treed11117ac32017cdba3d479f64c824afbc867e014
parent5ff9d6e31ba391b3630fbfc0db1ca8da486e1b9f (diff)
downloadqtlocation-mapboxgl-2652a4a677b83656a7b5c9a1e477f1b2f9e8c76d.tar.gz
[core] Add templated RTTI for RenderSource classes
-rw-r--r--src/mbgl/annotation/render_annotation_source.hpp5
-rw-r--r--src/mbgl/renderer/layers/render_raster_layer.cpp8
-rw-r--r--src/mbgl/renderer/render_source.hpp15
-rw-r--r--src/mbgl/renderer/sources/render_geojson_source.hpp5
-rw-r--r--src/mbgl/renderer/sources/render_image_source.hpp5
-rw-r--r--src/mbgl/renderer/sources/render_raster_source.hpp5
-rw-r--r--src/mbgl/renderer/sources/render_vector_source.hpp5
7 files changed, 44 insertions, 4 deletions
diff --git a/src/mbgl/annotation/render_annotation_source.hpp b/src/mbgl/annotation/render_annotation_source.hpp
index 539e73b57e..980d9d27e9 100644
--- a/src/mbgl/annotation/render_annotation_source.hpp
+++ b/src/mbgl/annotation/render_annotation_source.hpp
@@ -52,4 +52,9 @@ private:
TilePyramid tilePyramid;
};
+template <>
+inline bool RenderSource::is<RenderAnnotationSource>() const {
+ return baseImpl->type == SourceType::Annotations;
+}
+
} // namespace mbgl
diff --git a/src/mbgl/renderer/layers/render_raster_layer.cpp b/src/mbgl/renderer/layers/render_raster_layer.cpp
index 49983462a3..28cf722c14 100644
--- a/src/mbgl/renderer/layers/render_raster_layer.cpp
+++ b/src/mbgl/renderer/layers/render_raster_layer.cpp
@@ -38,8 +38,8 @@ bool RenderRasterLayer::hasTransition() const {
void RenderRasterLayer::uploadBuckets(gl::Context& context, RenderSource* source) {
RenderLayer::uploadBuckets(context, source);
- if (renderTiles.size() == 0) {
- RenderImageSource* imageSource = dynamic_cast<RenderImageSource*>(source);
+ if (renderTiles.empty()) {
+ RenderImageSource* imageSource = source->as<RenderImageSource>();
if (imageSource) {
imageSource->upload(context);
}
@@ -48,8 +48,8 @@ void RenderRasterLayer::uploadBuckets(gl::Context& context, RenderSource* source
void RenderRasterLayer::render(Painter& painter, PaintParameters& parameters, RenderSource* source) {
RenderLayer::render(painter, parameters, source);
- if (renderTiles.size() == 0) {
- RenderImageSource* imageSource = dynamic_cast<RenderImageSource*>(source);
+ if (renderTiles.empty()) {
+ RenderImageSource* imageSource = source->as<RenderImageSource>();
if (imageSource) {
imageSource->render(painter, parameters, *this);
}
diff --git a/src/mbgl/renderer/render_source.hpp b/src/mbgl/renderer/render_source.hpp
index 994d600613..dae0ea19b1 100644
--- a/src/mbgl/renderer/render_source.hpp
+++ b/src/mbgl/renderer/render_source.hpp
@@ -33,6 +33,21 @@ public:
~RenderSource() override = default;
+ // Check whether this source is of the given subtype.
+ template <class T>
+ bool is() const;
+
+ // Dynamically cast this source to the given subtype.
+ template <class T>
+ T* as() {
+ return is<T>() ? reinterpret_cast<T*>(this) : nullptr;
+ }
+
+ template <class T>
+ const T* as() const {
+ return is<T>() ? reinterpret_cast<const T*>(this) : nullptr;
+ }
+
virtual bool isLoaded() const = 0;
// Called when the camera has changed. May load new tiles, unload obsolete tiles, or
diff --git a/src/mbgl/renderer/sources/render_geojson_source.hpp b/src/mbgl/renderer/sources/render_geojson_source.hpp
index 0f9379b9b6..51caf43714 100644
--- a/src/mbgl/renderer/sources/render_geojson_source.hpp
+++ b/src/mbgl/renderer/sources/render_geojson_source.hpp
@@ -57,4 +57,9 @@ private:
style::GeoJSONData* data;
};
+template <>
+inline bool RenderSource::is<RenderGeoJSONSource>() const {
+ return baseImpl->type == SourceType::GeoJSON;
+}
+
} // namespace mbgl
diff --git a/src/mbgl/renderer/sources/render_image_source.hpp b/src/mbgl/renderer/sources/render_image_source.hpp
index 86c17b10fd..54afca4bee 100644
--- a/src/mbgl/renderer/sources/render_image_source.hpp
+++ b/src/mbgl/renderer/sources/render_image_source.hpp
@@ -65,4 +65,9 @@ private:
bool shouldRender;
};
+template <>
+inline bool RenderSource::is<RenderImageSource>() const {
+ return baseImpl->type == SourceType::Image;
+}
+
} // namespace mbgl
diff --git a/src/mbgl/renderer/sources/render_raster_source.hpp b/src/mbgl/renderer/sources/render_raster_source.hpp
index 9bf4436bc7..d0714aee06 100644
--- a/src/mbgl/renderer/sources/render_raster_source.hpp
+++ b/src/mbgl/renderer/sources/render_raster_source.hpp
@@ -53,4 +53,9 @@ private:
optional<std::vector<std::string>> tileURLTemplates;
};
+template <>
+inline bool RenderSource::is<RenderRasterSource>() const {
+ return baseImpl->type == SourceType::Raster;
+}
+
} // namespace mbgl
diff --git a/src/mbgl/renderer/sources/render_vector_source.hpp b/src/mbgl/renderer/sources/render_vector_source.hpp
index b3704a1274..f3de27d78a 100644
--- a/src/mbgl/renderer/sources/render_vector_source.hpp
+++ b/src/mbgl/renderer/sources/render_vector_source.hpp
@@ -53,4 +53,9 @@ private:
optional<std::vector<std::string>> tileURLTemplates;
};
+template <>
+inline bool RenderSource::is<RenderVectorSource>() const {
+ return baseImpl->type == SourceType::Vector;
+}
+
} // namespace mbgl