diff options
author | Laszlo Agocs <laszlo.agocs@digia.com> | 2014-03-19 15:43:49 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-20 15:51:45 +0100 |
commit | d8fb0b485a604d690504df5b44feaeba5325dd60 (patch) | |
tree | 40783d45bc47b117a61107e9ba47df647aad6568 /tests/auto/quick/qquickwindow | |
parent | a122617ac110c1d98dbf2bbde1b1b4a8d6a2ee0b (diff) |
Add defaultSurfaceFormat to QQuickWindow
This static function can be used to set a surface format that is
then picked up by all QQuickWindows, including the ones instantiated
from QML.
This introduces the ability to request higher OpenGL versions, core
profile and other options also for windows that are created from QML
via the ApplicationWindow element in Quick Controls applications.
[ChangeLog] Added QQuickWindow::setDefaultSurfaceFormat() to
set a surface format that applies to all Quick windows,
including the ones created from QML. The OpenGL shading language
version is now exposed to QML too in order to allow components
to provide the correct shader source so shader effect items.
Task-number: QTBUG-36392
Change-Id: I75a4718243d835894461f7ee0b4a383988840f9b
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
Diffstat (limited to 'tests/auto/quick/qquickwindow')
-rw-r--r-- | tests/auto/quick/qquickwindow/tst_qquickwindow.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp index 28945c4cb5..4ec479a924 100644 --- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp +++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp @@ -357,6 +357,9 @@ private slots: void contentItemSize(); + void defaultSurfaceFormat(); + void glslVersion(); + private: QTouchDevice *touchDevice; QTouchDevice *touchDeviceWithVelocity; @@ -1741,6 +1744,79 @@ void tst_qquickwindow::contentItemSize() QCOMPARE(QSizeF(rect->width(), rect->height()), size); } +void tst_qquickwindow::defaultSurfaceFormat() +{ + // It is quite difficult to verify anything for real since the resulting format after + // surface/context creation can be anything, depending on the platform and drivers, + // and many options and settings may fail in various configurations, but test at + // least using some harmless settings to check that the global, static format is + // taken into account in the requested format. + + QSurfaceFormat savedDefaultFormat = QQuickWindow::defaultFormat(); + + // Verify that depth and stencil are set, as they should be, unless they are disabled + // via environment variables. + QVERIFY(savedDefaultFormat.depthBufferSize() >= 16); + QVERIFY(savedDefaultFormat.stencilBufferSize() >= 8); + + QSurfaceFormat format = savedDefaultFormat; + format.setSwapInterval(0); + format.setRedBufferSize(8); + format.setGreenBufferSize(8); + format.setBlueBufferSize(8); + format.setProfile(QSurfaceFormat::CompatibilityProfile); + format.setOption(QSurfaceFormat::DebugContext); + QQuickWindow::setDefaultFormat(format); + + QQuickWindow window; + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + const QSurfaceFormat reqFmt = window.requestedFormat(); + QCOMPARE(format.swapInterval(), reqFmt.swapInterval()); + QCOMPARE(format.redBufferSize(), reqFmt.redBufferSize()); + QCOMPARE(format.greenBufferSize(), reqFmt.greenBufferSize()); + QCOMPARE(format.blueBufferSize(), reqFmt.blueBufferSize()); + QCOMPARE(format.profile(), reqFmt.profile()); + QCOMPARE(int(format.options()), int(reqFmt.options())); + + QQuickWindow::setDefaultFormat(savedDefaultFormat); +} + +void tst_qquickwindow::glslVersion() +{ + QQuickWindow window; + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + // Core profile is never requested by default. + QVERIFY(!window.glslIsCoreProfile()); + + // Get the format from the context, not the window. The actual OpenGL version and + // related settings are associated with the context and are only written back to the + // context's format. + QSurfaceFormat format = window.openglContext()->format(); + + if (format.renderableType() == QSurfaceFormat::OpenGL) { + if (format.majorVersion() == 2) + QCOMPARE(window.glslVersion(), QString()); + else if (format.majorVersion() == 3) + QVERIFY(window.glslVersion().startsWith('3') + || window.glslVersion() == QStringLiteral("130") + || window.glslVersion() == QStringLiteral("140") + || window.glslVersion() == QStringLiteral("150")); + else if (format.majorVersion() == 4) + QVERIFY(window.glslVersion().startsWith('4')); + QVERIFY(!window.glslVersion().contains(QStringLiteral("core"))); + QVERIFY(!window.glslVersion().contains(QStringLiteral("es"))); + } else if (format.renderableType() == QSurfaceFormat::OpenGLES) { + if (format.majorVersion() == 2) + QCOMPARE(window.glslVersion(), QString()); + else + QVERIFY(window.glslVersion().contains(QStringLiteral("es"))); + } +} + QTEST_MAIN(tst_qquickwindow) #include "tst_qquickwindow.moc" |