summaryrefslogtreecommitdiff
path: root/src/mbgl/geometry/line_atlas.cpp
diff options
context:
space:
mode:
authorAnsis Brammanis <brammanis@gmail.com>2015-01-14 23:09:14 -0500
committerAnsis Brammanis <brammanis@gmail.com>2015-01-14 23:09:14 -0500
commitb66f4e2c4b21ee6e028610f4fddf8f22bb2ba5e2 (patch)
tree05cbf4cc2b3383b049bdef7a2bfc1cf3f91bab46 /src/mbgl/geometry/line_atlas.cpp
parent4f827c21c62e9059cdfc108d2275ec99f639566c (diff)
downloadqtlocation-mapboxgl-b66f4e2c4b21ee6e028610f4fddf8f22bb2ba5e2.tar.gz
use TexSubImage2D for line atlas updates
Diffstat (limited to 'src/mbgl/geometry/line_atlas.cpp')
-rw-r--r--src/mbgl/geometry/line_atlas.cpp51
1 files changed, 42 insertions, 9 deletions
diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp
index 45fcde99d4..7485ef31a7 100644
--- a/src/mbgl/geometry/line_atlas.cpp
+++ b/src/mbgl/geometry/line_atlas.cpp
@@ -15,9 +15,15 @@ LineAtlas::LineAtlas(uint16_t w, uint16_t h)
}
LineAtlas::~LineAtlas() {
+ std::lock_guard<std::recursive_mutex> lock(mtx);
+
+ MBGL_CHECK_ERROR(glDeleteTextures(1, &texture));
+ texture = 0;
}
LinePatternPos LineAtlas::getDashPosition(const std::vector<float> &dasharray, bool round) {
+ std::lock_guard<std::recursive_mutex> lock(mtx);
+
std::ostringstream sskey;
for (const float &part : dasharray) {
@@ -103,21 +109,48 @@ LinePatternPos LineAtlas::addDash(const std::vector<float> &dasharray, bool roun
};
void LineAtlas::bind() {
+ bool first = false;
if (!texture) {
- glGenTextures(1, &texture);
- glBindTexture(GL_TEXTURE_2D, texture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ MBGL_CHECK_ERROR(glGenTextures(1, &texture));
+ MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture));
+ 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_REPEAT));
+ MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
dirty = true;
} else {
- glBindTexture(GL_TEXTURE_2D, texture);
+ MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture));
}
- dirty = true;
-
if (dirty) {
+ std::lock_guard<std::recursive_mutex> lock(mtx);
+ if (first) {
+ 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
+ );
+ }
+
+
// TODO use texsubimage for updates
// TODO lock?
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data);