summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrad Leege <bleege@gmail.com>2016-06-09 15:10:05 -0500
committerBrad Leege <bleege@gmail.com>2016-06-09 15:10:05 -0500
commit3972044308410bc5281e267b5247a3a0898c777a (patch)
tree95bdbee967eb783be701847fc07072868c9040c2 /src
parentb90571107d6fa5dd970d77c0b67029de8cd3461a (diff)
parent40211abd9a6cb6a3b0eb8dbe61e1ccb605d19677 (diff)
downloadqtlocation-mapboxgl-3972044308410bc5281e267b5247a3a0898c777a.tar.gz
Merge branch 'master' of github.com:mapbox/mapbox-gl-native
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/geometry/buffer.hpp13
-rw-r--r--src/mbgl/geometry/glyph_atlas.hpp2
-rw-r--r--src/mbgl/gl/object_store.hpp22
-rw-r--r--src/mbgl/gl/texture_pool.cpp77
-rw-r--r--src/mbgl/gl/texture_pool.hpp35
-rw-r--r--src/mbgl/renderer/painter_fill.cpp4
-rw-r--r--src/mbgl/renderer/renderable.hpp11
-rw-r--r--src/mbgl/shader/outline_shader.hpp8
-rw-r--r--src/mbgl/style/layers/line_layer_properties.hpp2
-rw-r--r--src/mbgl/style/source.hpp1
-rw-r--r--src/mbgl/util/assert.hpp10
-rw-r--r--src/mbgl/util/channel.hpp36
-rw-r--r--src/mbgl/util/raster.cpp22
-rw-r--r--src/mbgl/util/raster.hpp9
14 files changed, 103 insertions, 149 deletions
diff --git a/src/mbgl/geometry/buffer.hpp b/src/mbgl/geometry/buffer.hpp
index 1712ca9887..6465b6f8e3 100644
--- a/src/mbgl/geometry/buffer.hpp
+++ b/src/mbgl/geometry/buffer.hpp
@@ -88,19 +88,6 @@ protected:
return reinterpret_cast<char *>(array) + (pos - itemSize);
}
- // Get a pointer to the item at a given index.
- inline void *getElement(size_t i) {
- if (array == nullptr) {
- throw std::runtime_error("Buffer was already deleted or doesn't contain elements");
- }
-
- if (i * itemSize >= pos) {
- throw std::runtime_error("Can't get element after array bounds");
- } else {
- return reinterpret_cast<char *>(array) + (i * itemSize);
- }
- }
-
public:
static const size_t itemSize = item_size;
diff --git a/src/mbgl/geometry/glyph_atlas.hpp b/src/mbgl/geometry/glyph_atlas.hpp
index 3f9a87809f..d3e2a62199 100644
--- a/src/mbgl/geometry/glyph_atlas.hpp
+++ b/src/mbgl/geometry/glyph_atlas.hpp
@@ -53,7 +53,7 @@ private:
BinPack<uint16_t> bin;
std::unordered_map<FontStack, std::map<uint32_t, GlyphValue>, FontStackHash> index;
const std::unique_ptr<uint8_t[]> data;
- std::atomic<bool> dirty;
+ util::Atomic<bool> dirty;
mbgl::optional<gl::UniqueTexture> texture;
};
diff --git a/src/mbgl/gl/object_store.hpp b/src/mbgl/gl/object_store.hpp
index e430214013..3ae1b6e2fe 100644
--- a/src/mbgl/gl/object_store.hpp
+++ b/src/mbgl/gl/object_store.hpp
@@ -20,27 +20,27 @@ class ObjectStore;
struct ProgramDeleter {
ObjectStore* store;
- void operator()(GLuint id) const;
+ void operator()(GLuint) const;
};
struct ShaderDeleter {
ObjectStore* store;
- void operator()(GLuint id) const;
+ void operator()(GLuint) const;
};
struct BufferDeleter {
ObjectStore* store;
- void operator()(GLuint id) const;
+ void operator()(GLuint) const;
};
struct TextureDeleter {
ObjectStore* store;
- void operator()(GLuint id) const;
+ void operator()(GLuint) const;
};
struct VAODeleter {
ObjectStore* store;
- void operator()(GLuint id) const;
+ void operator()(GLuint) const;
};
using ObjectPool = std::array<GLuint, TextureMax>;
@@ -62,36 +62,36 @@ public:
~ObjectStore();
UniqueProgram createProgram() {
- return UniqueProgram(MBGL_CHECK_ERROR(glCreateProgram()), { this });
+ return UniqueProgram { MBGL_CHECK_ERROR(glCreateProgram()), { this } };
}
UniqueShader createShader(GLenum type) {
- return UniqueShader(MBGL_CHECK_ERROR(glCreateShader(type)), { this });
+ return UniqueShader { MBGL_CHECK_ERROR(glCreateShader(type)), { this } };
}
UniqueBuffer createBuffer() {
GLuint id = 0;
MBGL_CHECK_ERROR(glGenBuffers(1, &id));
- return UniqueBuffer(std::move(id), { this });
+ return UniqueBuffer { std::move(id), { this } };
}
UniqueTexture createTexture() {
GLuint id = 0;
MBGL_CHECK_ERROR(glGenTextures(1, &id));
- return UniqueTexture(std::move(id), { this });
+ return UniqueTexture { std::move(id), { this } };
}
UniqueVAO createVAO() {
GLuint id = 0;
MBGL_CHECK_ERROR(gl::GenVertexArrays(1, &id));
- return UniqueVAO(std::move(id), { this });
+ return UniqueVAO { std::move(id), { this } };
}
UniqueTexturePool createTexturePool() {
ObjectPool ids;
MBGL_CHECK_ERROR(glGenTextures(TextureMax, ids.data()));
assert(ids.size() == size_t(TextureMax));
- return UniqueTexturePool(std::move(ids), { this });
+ return UniqueTexturePool { std::move(ids), { this } };
}
// Actually remove the objects we marked as abandoned with the above methods.
diff --git a/src/mbgl/gl/texture_pool.cpp b/src/mbgl/gl/texture_pool.cpp
index 8818cbef0a..c4984b0186 100644
--- a/src/mbgl/gl/texture_pool.cpp
+++ b/src/mbgl/gl/texture_pool.cpp
@@ -7,35 +7,68 @@
namespace mbgl {
namespace gl {
-GLuint TexturePool::getTextureID(gl::ObjectStore& store) {
- auto nextAvailableID = [](auto& pool_) {
- auto it = pool_.availableIDs.begin();
- GLuint id = *it;
- pool_.availableIDs.erase(it);
- return id;
+class TexturePool::Impl : private util::noncopyable {
+public:
+ class Pool : private util::noncopyable {
+ public:
+ Pool(gl::ObjectStore& store) : pool(store.createTexturePool()), availableIDs(gl::TextureMax) {
+ std::copy(pool.get().begin(), pool.get().end(), availableIDs.begin());
+ }
+
+ Pool(Pool&& o) : pool(std::move(o.pool)), availableIDs(std::move(o.availableIDs)) {}
+ Pool& operator=(Pool&& o) { pool = std::move(o.pool); availableIDs = std::move(o.availableIDs); return *this; }
+
+ gl::UniqueTexturePool pool;
+ std::vector<GLuint> availableIDs;
};
- for (auto& pool : pools) {
- if (pool.availableIDs.empty()) continue;
- return nextAvailableID(pool);
- }
+ GLuint acquireTexture(gl::ObjectStore& store) {
+ auto nextAvailableID = [](auto& pool_) {
+ auto it = pool_.availableIDs.begin();
+ GLuint id = *it;
+ pool_.availableIDs.erase(it);
+ return id;
+ };
- // All texture IDs are in use.
- pools.emplace_back(Impl { store });
- return nextAvailableID(pools.back());
-}
+ for (auto& pool : pools) {
+ if (pool.availableIDs.empty()) continue;
+ return nextAvailableID(pool);
+ }
+
+ // All texture IDs are in use.
+ pools.emplace_back(Pool { store });
+ return nextAvailableID(pools.back());
+ }
-void TexturePool::releaseTextureID(GLuint& id) {
- for (auto it = pools.begin(); it != pools.end(); ++it) {
- if (std::find(it->pool.get().begin(), it->pool.get().end(), id) != it->pool.get().end()) {
- it->availableIDs.push_back(id);
- id = 0;
- if (GLsizei(it->availableIDs.size()) == gl::TextureMax) {
- pools.erase(it);
+ void releaseTexture(GLuint id) {
+ for (auto it = pools.begin(); it != pools.end(); ++it) {
+ if (std::find(it->pool.get().begin(), it->pool.get().end(), id) != it->pool.get().end()) {
+ it->availableIDs.push_back(id);
+ if (GLsizei(it->availableIDs.size()) == gl::TextureMax) {
+ pools.erase(it);
+ }
+ return;
}
- return;
}
}
+
+private:
+ std::vector<Pool> pools;
+};
+
+void TextureReleaser::operator()(GLuint id) const {
+ assert(pool);
+ pool->impl->releaseTexture(id);
+}
+
+TexturePool::TexturePool() : impl(std::make_unique<Impl>()) {
+}
+
+TexturePool::~TexturePool() {
+}
+
+PooledTexture TexturePool::acquireTexture(gl::ObjectStore& store) {
+ return PooledTexture { impl->acquireTexture(store) , { this } };
}
} // namespace gl
diff --git a/src/mbgl/gl/texture_pool.hpp b/src/mbgl/gl/texture_pool.hpp
index a32ec76746..1cdcdf220c 100644
--- a/src/mbgl/gl/texture_pool.hpp
+++ b/src/mbgl/gl/texture_pool.hpp
@@ -4,33 +4,34 @@
#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/object_store.hpp>
-#include <algorithm>
+#include <unique_resource.hpp>
+
#include <memory>
-#include <vector>
namespace mbgl {
namespace gl {
+class TexturePool;
+
+struct TextureReleaser {
+ TexturePool* pool;
+ void operator()(GLuint) const;
+};
+
+using PooledTexture = std_experimental::unique_resource<GLuint, TextureReleaser>;
+
class TexturePool : private util::noncopyable {
public:
- GLuint getTextureID(gl::ObjectStore&);
- void releaseTextureID(GLuint&);
-
-private:
- class Impl : private util::noncopyable {
- public:
- Impl(gl::ObjectStore& store) : pool(store.createTexturePool()), availableIDs(gl::TextureMax) {
- std::copy(pool.get().begin(), pool.get().end(), availableIDs.begin());
- }
+ TexturePool();
+ ~TexturePool();
- Impl(Impl&& o) : pool(std::move(o.pool)), availableIDs(std::move(o.availableIDs)) {}
- Impl& operator=(Impl&& o) { pool = std::move(o.pool); availableIDs = std::move(o.availableIDs); return *this; }
+ PooledTexture acquireTexture(gl::ObjectStore&);
- gl::UniqueTexturePool pool;
- std::vector<GLuint> availableIDs;
- };
+private:
+ friend TextureReleaser;
- std::vector<Impl> pools;
+ class Impl;
+ const std::unique_ptr<Impl> impl;
};
} // namespace gl
diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp
index b89686c815..4c6ad1ba0f 100644
--- a/src/mbgl/renderer/painter_fill.cpp
+++ b/src/mbgl/renderer/painter_fill.cpp
@@ -55,7 +55,7 @@ void Painter::renderFill(FillBucket& bucket,
outlineShader->u_matrix = vtxMatrix;
config.lineWidth = 2.0f; // This is always fixed and does not depend on the pixelRatio!
- outlineShader->u_color = stroke_color;
+ outlineShader->u_outline_color = stroke_color;
outlineShader->u_opacity = opacity;
// Draw the entire line
@@ -184,7 +184,7 @@ void Painter::renderFill(FillBucket& bucket,
outlineShader->u_matrix = vtxMatrix;
config.lineWidth = 2.0f; // This is always fixed and does not depend on the pixelRatio!
- outlineShader->u_color = fill_color;
+ outlineShader->u_outline_color = fill_color;
outlineShader->u_opacity = opacity;
// Draw the entire line
diff --git a/src/mbgl/renderer/renderable.hpp b/src/mbgl/renderer/renderable.hpp
deleted file mode 100644
index 27acfc4d0d..0000000000
--- a/src/mbgl/renderer/renderable.hpp
+++ /dev/null
@@ -1,11 +0,0 @@
-#pragma once
-
-#include <mbgl/util/clip_id.hpp>
-
-namespace mbgl {
-
-struct Renderable {
- ClipID& clip;
-};
-
-} // namespace mbgl
diff --git a/src/mbgl/shader/outline_shader.hpp b/src/mbgl/shader/outline_shader.hpp
index 22b9013afd..25c873b4fe 100644
--- a/src/mbgl/shader/outline_shader.hpp
+++ b/src/mbgl/shader/outline_shader.hpp
@@ -11,10 +11,10 @@ public:
void bind(GLbyte *offset) final;
- UniformMatrix<4> u_matrix = {"u_matrix", *this};
- Uniform<std::array<GLfloat, 4>> u_color = {"u_color", *this};
- Uniform<GLfloat> u_opacity = {"u_opacity", *this};
- Uniform<std::array<GLfloat, 2>> u_world = {"u_world", *this};
+ UniformMatrix<4> u_matrix = {"u_matrix", *this};
+ Uniform<std::array<GLfloat, 4>> u_outline_color = {"u_outline_color", *this};
+ Uniform<GLfloat> u_opacity = {"u_opacity", *this};
+ Uniform<std::array<GLfloat, 2>> u_world = {"u_world", *this};
};
} // namespace mbgl
diff --git a/src/mbgl/style/layers/line_layer_properties.hpp b/src/mbgl/style/layers/line_layer_properties.hpp
index e0c63b516b..01a8534222 100644
--- a/src/mbgl/style/layers/line_layer_properties.hpp
+++ b/src/mbgl/style/layers/line_layer_properties.hpp
@@ -20,7 +20,7 @@ public:
LayoutProperty<LineCapType> lineCap { LineCapType::Butt };
LayoutProperty<LineJoinType> lineJoin { LineJoinType::Miter };
LayoutProperty<float> lineMiterLimit { 2 };
- LayoutProperty<float> lineRoundLimit { 1.05 };
+ LayoutProperty<float> lineRoundLimit { 1 };
};
class LinePaintProperties {
diff --git a/src/mbgl/style/source.hpp b/src/mbgl/style/source.hpp
index cadc45c25c..07e1aeaf58 100644
--- a/src/mbgl/style/source.hpp
+++ b/src/mbgl/style/source.hpp
@@ -4,7 +4,6 @@
#include <mbgl/tile/tile_data.hpp>
#include <mbgl/tile/tile_cache.hpp>
#include <mbgl/style/types.hpp>
-#include <mbgl/renderer/renderable.hpp>
#include <mbgl/util/mat4.hpp>
#include <mbgl/util/rapidjson.hpp>
diff --git a/src/mbgl/util/assert.hpp b/src/mbgl/util/assert.hpp
deleted file mode 100644
index 47fc13f94e..0000000000
--- a/src/mbgl/util/assert.hpp
+++ /dev/null
@@ -1,10 +0,0 @@
-#pragma once
-
-#include <cassert>
-
-// Based on FreeBSD's src/include/assert.h
-// Licensed under the original BSD license
-#define assert_always(expr) \
- ((void)((expr) ? ((void)0) : ((void)fprintf(stderr, "%s:%u: failed assertion `%s'\n", \
- __FILE__, __LINE__, #expr), \
- abort())))
diff --git a/src/mbgl/util/channel.hpp b/src/mbgl/util/channel.hpp
deleted file mode 100644
index 319205b444..0000000000
--- a/src/mbgl/util/channel.hpp
+++ /dev/null
@@ -1,36 +0,0 @@
-#pragma once
-
-#include <mbgl/util/noncopyable.hpp>
-
-#include <mutex>
-#include <condition_variable>
-#include <queue>
-
-namespace mbgl {
-
-template <class T>
-class Channel : public mbgl::util::noncopyable {
-public:
- void send(const T& t) {
- std::unique_lock<std::mutex> lock(mutex);
- queue.push(t);
- condition.notify_one();
- }
-
- T receive() {
- std::unique_lock<std::mutex> lock(mutex);
- condition.wait(lock, [&](){ return !queue.empty(); });
-
- T t = queue.front();
- queue.pop();
-
- return t;
- }
-
-private:
- std::mutex mutex;
- std::condition_variable condition;
- std::queue<T> queue;
-};
-
-}
diff --git a/src/mbgl/util/raster.cpp b/src/mbgl/util/raster.cpp
index 70fdf7b02a..3146a00513 100644
--- a/src/mbgl/util/raster.cpp
+++ b/src/mbgl/util/raster.cpp
@@ -13,12 +13,6 @@ Raster::Raster(gl::TexturePool& texturePool_)
: texturePool(texturePool_)
{}
-Raster::~Raster() {
- if (textured) {
- texturePool.releaseTextureID(textureID);
- }
-}
-
bool Raster::isLoaded() const {
std::lock_guard<std::mutex> lock(mtx);
return loaded;
@@ -42,10 +36,10 @@ void Raster::bind(bool linear, gl::ObjectStore& store) {
return;
}
- if (img.data && !textured) {
+ if (img.data && !texture) {
upload(store);
- } else if (textured) {
- MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, textureID));
+ } else if (texture) {
+ MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, *texture));
}
GLint new_filter = linear ? GL_LINEAR : GL_NEAREST;
@@ -57,15 +51,15 @@ void Raster::bind(bool linear, gl::ObjectStore& store) {
}
void Raster::upload(gl::ObjectStore& store) {
- if (img.data && !textured) {
- textureID = texturePool.getTextureID(store);
- MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, textureID));
+ if (img.data && !texture) {
+ texture = texturePool.acquireTexture(store);
+ MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, *texture));
#ifndef GL_ES_VERSION_2_0
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0));
#endif
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
- MBGL_CHECK_ERROR(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.data.release()));
- textured = true;
+ MBGL_CHECK_ERROR(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.data.get()));
+ img.data.reset();
}
}
diff --git a/src/mbgl/util/raster.hpp b/src/mbgl/util/raster.hpp
index ff16112d90..b539032d81 100644
--- a/src/mbgl/util/raster.hpp
+++ b/src/mbgl/util/raster.hpp
@@ -5,6 +5,7 @@
#include <mbgl/util/image.hpp>
#include <mbgl/util/ptr.hpp>
#include <mbgl/util/chrono.hpp>
+#include <mbgl/util/optional.hpp>
#include <mutex>
@@ -14,7 +15,6 @@ class Raster : public std::enable_shared_from_this<Raster> {
public:
Raster(gl::TexturePool&);
- ~Raster();
// load image data
void load(PremultipliedImage);
@@ -33,11 +33,8 @@ public:
GLsizei width = 0;
GLsizei height = 0;
- // has been uploaded to texture
- bool textured = false;
-
- // the uploaded texture
- GLuint textureID = 0;
+ // GL buffer object handle.
+ mbgl::optional<gl::PooledTexture> texture;
// texture opacity
double opacity = 0;