summaryrefslogtreecommitdiff
path: root/src/mbgl/gl
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-10-26 16:39:25 -0700
committerKonstantin Käfer <mail@kkaefer.com>2016-11-01 18:41:52 +0100
commit9e3839781fdf1b1c6a2d61a5de9b2c7ddd68e9ed (patch)
treecde9eb4e99341e5200ca5a06a4a1d0fc602c9232 /src/mbgl/gl
parente2981c890e9a758c4dee703fa9e25e5d9eff65ce (diff)
downloadqtlocation-mapboxgl-9e3839781fdf1b1c6a2d61a5de9b2c7ddd68e9ed.tar.gz
[core] convert SpriteAtlas to use managed texture handling
Diffstat (limited to 'src/mbgl/gl')
-rw-r--r--src/mbgl/gl/context.cpp12
-rw-r--r--src/mbgl/gl/context.hpp7
2 files changed, 16 insertions, 3 deletions
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp
index acecf2b698..7200b75050 100644
--- a/src/mbgl/gl/context.cpp
+++ b/src/mbgl/gl/context.cpp
@@ -185,15 +185,21 @@ Framebuffer Context::createFramebuffer(const Texture& color) {
UniqueTexture
Context::createTexture(const Size size, const void* data, TextureUnit unit) {
auto obj = createTexture();
- activeTexture = unit;
- texture[unit] = obj;
+ updateTexture(obj, size, data, unit);
+ // We are using clamp to edge here since OpenGL ES doesn't allow GL_REPEAT on NPOT textures.
+ // We use those when the pixelRatio isn't a power of two, e.g. on iPhone 6 Plus.
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));
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
+ return obj;
+}
+
+void Context::updateTexture(TextureID id, const Size size, const void* data, TextureUnit unit) {
+ activeTexture = unit;
+ texture[unit] = id;
MBGL_CHECK_ERROR(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width, size.height, 0, GL_RGBA,
GL_UNSIGNED_BYTE, data));
- return obj;
}
void Context::bindTexture(Texture& obj,
diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp
index 84c83f8d31..ae2b71994f 100644
--- a/src/mbgl/gl/context.hpp
+++ b/src/mbgl/gl/context.hpp
@@ -68,6 +68,12 @@ public:
return { image.size, createTexture(image.size, image.data.get(), unit) };
}
+ template <typename Image>
+ void updateTexture(Texture& obj, const Image& image, TextureUnit unit = 0) {
+ updateTexture(obj.texture.get(), image.size, image.data.get(), unit);
+ obj.size = image.size;
+ }
+
// Creates an empty texture with the specified dimensions.
Texture createTexture(const Size size, TextureUnit unit = 0) {
return { size, createTexture(size, nullptr, unit) };
@@ -148,6 +154,7 @@ private:
UniqueBuffer createVertexBuffer(const void* data, std::size_t size);
UniqueBuffer createIndexBuffer(const void* data, std::size_t size);
UniqueTexture createTexture(Size size, const void* data, TextureUnit);
+ void updateTexture(TextureID, Size size, const void* data, TextureUnit);
UniqueFramebuffer createFramebuffer();
UniqueRenderbuffer createRenderbuffer(RenderbufferType, Size size);