From 8a031696a154fe115983372022c142db0e877962 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 3 Jul 2014 13:36:01 +0200 Subject: 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 --- tests/auto/gui/qopengl/tst_qopengl.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'tests/auto/gui') diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp index 7de1989ada..1e8727ca04 100644 --- a/tests/auto/gui/qopengl/tst_qopengl.cpp +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -65,6 +65,8 @@ #include #endif +Q_DECLARE_METATYPE(QImage::Format) + class tst_QOpenGL : public QObject { Q_OBJECT @@ -605,7 +607,14 @@ void tst_QOpenGL::fboHandleNulledAfterContextDestroyed() void tst_QOpenGL::openGLPaintDevice_data() { - common_data(); + QTest::addColumn("surfaceClass"); + QTest::addColumn("imageFormat"); + + QTest::newRow("Using QWindow - RGB32") << int(QSurface::Window) << QImage::Format_RGB32; + QTest::newRow("Using QOffscreenSurface - RGB32") << int(QSurface::Offscreen) << QImage::Format_RGB32; + QTest::newRow("Using QOffscreenSurface - RGBx8888") << int(QSurface::Offscreen) << QImage::Format_RGBX8888; + QTest::newRow("Using QOffscreenSurface - RGB888") << int(QSurface::Offscreen) << QImage::Format_RGB888; + QTest::newRow("Using QOffscreenSurface - RGB16") << int(QSurface::Offscreen) << QImage::Format_RGB16; } void tst_QOpenGL::openGLPaintDevice() @@ -615,6 +624,7 @@ void tst_QOpenGL::openGLPaintDevice() #endif QFETCH(int, surfaceClass); + QFETCH(QImage::Format, imageFormat); QScopedPointer surface(createSurface(surfaceClass)); QOpenGLContext ctx; @@ -627,7 +637,7 @@ void tst_QOpenGL::openGLPaintDevice() const QSize size(128, 128); - QImage image(size, QImage::Format_RGB32); + QImage image(size, imageFormat); QPainter p(&image); p.fillRect(0, 0, image.width() / 2, image.height() / 2, Qt::red); p.fillRect(image.width() / 2, 0, image.width() / 2, image.height() / 2, Qt::green); @@ -646,7 +656,7 @@ void tst_QOpenGL::openGLPaintDevice() p.fillRect(0, image.height() / 2, image.width() / 2, image.height() / 2, Qt::white); p.end(); - QImage actual = fbo.toImage().convertToFormat(QImage::Format_RGB32); + QImage actual = fbo.toImage().convertToFormat(imageFormat); QCOMPARE(image.size(), actual.size()); QCOMPARE(image, actual); @@ -655,7 +665,7 @@ void tst_QOpenGL::openGLPaintDevice() p.drawImage(0, 0, image); p.end(); - actual = fbo.toImage().convertToFormat(QImage::Format_RGB32); + actual = fbo.toImage().convertToFormat(imageFormat); QCOMPARE(image.size(), actual.size()); QCOMPARE(image, actual); @@ -664,7 +674,7 @@ void tst_QOpenGL::openGLPaintDevice() p.fillRect(0, 0, image.width(), image.height(), QBrush(image)); p.end(); - actual = fbo.toImage().convertToFormat(QImage::Format_RGB32); + actual = fbo.toImage().convertToFormat(imageFormat); QCOMPARE(image.size(), actual.size()); QCOMPARE(image, actual); } -- cgit v1.2.3