From 512037cfdc14fb1f7686254efe97b72433c5e4b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Mon, 22 Aug 2016 15:54:40 +0200 Subject: [PATCH] [core] Allow retrieving texture ID and size --- src/mbgl/util/raster.cpp | 12 +++++++++--- src/mbgl/util/raster.hpp | 8 ++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/mbgl/util/raster.cpp b/src/mbgl/util/raster.cpp index 3f9cb467b..535d34b10 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 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(img.width), static_cast(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 34e7c6767..9d621668f 100644 --- a/src/mbgl/util/raster.hpp +++ b/src/mbgl/util/raster.hpp @@ -5,6 +5,7 @@ #include #include +#include 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 getSize() const; + private: // raw pixels have been loaded std::atomic loaded { false }; + std::array size = {{ 0, 0 }}; // filters Scaling filter = Scaling::Nearest;