summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-08-22 15:54:40 +0200
committerKonstantin Käfer <mail@kkaefer.com>2016-09-27 10:42:10 +0200
commit512037cfdc14fb1f7686254efe97b72433c5e4b6 (patch)
tree93538e0aa0bf6217bb2b57f46782d785e5061590
parent0c3abb21296e25d6b5fd8ccc139d1484524b2033 (diff)
downloadqtlocation-mapboxgl-512037cfdc14fb1f7686254efe97b72433c5e4b6.tar.gz
[core] Allow retrieving texture ID and size
-rw-r--r--src/mbgl/util/raster.cpp12
-rw-r--r--src/mbgl/util/raster.hpp8
2 files changed, 17 insertions, 3 deletions
diff --git a/src/mbgl/util/raster.cpp b/src/mbgl/util/raster.cpp
index 3f9cb467b9..535d34b105 100644
--- a/src/mbgl/util/raster.cpp
+++ b/src/mbgl/util/raster.cpp
@@ -14,9 +14,15 @@ bool Raster::isLoaded() const {
return loaded;
}
-void Raster::load(PremultipliedImage image, uint32_t mipmapLevel) {
- assert(image.data.get());
+GLuint Raster::getID() const {
+ return texture ? *texture : 0;
+}
+std::array<size_t, 2> Raster::getSize() const {
+ return size;
+}
+
+void Raster::load(PremultipliedImage image, uint32_t mipmapLevel) {
if (images.size() <= mipmapLevel) {
images.resize(mipmapLevel + 1);
}
@@ -74,11 +80,11 @@ void Raster::upload(gl::ObjectStore& store, gl::Config& config, uint32_t unit) {
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
GLint level = 0;
for (auto& img : images) {
- assert(img.data.get());
MBGL_CHECK_ERROR(glTexImage2D(
GL_TEXTURE_2D, level++, GL_RGBA, static_cast<GLsizei>(img.width),
static_cast<GLsizei>(img.height), 0, GL_RGBA, GL_UNSIGNED_BYTE, img.data.get()));
}
+ size = { { images.front().width, images.front().height } };
images.clear();
images.shrink_to_fit();
}
diff --git a/src/mbgl/util/raster.hpp b/src/mbgl/util/raster.hpp
index 34e7c67678..9d621668f4 100644
--- a/src/mbgl/util/raster.hpp
+++ b/src/mbgl/util/raster.hpp
@@ -5,6 +5,7 @@
#include <mbgl/util/optional.hpp>
#include <atomic>
+#include <array>
namespace mbgl {
@@ -33,9 +34,16 @@ public:
// loaded status
bool isLoaded() const;
+ // returns the OpenGL texture ID
+ GLuint getID() const;
+
+ // size of uploaded image.
+ std::array<size_t, 2> getSize() const;
+
private:
// raw pixels have been loaded
std::atomic<bool> loaded { false };
+ std::array<size_t, 2> size = {{ 0, 0 }};
// filters
Scaling filter = Scaling::Nearest;