summaryrefslogtreecommitdiffstats
path: root/src/gui/opengl/qopengltexturecache_p.h
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@digia.com>2014-07-03 13:36:01 +0200
committerAllan Sandfeld Jensen <allan.jensen@digia.com>2014-07-04 16:09:27 +0200
commit8a031696a154fe115983372022c142db0e877962 (patch)
treecbbe6ea6536b061a5645a64d2427941afe5ae64a /src/gui/opengl/qopengltexturecache_p.h
parent0eefa785a0d8bfe96403f9c13e80544cf8bb8eb3 (diff)
Make QOpenGLTextureCache::bindTexture upload efficiently
Currently QOpenGLTextureCache::bindTexture always convert any uploaded image to RGBA8888 before uploading. This is quite inefficient when OpenGL natively supports uploading formats in the original format. This patch adds support for uploading a few native QImage formats. This also get the performance of QOpenGLTextureCache::bindTexture on par with QGLContext::bindTexture. The texture brush used by QOpenGLPaintEngine is also converted to QImage, since bindTexture will convert it to QImage anyway, and going over QPixmap may cause an unnecessary conversion. [ChangeLog][QtGui][QOpenGLTextureCache] Support uploading common QImage formats directly to OpenGL when supported. Change-Id: I828a763126441a98e4547c32ef52dddf7c129a32 Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
Diffstat (limited to 'src/gui/opengl/qopengltexturecache_p.h')
-rw-r--r--src/gui/opengl/qopengltexturecache_p.h18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/gui/opengl/qopengltexturecache_p.h b/src/gui/opengl/qopengltexturecache_p.h
index 2e82d5f373..d81115fefc 100644
--- a/src/gui/opengl/qopengltexturecache_p.h
+++ b/src/gui/opengl/qopengltexturecache_p.h
@@ -64,13 +64,15 @@ QT_BEGIN_NAMESPACE
class QOpenGLCachedTexture
{
public:
- QOpenGLCachedTexture(GLuint id, QOpenGLContext *context);
+ QOpenGLCachedTexture(GLuint id, int options, QOpenGLContext *context);
~QOpenGLCachedTexture() { m_resource->free(); }
GLuint id() const { return m_resource->id(); }
+ int options() const { return m_options; }
private:
QOpenGLSharedResourceGuard *m_resource;
+ int m_options;
};
class Q_GUI_EXPORT QOpenGLTextureCache : public QOpenGLSharedResource
@@ -81,8 +83,14 @@ public:
QOpenGLTextureCache(QOpenGLContext *);
~QOpenGLTextureCache();
- GLuint bindTexture(QOpenGLContext *context, const QPixmap &pixmap);
- GLuint bindTexture(QOpenGLContext *context, const QImage &image);
+ enum BindOption {
+ NoBindOption = 0x0000,
+ PremultipliedAlphaBindOption = 0x0001,
+ };
+ Q_DECLARE_FLAGS(BindOptions, BindOption)
+
+ GLuint bindTexture(QOpenGLContext *context, const QPixmap &pixmap, QOpenGLTextureCache::BindOptions options = PremultipliedAlphaBindOption);
+ GLuint bindTexture(QOpenGLContext *context, const QImage &image, QOpenGLTextureCache::BindOptions options = PremultipliedAlphaBindOption);
void invalidate(qint64 key);
@@ -90,12 +98,14 @@ public:
void freeResource(QOpenGLContext *ctx);
private:
- GLuint bindTexture(QOpenGLContext *context, qint64 key, const QImage &image);
+ GLuint bindTexture(QOpenGLContext *context, qint64 key, const QImage &image, QOpenGLTextureCache::BindOptions options);
QMutex m_mutex;
QCache<quint64, QOpenGLCachedTexture> m_cache;
};
+Q_DECLARE_OPERATORS_FOR_FLAGS(QOpenGLTextureCache::BindOptions)
+
QT_END_NAMESPACE
#endif