QOpenGLTextureCache : make it possible to skip qgl_byteSwapImage

Improving performance when making texture from QImage, this commit
makes it possible to skip qgl_byteSwapImage. If gl_FragColor of fragment
shader is properly configured, qgl_byteSwapImage is not required.
Ex) gl_FragColor = texture2D(texture, textureCoord).bgra;

Change-Id: If1f2d7dc1fc1c4e583cc3f38dec95a9d29417cd2
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
This commit is contained in:
Elvis Lee 2013-01-14 11:57:22 +09:00 committed by The Qt Project
parent c0860d26a1
commit a6faecba1a
2 changed files with 7 additions and 3 deletions

View File

@ -95,9 +95,10 @@ void QOpenGLTextureCacheWrapper::cleanupTexturesForPixmapData(QPlatformPixmap *p
cleanupTexturesForCacheKey(pmd->cacheKey());
}
QOpenGLTextureCache::QOpenGLTextureCache(QOpenGLContext *ctx)
QOpenGLTextureCache::QOpenGLTextureCache(QOpenGLContext *ctx, bool useByteSwapImage)
: QOpenGLSharedResource(ctx->shareGroup())
, m_cache(64 * 1024) // 64 MB cache
, m_useByteSwapImage(useByteSwapImage)
{
}
@ -180,7 +181,9 @@ GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, qint64 key, con
QImage tx = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
qgl_byteSwapImage(tx);
// Performance could be improved by skipping qgl_byteSwapImage().
if (m_useByteSwapImage)
qgl_byteSwapImage(tx);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tx.width(), tx.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, const_cast<const QImage &>(tx).bits());

View File

@ -78,7 +78,7 @@ class Q_GUI_EXPORT QOpenGLTextureCache : public QOpenGLSharedResource
public:
static QOpenGLTextureCache *cacheForContext(QOpenGLContext *context);
QOpenGLTextureCache(QOpenGLContext *);
QOpenGLTextureCache(QOpenGLContext *, bool useByteSwapImage = true);
~QOpenGLTextureCache();
GLuint bindTexture(QOpenGLContext *context, const QPixmap &pixmap);
@ -94,6 +94,7 @@ private:
QMutex m_mutex;
QCache<quint64, QOpenGLCachedTexture> m_cache;
bool m_useByteSwapImage;
};
QT_END_NAMESPACE