[core] Allow retrieving texture ID and size

This commit is contained in:
Konstantin Käfer
2016-08-22 15:54:40 +02:00
parent 0c3abb2129
commit 512037cfdc
2 changed files with 17 additions and 3 deletions

View File

@@ -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();
}

View File

@@ -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;