summaryrefslogtreecommitdiff
path: root/src/mbgl/text/glyph_atlas.cpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-10-26 17:32:07 -0700
committerKonstantin Käfer <mail@kkaefer.com>2016-11-01 18:41:52 +0100
commit7b50cac49f353524457e16d3f342299e0886e963 (patch)
tree22356d28417e24623c5919e3a50f5763967a53dc /src/mbgl/text/glyph_atlas.cpp
parent358701f475b2c04c4681d70435bc76370b371285 (diff)
downloadqtlocation-mapboxgl-7b50cac49f353524457e16d3f342299e0886e963.tar.gz
[core] convert GlyphAtlas to use managed texture handling
Diffstat (limited to 'src/mbgl/text/glyph_atlas.cpp')
-rw-r--r--src/mbgl/text/glyph_atlas.cpp84
1 files changed, 23 insertions, 61 deletions
diff --git a/src/mbgl/text/glyph_atlas.cpp b/src/mbgl/text/glyph_atlas.cpp
index 2f8c44db59..031e89d13a 100644
--- a/src/mbgl/text/glyph_atlas.cpp
+++ b/src/mbgl/text/glyph_atlas.cpp
@@ -1,7 +1,6 @@
#include <mbgl/text/glyph_atlas.hpp>
#include <mbgl/text/glyph_atlas_observer.hpp>
#include <mbgl/text/glyph_pbf.hpp>
-#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/platform/platform.hpp>
@@ -13,13 +12,11 @@ namespace mbgl {
static GlyphAtlasObserver nullObserver;
-GlyphAtlas::GlyphAtlas(uint16_t width_, uint16_t height_, FileSource& fileSource_)
- : width(width_),
- height(height_),
- fileSource(fileSource_),
+GlyphAtlas::GlyphAtlas(const Size size, FileSource& fileSource_)
+ : fileSource(fileSource_),
observer(&nullObserver),
- bin(width_, height_),
- data(std::make_unique<uint8_t[]>(width_ * height_)),
+ bin(size.width, size.height),
+ image(size),
dirty(true) {
}
@@ -148,18 +145,18 @@ Rect<uint16_t> GlyphAtlas::addGlyph(uintptr_t tileUID,
return rect;
}
- assert(rect.x + rect.w <= width);
- assert(rect.y + rect.h <= height);
+ assert(rect.x + rect.w <= image.size.width);
+ assert(rect.y + rect.h <= image.size.height);
face.emplace(glyph.id, GlyphValue { rect, tileUID });
// Copy the bitmap
const uint8_t* source = reinterpret_cast<const uint8_t*>(glyph.bitmap.data());
for (uint32_t y = 0; y < buffered_height; y++) {
- uint32_t y1 = width * (rect.y + y + padding) + rect.x + padding;
+ uint32_t y1 = image.size.width * (rect.y + y + padding) + rect.x + padding;
uint32_t y2 = buffered_width * y;
for (uint32_t x = 0; x < buffered_width; x++) {
- data[y1 + x] = source[y2 + x];
+ image.data[y1 + x] = source[y2 + x];
}
}
@@ -181,9 +178,9 @@ void GlyphAtlas::removeGlyphs(uintptr_t tileUID) {
const Rect<uint16_t>& rect = value.rect;
// Clear out the bitmap.
- uint8_t *target = data.get();
+ uint8_t *target = image.data.get();
for (uint32_t y = 0; y < rect.h; y++) {
- uint32_t y1 = width * (rect.y + y) + rect.x;
+ uint32_t y1 = image.size.width * (rect.y + y) + rect.x;
for (uint32_t x = 0; x < rect.w; x++) {
target[y1 + x] = 0;
}
@@ -203,60 +200,25 @@ void GlyphAtlas::removeGlyphs(uintptr_t tileUID) {
}
}
+Size GlyphAtlas::getSize() const {
+ return image.size;
+}
+
void GlyphAtlas::upload(gl::Context& context, gl::TextureUnit unit) {
- if (dirty) {
- const bool first = !texture;
- bind(context, unit);
-
- std::lock_guard<std::mutex> lock(mtx);
-
- context.activeTexture = unit;
- if (first) {
- MBGL_CHECK_ERROR(glTexImage2D(
- GL_TEXTURE_2D, // GLenum target
- 0, // GLint level
- GL_ALPHA, // GLint internalformat
- width, // GLsizei width
- height, // GLsizei height
- 0, // GLint border
- GL_ALPHA, // GLenum format
- GL_UNSIGNED_BYTE, // GLenum type
- data.get() // const GLvoid* data
- ));
- } else {
- MBGL_CHECK_ERROR(glTexSubImage2D(
- GL_TEXTURE_2D, // GLenum target
- 0, // GLint level
- 0, // GLint xoffset
- 0, // GLint yoffset
- width, // GLsizei width
- height, // GLsizei height
- GL_ALPHA, // GLenum format
- GL_UNSIGNED_BYTE, // GLenum type
- data.get() // const GLvoid* data
- ));
- }
+ std::lock_guard<std::mutex> lock(mtx);
- dirty = false;
+ if (!texture) {
+ texture = context.createTexture(image, unit);
+ } else if (dirty) {
+ context.updateTexture(*texture, image, unit);
}
+
+ dirty = false;
}
void GlyphAtlas::bind(gl::Context& context, gl::TextureUnit unit) {
- if (!texture) {
- texture = context.createTexture();
- context.activeTexture = unit;
- context.texture[unit] = *texture;
-#if not MBGL_USE_GLES2
- MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0));
-#endif
- MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
- MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
- 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));
- } else if (context.texture[unit] != *texture) {
- context.activeTexture = unit;
- context.texture[unit] = *texture;
- }
+ upload(context, unit);
+ context.bindTexture(*texture, unit, gl::TextureFilter::Linear);
}
} // namespace mbgl