Merge pull request #429 from mapbox/texture-updates

Use texSubImage2D to avoid texture memory reallocation
This commit is contained in:
Konstantin Käfer
2014-08-19 11:52:35 +02:00
2 changed files with 30 additions and 3 deletions

View File

@@ -122,10 +122,36 @@ void GlyphAtlas::removeGlyphs(uint64_t tile_id) {
void GlyphAtlas::upload() {
if (dirty) {
const bool exists = texture;
bind();
std::lock_guard<std::mutex> lock(mtx);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data);
if (!exists) {
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 // const GLvoid * data
);
} else {
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 // const GLvoid *pixels
);
}
dirty = false;
#if defined(DEBUG)

View File

@@ -215,7 +215,7 @@ void SpriteAtlas::bind(bool linear) {
void SpriteAtlas::upload() {
if (dirty) {
bool exists = texture;
const bool exists = texture;
bind(filter); // Make sure we don't change the filter value.
std::lock_guard<std::mutex> lock(mtx);
@@ -234,7 +234,8 @@ void SpriteAtlas::upload() {
data // const GLvoid * data
);
} else {
glTexSubImage2D(GL_TEXTURE_2D, // GLenum target
glTexSubImage2D(
GL_TEXTURE_2D, // GLenum target
0, // GLint level
0, // GLint xoffset
0, // GLint yoffset