From ce08b106c4183946f19de46ad8a83b953ac1efc9 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Fri, 6 Jan 2012 17:11:11 +0100 Subject: Avoid storing a deep copy of the image in the texture object Change-Id: I605445ea23493fd562a7fe2b3cc841ad21e5b08b Reviewed-by: Lars Knoll --- src/quick/scenegraph/util/qsgtexture.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/quick/scenegraph/util/qsgtexture.cpp b/src/quick/scenegraph/util/qsgtexture.cpp index 0abbc8dae1..a732c5ab06 100644 --- a/src/quick/scenegraph/util/qsgtexture.cpp +++ b/src/quick/scenegraph/util/qsgtexture.cpp @@ -415,11 +415,7 @@ static void swizzleBGRAToRGBA(QImage *image) void QSGPlainTexture::setImage(const QImage &image) { - m_image = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); -#ifdef QT_OPENGL_ES - swizzleBGRAToRGBA(&m_image); -#endif - + m_image = image; m_texture_size = image.size(); m_has_alpha = image.hasAlphaChannel(); m_dirty_texture = true; @@ -496,10 +492,15 @@ void QSGPlainTexture::bind() int w = m_image.width(); int h = m_image.height(); + QImage tmp = (m_image.format() == QImage::Format_RGB32 || m_image.format() == QImage::Format_ARGB32_Premultiplied) + ? m_image + : m_image.convertToFormat(QImage::Format_ARGB32_Premultiplied); + #ifdef QT_OPENGL_ES - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_image.constBits()); + swizzleBGRAToRGBA(&tmp); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmp.constBits()); #else - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, m_image.constBits()); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, tmp.constBits()); #endif if (m_has_mipmaps) { -- cgit v1.2.3