diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-11-04 17:50:42 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-11-04 21:24:05 +0100 |
commit | 7b772611d576ed99b148208c21824bb089663599 (patch) | |
tree | c693f89323fd309ac63a982e2510464603b11e35 /src/mbgl | |
parent | 29c5c13aa2860a0e8c1ac9a826b08330708d3f29 (diff) | |
download | qtlocation-mapboxgl-7b772611d576ed99b148208c21824bb089663599.tar.gz |
[core] move pixel blitting to gl::Context
Diffstat (limited to 'src/mbgl')
-rw-r--r-- | src/mbgl/gl/context.cpp | 11 | ||||
-rw-r--r-- | src/mbgl/gl/context.hpp | 11 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_debug.cpp | 9 |
3 files changed, 24 insertions, 7 deletions
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index 811a038caf..c63819bc03 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -118,6 +118,17 @@ std::unique_ptr<uint8_t[]> Context::readFramebuffer(const Size size, const Textu return data; } +#if not MBGL_USE_GLES2 +void Context::drawPixels(const Size size, const void* data, TextureFormat format) { + pixelStoreUnpack = { 1 }; + if (format != TextureFormat::RGBA) { + format = static_cast<TextureFormat>(GL_LUMINANCE); + } + MBGL_CHECK_ERROR(glDrawPixels(size.width, size.height, static_cast<GLenum>(GL_LUMINANCE), + GL_UNSIGNED_BYTE, data)); +} +#endif // MBGL_USE_GLES2 + namespace { void checkFramebuffer() { diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index 169aa5566e..438450fe14 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -71,6 +71,14 @@ public: return { size, readFramebuffer(size, format, flip) }; } +#if not MBGL_USE_GLES2 + template <typename Image> + void drawPixels(const Image& image) { + auto format = image.channels == 4 ? TextureFormat::RGBA : TextureFormat::Alpha; + drawPixels(image.size, image.data.get(), format); + } +#endif // MBGL_USE_GLES2 + // Create a texture from an image with data. template <typename Image> Texture createTexture(const Image& image, TextureUnit unit = 0) { @@ -177,6 +185,9 @@ private: UniqueFramebuffer createFramebuffer(); UniqueRenderbuffer createRenderbuffer(RenderbufferType, Size size); std::unique_ptr<uint8_t[]> readFramebuffer(Size, TextureFormat, bool flip); +#if not MBGL_USE_GLES2 + void drawPixels(Size size, const void* data, TextureFormat); +#endif // MBGL_USE_GLES2 PrimitiveType operator()(const Points&); PrimitiveType operator()(const Lines&); diff --git a/src/mbgl/renderer/painter_debug.cpp b/src/mbgl/renderer/painter_debug.cpp index dfb1581bab..c290f9b04b 100644 --- a/src/mbgl/renderer/painter_debug.cpp +++ b/src/mbgl/renderer/painter_debug.cpp @@ -8,7 +8,6 @@ #include <mbgl/shader/fill_uniforms.hpp> #include <mbgl/util/string.hpp> #include <mbgl/gl/debugging.hpp> -#include <mbgl/gl/gl.hpp> #include <mbgl/util/color.hpp> namespace mbgl { @@ -86,9 +85,7 @@ void Painter::renderClipMasks(PaintParameters&) { context.pixelZoom = { 1, 1 }; context.rasterPos = { -1, -1, 0, 1 }; - context.pixelStoreUnpack = { 1 }; - MBGL_CHECK_ERROR(glDrawPixels(viewport.size.width, viewport.size.height, GL_LUMINANCE, - GL_UNSIGNED_BYTE, image.data.get())); + context.drawPixels(image); #endif // MBGL_USE_GLES2 } @@ -111,9 +108,7 @@ void Painter::renderDepthBuffer(PaintParameters&) { context.pixelZoom = { 1, 1 }; context.rasterPos = { -1, -1, 0, 1 }; - context.pixelStoreUnpack = { 1 }; - MBGL_CHECK_ERROR(glDrawPixels(viewport.size.width, viewport.size.height, GL_LUMINANCE, - GL_UNSIGNED_BYTE, image.data.get())); + context.drawPixels(image); #endif // MBGL_USE_GLES2 } #endif // NDEBUG |