summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-05-31 23:14:12 -0700
committerAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-06-01 15:38:01 -0700
commit5ff9d6e31ba391b3630fbfc0db1ca8da486e1b9f (patch)
tree5d463062de5537feb940572faeebf9f53a76f37e
parent8b37a0704c7c20b1664fee3dfcc79139982a1ce7 (diff)
downloadqtlocation-mapboxgl-5ff9d6e31ba391b3630fbfc0db1ca8da486e1b9f.tar.gz
[core] Reuse RasterBucket for ImageSource
-rw-r--r--src/mbgl/gl/index_buffer.hpp1
-rw-r--r--src/mbgl/gl/vertex_buffer.hpp1
-rw-r--r--src/mbgl/renderer/buckets/raster_bucket.cpp13
-rw-r--r--src/mbgl/renderer/buckets/raster_bucket.hpp2
-rw-r--r--src/mbgl/renderer/sources/render_image_source.cpp3
-rw-r--r--test/gl/bucket.test.cpp16
6 files changed, 29 insertions, 7 deletions
diff --git a/src/mbgl/gl/index_buffer.hpp b/src/mbgl/gl/index_buffer.hpp
index b3610f4154..1e57fb11f2 100644
--- a/src/mbgl/gl/index_buffer.hpp
+++ b/src/mbgl/gl/index_buffer.hpp
@@ -24,6 +24,7 @@ public:
std::size_t byteSize() const { return v.size() * sizeof(uint16_t); }
bool empty() const { return v.empty(); }
+ void clear() { v.clear(); }
const uint16_t* data() const { return v.data(); }
private:
diff --git a/src/mbgl/gl/vertex_buffer.hpp b/src/mbgl/gl/vertex_buffer.hpp
index c9bc01f3e8..4808803d00 100644
--- a/src/mbgl/gl/vertex_buffer.hpp
+++ b/src/mbgl/gl/vertex_buffer.hpp
@@ -26,6 +26,7 @@ public:
std::size_t byteSize() const { return v.size() * sizeof(Vertex); }
bool empty() const { return v.empty(); }
+ void clear() { v.clear(); }
const Vertex* data() const { return v.data(); }
private:
diff --git a/src/mbgl/renderer/buckets/raster_bucket.cpp b/src/mbgl/renderer/buckets/raster_bucket.cpp
index e0bfaf7b68..8c9c1658a1 100644
--- a/src/mbgl/renderer/buckets/raster_bucket.cpp
+++ b/src/mbgl/renderer/buckets/raster_bucket.cpp
@@ -12,10 +12,6 @@ using namespace style;
RasterBucket::RasterBucket(UnassociatedImage&& image_) : image(std::move(image_)) {
}
-RasterBucket::RasterBucket(RasterBucket&& other) : image(std::move(other.image)) {
- uploaded = false;
-}
-
void RasterBucket::upload(gl::Context& context) {
texture = context.createTexture(image);
if (!vertices.empty()) {
@@ -25,6 +21,15 @@ void RasterBucket::upload(gl::Context& context) {
uploaded = true;
}
+void RasterBucket::clear() {
+ vertexBuffer = {};
+ indexBuffer = {};
+ segments.clear();
+ vertices.clear();
+ indices.clear();
+
+ uploaded = false;
+}
void RasterBucket::render(Painter& painter,
PaintParameters& parameters,
const RenderLayer& layer,
diff --git a/src/mbgl/renderer/buckets/raster_bucket.hpp b/src/mbgl/renderer/buckets/raster_bucket.hpp
index 08afa6ddfa..b5cf7997d5 100644
--- a/src/mbgl/renderer/buckets/raster_bucket.hpp
+++ b/src/mbgl/renderer/buckets/raster_bucket.hpp
@@ -14,7 +14,6 @@ namespace mbgl {
class RasterBucket : public Bucket {
public:
RasterBucket(UnassociatedImage&&);
- RasterBucket(RasterBucket&&);
void upload(gl::Context&) override;
void render(Painter&, PaintParameters&, const RenderLayer&, const RenderTile&) override;
@@ -24,6 +23,7 @@ public:
const mat4& matrix);
bool hasData() const override;
+ void clear();
UnassociatedImage image;
optional<gl::Texture> texture;
diff --git a/src/mbgl/renderer/sources/render_image_source.cpp b/src/mbgl/renderer/sources/render_image_source.cpp
index 3fec926b7f..e5a7b1a6ed 100644
--- a/src/mbgl/renderer/sources/render_image_source.cpp
+++ b/src/mbgl/renderer/sources/render_image_source.cpp
@@ -137,8 +137,7 @@ void RenderImageSource::updateTiles(const TileParameters& parameters) {
}
bucket = std::make_unique<RasterBucket>(std::move(img));
} else {
- // Reuse the bucket
- bucket = std::make_unique<RasterBucket>(std::move(*bucket));
+ bucket->clear();
}
// Set Bucket Vertices, Indices, and segments
diff --git a/test/gl/bucket.test.cpp b/test/gl/bucket.test.cpp
index b291816562..ee9ea54414 100644
--- a/test/gl/bucket.test.cpp
+++ b/test/gl/bucket.test.cpp
@@ -3,9 +3,11 @@
#include <mbgl/renderer/buckets/circle_bucket.hpp>
#include <mbgl/renderer/buckets/fill_bucket.hpp>
#include <mbgl/renderer/buckets/line_bucket.hpp>
+#include <mbgl/renderer/buckets/raster_bucket.hpp>
#include <mbgl/renderer/buckets/symbol_bucket.hpp>
#include <mbgl/renderer/bucket_parameters.hpp>
#include <mbgl/style/layers/symbol_layer_properties.hpp>
+#include <mbgl/gl/context.hpp>
#include <mbgl/map/mode.hpp>
@@ -36,3 +38,17 @@ TEST(Buckets, SymbolBucket) {
ASSERT_FALSE(bucket.hasTextData());
ASSERT_FALSE(bucket.hasCollisionBoxData());
}
+
+TEST(Buckets, RasterBucket) {
+ gl::Context context;
+ UnassociatedImage rgba({ 1, 1 });
+
+ RasterBucket bucket = { std::move(rgba) };
+ ASSERT_TRUE(bucket.needsUpload());
+
+ bucket.upload(context);
+ ASSERT_FALSE(bucket.needsUpload());
+
+ bucket.clear();
+ ASSERT_TRUE(bucket.needsUpload());
+}