diff options
Diffstat (limited to 'tests/auto/gui/qopengl')
-rw-r--r-- | tests/auto/gui/qopengl/qopengl.pro | 2 | ||||
-rw-r--r-- | tests/auto/gui/qopengl/tst_qopengl.cpp | 79 |
2 files changed, 72 insertions, 9 deletions
diff --git a/tests/auto/gui/qopengl/qopengl.pro b/tests/auto/gui/qopengl/qopengl.pro index aaef6e5125..d744d37280 100644 --- a/tests/auto/gui/qopengl/qopengl.pro +++ b/tests/auto/gui/qopengl/qopengl.pro @@ -8,4 +8,4 @@ QT += gui-private core-private testlib SOURCES += tst_qopengl.cpp -linux:qtConfig(xcb-glx):qtConfig(xcb-xlib):!qtConfig(egl): DEFINES += USE_GLX +linux:qtConfig(xcb):qtConfig(xcb-glx):qtConfig(xcb-xlib):!qtConfig(egl): DEFINES += USE_GLX diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp index 4cdd8202e9..6d9456fa69 100644 --- a/tests/auto/gui/qopengl/tst_qopengl.cpp +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -67,6 +67,7 @@ class tst_QOpenGL : public QObject Q_OBJECT private slots: + void initTestCase(); void sharedResourceCleanup_data(); void sharedResourceCleanup(); void multiGroupSharedResourceCleanup_data(); @@ -86,6 +87,7 @@ private slots: void fboMRT_differentFormats(); void openGLPaintDevice_data(); void openGLPaintDevice(); + void openGLPaintDeviceWithChangingContext(); void aboutToBeDestroyed(); void sizeLessWindow(); void QTBUG15621_triangulatingStrokerDivZero(); @@ -204,6 +206,12 @@ static QSurface *createSurface(int surfaceClass) return 0; } +void tst_QOpenGL::initTestCase() +{ + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)) + QSKIP("OpenGL is not supported on this platform."); +} + static void common_data() { QTest::addColumn<int>("surfaceClass"); @@ -949,6 +957,14 @@ void tst_QOpenGL::openGLPaintDevice_data() QTest::newRow("Using QOffscreenSurface - RGB16") << int(QSurface::Offscreen) << QImage::Format_RGB16; } +static void drawColoredRects(QPainter *p, const QSize &size) +{ + p->fillRect(0, 0, size.width() / 2, size.height() / 2, Qt::red); + p->fillRect(size.width() / 2, 0, size.width() / 2, size.height() / 2, Qt::green); + p->fillRect(size.width() / 2, size.height() / 2, size.width() / 2, size.height() / 2, Qt::blue); + p->fillRect(0, size.height() / 2, size.width() / 2, size.height() / 2, Qt::white); +} + void tst_QOpenGL::openGLPaintDevice() { #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(__x86_64__) @@ -971,10 +987,7 @@ void tst_QOpenGL::openGLPaintDevice() 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); - p.fillRect(image.width() / 2, image.height() / 2, image.width() / 2, image.height() / 2, Qt::blue); - p.fillRect(0, image.height() / 2, image.width() / 2, image.height() / 2, Qt::white); + drawColoredRects(&p, image.size()); p.end(); QOpenGLFramebufferObject fbo(size); @@ -982,10 +995,7 @@ void tst_QOpenGL::openGLPaintDevice() QOpenGLPaintDevice device(size); QVERIFY(p.begin(&device)); - 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); - p.fillRect(image.width() / 2, image.height() / 2, image.width() / 2, image.height() / 2, Qt::blue); - p.fillRect(0, image.height() / 2, image.width() / 2, image.height() / 2, Qt::white); + drawColoredRects(&p, image.size()); p.end(); QImage actual = fbo.toImage().convertToFormat(imageFormat); @@ -1011,6 +1021,59 @@ void tst_QOpenGL::openGLPaintDevice() QCOMPARE(image, actual); } +void tst_QOpenGL::openGLPaintDeviceWithChangingContext() +{ + QScopedPointer<QSurface> surface(createSurface(QSurface::Window)); + const QSize size(512, 512); + + // QOpenGLPaintDevice has a thread-local paint engine. Therefore render + // twice, with a different context and device. Under the hood it will + // still use the same paint engine! + + QOpenGLContext ctx; + QVERIFY(ctx.create()); + QVERIFY(ctx.makeCurrent(surface.data())); + + QOpenGLFramebufferObject fbo(size); + QVERIFY(fbo.bind()); + + QOpenGLPaintDevice device(size); + + QPainter p; + QVERIFY(p.begin(&device)); + drawColoredRects(&p, size); + p.end(); + + QImage img1 = fbo.toImage(); + + QOpenGLContext ctx2; + // When supported, test the special case, where the second context is + // totally incompatible due to being a core profile one. + QSurfaceFormat coreFormat; + coreFormat.setVersion(3, 2); + coreFormat.setProfile(QSurfaceFormat::CoreProfile); + ctx2.setFormat(coreFormat); + if (!ctx2.create() || !ctx2.makeCurrent(surface.data())) { + ctx2.setFormat(QSurfaceFormat()); + QVERIFY(ctx2.create()); + } + + QVERIFY(ctx2.makeCurrent(surface.data())); + + QOpenGLFramebufferObject fbo2(size); + QVERIFY(fbo2.bind()); + + QOpenGLPaintDevice device2(size); + + QVERIFY(p.begin(&device2)); + drawColoredRects(&p, size); + p.end(); + + QImage img2 = fbo2.toImage(); + + QFUZZY_COMPARE_IMAGES(img1, img2); +} + void tst_QOpenGL::aboutToBeDestroyed() { QWindow window; |