From 9e3839781fdf1b1c6a2d61a5de9b2c7ddd68e9ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Wed, 26 Oct 2016 16:39:25 -0700 Subject: [core] convert SpriteAtlas to use managed texture handling --- src/mbgl/gl/context.cpp | 12 +++++++++--- src/mbgl/gl/context.hpp | 7 +++++++ 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src/mbgl/gl') 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 + 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); -- cgit v1.2.1