From 2cebf523aa099c8b6f8bf164756575dc191f6bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Sat, 13 Dec 2014 14:43:56 +0100 Subject: [PATCH] Store shadows in GL_R8 textures when possible --- scene_opengl.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/scene_opengl.cpp b/scene_opengl.cpp index 80cfc88f8d..78d79befb0 100644 --- a/scene_opengl.cpp +++ b/scene_opengl.cpp @@ -2250,9 +2250,37 @@ bool SceneOpenGLShadow::prepareBackend() p.drawPixmap(bottomLeft.width() + bottom.width(), topRight.height() + right.height(), shadowPixmap(ShadowElementBottomRight)); p.end(); + // Check if the image is alpha-only in practice, and if so convert it to an 8-bpp format + if (!GLPlatform::instance()->isGLES() && GLTexture::supportsSwizzle()) { + QImage alphaImage(image.size(), QImage::Format_Indexed8); // Change to Format_Alpha8 w/ Qt 5.5 + bool alphaOnly = true; + + for (ptrdiff_t y = 0; alphaOnly && y < image.height(); y++) { + const uint32_t * const src = reinterpret_cast(image.scanLine(y)); + uint8_t * const dst = reinterpret_cast(alphaImage.scanLine(y)); + + for (ptrdiff_t x = 0; x < image.width(); x++) { + if (src[x] & 0x00ffffff) + alphaOnly = false; + + dst[x] = qAlpha(src[x]); + } + } + + if (alphaOnly) { + image = alphaImage; + } + } + effects->makeOpenGLContextCurrent(); m_texture = QSharedPointer::create(image); + if (m_texture->internalFormat() == GL_R8) { + // Swizzle red to alpha and all other channels to zero + m_texture->bind(); + m_texture->setSwizzle(GL_ZERO, GL_ZERO, GL_ZERO, GL_RED); + } + return true; }