diff options
author | Asheem Mamoowala <asheem.mamoowala@mapbox.com> | 2017-05-31 11:53:04 -0700 |
---|---|---|
committer | Asheem Mamoowala <asheem.mamoowala@mapbox.com> | 2017-06-01 15:38:01 -0700 |
commit | 8b37a0704c7c20b1664fee3dfcc79139982a1ce7 (patch) | |
tree | 9c0a50330b7e4f152a3a9ee25685fcbe8b9a4df4 /src | |
parent | 843da07b28a840fd850056c4b15d492ccc76a646 (diff) | |
download | qtlocation-mapboxgl-8b37a0704c7c20b1664fee3dfcc79139982a1ce7.tar.gz |
[core] Use fixed-size std::array for ImageSource coordinates
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/renderer/buckets/raster_bucket.cpp | 7 | ||||
-rw-r--r-- | src/mbgl/renderer/buckets/raster_bucket.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/layers/render_raster_layer.cpp | 19 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_image_source.cpp | 7 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_image_source.hpp | 7 | ||||
-rw-r--r-- | src/mbgl/style/sources/image_source.cpp | 12 | ||||
-rw-r--r-- | src/mbgl/style/sources/image_source_impl.cpp | 10 | ||||
-rw-r--r-- | src/mbgl/style/sources/image_source_impl.hpp | 15 |
8 files changed, 31 insertions, 48 deletions
diff --git a/src/mbgl/renderer/buckets/raster_bucket.cpp b/src/mbgl/renderer/buckets/raster_bucket.cpp index fa105fd38d..e0bfaf7b68 100644 --- a/src/mbgl/renderer/buckets/raster_bucket.cpp +++ b/src/mbgl/renderer/buckets/raster_bucket.cpp @@ -1,11 +1,12 @@ -#include <mbgl/gl/context.hpp> -#include <mbgl/programs/raster_program.hpp> #include <mbgl/renderer/buckets/raster_bucket.hpp> #include <mbgl/renderer/layers/render_raster_layer.hpp> +#include <mbgl/programs/raster_program.hpp> #include <mbgl/renderer/painter.hpp> +#include <mbgl/gl/context.hpp> #include <mbgl/renderer/render_tile.hpp> namespace mbgl { + using namespace style; RasterBucket::RasterBucket(UnassociatedImage&& image_) : image(std::move(image_)) { @@ -17,7 +18,7 @@ RasterBucket::RasterBucket(RasterBucket&& other) : image(std::move(other.image)) void RasterBucket::upload(gl::Context& context) { texture = context.createTexture(image); - if (vertices.vertexSize() > 0) { + if (!vertices.empty()) { vertexBuffer = context.createVertexBuffer(std::move(vertices)); indexBuffer = context.createIndexBuffer(std::move(indices)); } diff --git a/src/mbgl/renderer/buckets/raster_bucket.hpp b/src/mbgl/renderer/buckets/raster_bucket.hpp index b7b1d312dc..08afa6ddfa 100644 --- a/src/mbgl/renderer/buckets/raster_bucket.hpp +++ b/src/mbgl/renderer/buckets/raster_bucket.hpp @@ -27,6 +27,8 @@ public: UnassociatedImage image; optional<gl::Texture> texture; + // Bucket specific vertices are used for Image Sources only + // Raster Tile Sources use the default buffers from Painter gl::VertexVector<RasterLayoutVertex> vertices; gl::IndexVector<gl::Triangles> indices; gl::SegmentVector<RasterAttributes> segments; diff --git a/src/mbgl/renderer/layers/render_raster_layer.cpp b/src/mbgl/renderer/layers/render_raster_layer.cpp index 3551f9fa9a..49983462a3 100644 --- a/src/mbgl/renderer/layers/render_raster_layer.cpp +++ b/src/mbgl/renderer/layers/render_raster_layer.cpp @@ -37,14 +37,8 @@ bool RenderRasterLayer::hasTransition() const { } void RenderRasterLayer::uploadBuckets(gl::Context& context, RenderSource* source) { - if (renderTiles.size() > 0) { - for (const auto& tileRef : renderTiles) { - const auto& bucket = tileRef.get().tile.getBucket(impl()); - if (bucket && bucket->needsUpload()) { - bucket->upload(context); - } - } - } else { + RenderLayer::uploadBuckets(context, source); + if (renderTiles.size() == 0) { RenderImageSource* imageSource = dynamic_cast<RenderImageSource*>(source); if (imageSource) { imageSource->upload(context); @@ -53,13 +47,8 @@ void RenderRasterLayer::uploadBuckets(gl::Context& context, RenderSource* source } void RenderRasterLayer::render(Painter& painter, PaintParameters& parameters, RenderSource* source) { - if (renderTiles.size() > 0) { - for (auto& tileRef : renderTiles) { - auto& tile = tileRef.get(); - auto bucket = tile.tile.getBucket(impl()); - bucket->render(painter, parameters, *this, tile); - } - } else { + RenderLayer::render(painter, parameters, source); + if (renderTiles.size() == 0) { RenderImageSource* imageSource = dynamic_cast<RenderImageSource*>(source); if (imageSource) { imageSource->render(painter, parameters, *this); diff --git a/src/mbgl/renderer/sources/render_image_source.cpp b/src/mbgl/renderer/sources/render_image_source.cpp index 975b08eb47..3fec926b7f 100644 --- a/src/mbgl/renderer/sources/render_image_source.cpp +++ b/src/mbgl/renderer/sources/render_image_source.cpp @@ -16,6 +16,8 @@ RenderImageSource::RenderImageSource(Immutable<style::ImageSource::Impl> impl_) : RenderSource(impl_), shouldRender(false) { } +RenderImageSource::~RenderImageSource() = default; + const style::ImageSource::Impl& RenderImageSource::impl() const { return static_cast<const style::ImageSource::Impl&>(*baseImpl); } @@ -127,10 +129,7 @@ void RenderImageSource::updateTiles(const TileParameters& parameters) { auto gc = TileCoordinate::toGeometryCoordinate(tileIds[0], tc.p); geomCoords.push_back(gc); } - setupBucket(geomCoords); -} - -void RenderImageSource::setupBucket(GeometryCoordinates& geomCoords) { + if (!bucket) { UnassociatedImage img = impl().getImage().clone(); if (!img.valid()) { diff --git a/src/mbgl/renderer/sources/render_image_source.hpp b/src/mbgl/renderer/sources/render_image_source.hpp index 769f932f27..86c17b10fd 100644 --- a/src/mbgl/renderer/sources/render_image_source.hpp +++ b/src/mbgl/renderer/sources/render_image_source.hpp @@ -1,16 +1,13 @@ #pragma once -#include <mbgl/renderer/buckets/raster_bucket.hpp> #include <mbgl/renderer/render_source.hpp> #include <mbgl/renderer/render_tile.hpp> #include <mbgl/style/sources/image_source_impl.hpp> -#include <mbgl/tile/geometry_tile_data.hpp> -#include <mbgl/util/image.hpp> -#include <mbgl/util/optional.hpp> namespace mbgl { class RenderLayer; class PaintParameters; +class RasterBucket; namespace gl { class Context; @@ -19,6 +16,7 @@ class Context; class RenderImageSource : public RenderSource { public: RenderImageSource(Immutable<style::ImageSource::Impl>); + ~RenderImageSource() override; bool isLoaded() const final; void upload(gl::Context&); @@ -59,7 +57,6 @@ public: private: const style::ImageSource::Impl& impl() const; - void setupBucket(GeometryCoordinates& coordiantes); std::map<UnwrappedTileID, RenderTile> tiles; std::vector<UnwrappedTileID> tileIds; diff --git a/src/mbgl/style/sources/image_source.cpp b/src/mbgl/style/sources/image_source.cpp index 79df65697c..9313d8da4a 100644 --- a/src/mbgl/style/sources/image_source.cpp +++ b/src/mbgl/style/sources/image_source.cpp @@ -8,7 +8,7 @@ namespace mbgl { namespace style { -ImageSource::ImageSource(std::string id, const std::vector<LatLng> coords_) +ImageSource::ImageSource(std::string id, const std::array<LatLng, 4> coords_) : Source(makeMutable<Impl>(std::move(id), coords_)) { } @@ -18,12 +18,12 @@ const ImageSource::Impl& ImageSource::impl() const { return static_cast<const Impl&>(*baseImpl); } -void ImageSource::setCoordinates(const std::vector<LatLng>& coords_) { +void ImageSource::setCoordinates(const std::array<LatLng, 4>& coords_) { baseImpl = makeMutable<Impl>(impl(), coords_); observer->onSourceChanged(*this); } -std::vector<LatLng> ImageSource::getCoordinates() const { +std::array<LatLng, 4> ImageSource::getCoordinates() const { return impl().getCoordinates(); } @@ -37,7 +37,7 @@ void ImageSource::setURL(const std::string& url_) { } } -void ImageSource::setImage(mbgl::UnassociatedImage&& image_) { +void ImageSource::setImage(UnassociatedImage&& image_) { url = {}; if (req) { req.reset(); @@ -47,8 +47,8 @@ void ImageSource::setImage(mbgl::UnassociatedImage&& image_) { observer->onSourceChanged(*this); } -const std::string& ImageSource::getURL() const { - return *url; +optional<std::string> ImageSource::getURL() const { + return url; } void ImageSource::loadDescription(FileSource& fileSource) { diff --git a/src/mbgl/style/sources/image_source_impl.cpp b/src/mbgl/style/sources/image_source_impl.cpp index 3678f641cb..98f3cc9db9 100644 --- a/src/mbgl/style/sources/image_source_impl.cpp +++ b/src/mbgl/style/sources/image_source_impl.cpp @@ -4,12 +4,12 @@ namespace mbgl { namespace style { -ImageSource::Impl::Impl(std::string id_, std::vector<LatLng> coords_) +ImageSource::Impl::Impl(std::string id_, std::array<LatLng, 4> coords_) : Source::Impl(SourceType::Image, std::move(id_)), coords(std::move(coords_)) { } -ImageSource::Impl::Impl(const Impl& other, std::vector<LatLng> coords_) +ImageSource::Impl::Impl(const Impl& other, std::array<LatLng, 4> coords_) : Source::Impl(other), coords(std::move(coords_)), image(other.image.clone()) { @@ -22,15 +22,11 @@ ImageSource::Impl::Impl(const Impl& rhs, UnassociatedImage image_) } ImageSource::Impl::~Impl() = default; -void ImageSource::Impl::setImage(UnassociatedImage&& image_) { - image = std::move(image_); -} - const UnassociatedImage& ImageSource::Impl::getImage() const { return image; } -std::vector<LatLng> ImageSource::Impl::getCoordinates() const { +std::array<LatLng, 4> ImageSource::Impl::getCoordinates() const { return coords; } diff --git a/src/mbgl/style/sources/image_source_impl.hpp b/src/mbgl/style/sources/image_source_impl.hpp index 26f025db74..5fd41ac6e6 100644 --- a/src/mbgl/style/sources/image_source_impl.hpp +++ b/src/mbgl/style/sources/image_source_impl.hpp @@ -3,28 +3,27 @@ #include <mbgl/style/source_impl.hpp> #include <mbgl/style/sources/image_source.hpp> #include <mbgl/util/image.hpp> +#include <mbgl/util/geo.hpp> namespace mbgl { -class LatLng; namespace style { class ImageSource::Impl : public Source::Impl { public: - Impl(std::string id, std::vector<LatLng> coords); - Impl(const Impl& rhs, std::vector<LatLng> coords); + Impl(std::string id, std::array<LatLng, 4> coords); + Impl(const Impl& rhs, std::array<LatLng, 4> coords); Impl(const Impl& rhs, UnassociatedImage image); ~Impl() final; - void setImage(UnassociatedImage&& ); - const mbgl::UnassociatedImage& getImage() const; - std::vector<LatLng> getCoordinates() const; + const UnassociatedImage& getImage() const; + std::array<LatLng, 4> getCoordinates() const; optional<std::string> getAttribution() const final; private: - std::vector<LatLng> coords; - mbgl::UnassociatedImage image; + std::array<LatLng, 4> coords; + UnassociatedImage image; }; } // namespace style |