diff options
author | Allan Sandfeld Jensen <allan.jensen@digia.com> | 2013-10-24 19:50:34 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-25 14:51:30 +0200 |
commit | e1325cf26e146b68725cc1a0a02b274ce3dfbe5c (patch) | |
tree | dba5e4afa3d2079712bdbc2b63f38475f2a4d2ea /src/gui/opengl/qopengltexturecache.cpp | |
parent | 788b8aa29d9f7c13ba3755a0b3ffa2dc7833732d (diff) |
Do not byteswap RGBA8888 formats
The three RGBA8888 formats was introduced to make it possible to have
QImages and QPixmaps in native OpenGL formats, but uploaded textures of
these types are still converted to ARGB first and then swapped back.
This patch detects the formats and ensures the unneeded back-and-forth
conversion does not take place. It also replaces a seemingly unused
private API meant for the same goal.
Change-Id: Id69d6973bb9c13d1052f2a1b0c516183f63421c2
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Diffstat (limited to 'src/gui/opengl/qopengltexturecache.cpp')
-rw-r--r-- | src/gui/opengl/qopengltexturecache.cpp | 30 |
1 files changed, 2 insertions, 28 deletions
diff --git a/src/gui/opengl/qopengltexturecache.cpp b/src/gui/opengl/qopengltexturecache.cpp index 94b82885ff..4238f63cd8 100644 --- a/src/gui/opengl/qopengltexturecache.cpp +++ b/src/gui/opengl/qopengltexturecache.cpp @@ -95,10 +95,9 @@ void QOpenGLTextureCacheWrapper::cleanupTexturesForPixmapData(QPlatformPixmap *p cleanupTexturesForCacheKey(pmd->cacheKey()); } -QOpenGLTextureCache::QOpenGLTextureCache(QOpenGLContext *ctx, bool useByteSwapImage) +QOpenGLTextureCache::QOpenGLTextureCache(QOpenGLContext *ctx) : QOpenGLSharedResource(ctx->shareGroup()) , m_cache(64 * 1024) // 64 MB cache - , m_useByteSwapImage(useByteSwapImage) { } @@ -152,38 +151,13 @@ GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QImage &i return id; } -static inline void qgl_byteSwapImage(QImage &img) -{ - const int width = img.width(); - const int height = img.height(); - - if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) - { - for (int i = 0; i < height; ++i) { - uint *p = (uint *) img.scanLine(i); - for (int x = 0; x < width; ++x) - p[x] = ((p[x] << 16) & 0xff0000) | ((p[x] >> 16) & 0xff) | (p[x] & 0xff00ff00); - } - } else { - for (int i = 0; i < height; ++i) { - uint *p = (uint *) img.scanLine(i); - for (int x = 0; x < width; ++x) - p[x] = (p[x] << 8) | (p[x] >> 24); - } - } -} - GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, qint64 key, const QImage &image) { GLuint id; glGenTextures(1, &id); glBindTexture(GL_TEXTURE_2D, id); - QImage tx = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); - - // Performance could be improved by skipping qgl_byteSwapImage(). - if (m_useByteSwapImage) - qgl_byteSwapImage(tx); + QImage tx = image.convertToFormat(QImage::Format_RGBA8888_Premultiplied); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tx.width(), tx.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, const_cast<const QImage &>(tx).bits()); |