}
/*!
- \brief QQuickWindow::glslVersion
- \since 5.4
- \return The OpenGL Shading Language version for this window.
-
- QML components that need to be usable on different platforms and environments may need
- to deal with different OpenGL versions if they include ShaderEffect items. The source
- code for a given shader may not be compatible with an OpenGL context that targets a
- different OpenGL version or profile, hence it might be necessary to provide multiple
- versions of the shader. This property helps in deciding which shader source should be
- chosen.
-
- The value corresponds to GLSL version declarations, for example an OpenGL 4.2 core
- profile context will result in the value \e{420 core}, while an OpenGL ES 3.0 context
- gives \e{300 es}. For OpenGL (ES) 2 the value will be an empty string since the
- corresponding shading language does not use version declarations.
-
- \note The value does not necessarily indicate that the shader source must target that
- specific version. For example, compatibility profiles and ES 3.x all allow using
- OpenGL 2 style shaders. The most important for reusable components is to check for
- core profiles since these do not accept shaders with the old syntax.
-
- \sa setFormat(), glslIsCoreProfile()
- */
-QString QQuickWindow::glslVersion() const
-{
- QString ver;
- QOpenGLContext *ctx = openglContext();
- if (ctx) {
- const QSurfaceFormat fmt = ctx->format();
- if (fmt.renderableType() == QSurfaceFormat::OpenGLES
- && fmt.majorVersion() >= 3) {
- ver += QLatin1Char(fmt.majorVersion() + '0');
- ver += QLatin1Char(fmt.minorVersion() + '0');
- ver += QLatin1String("0 es");
- } else if (fmt.renderableType() == QSurfaceFormat::OpenGL
- && fmt.majorVersion() >= 3) {
- if (fmt.version() == qMakePair(3, 0)) {
- ver = QStringLiteral("130");
- } else if (fmt.version() == qMakePair(3, 1)) {
- ver = QStringLiteral("140");
- } else if (fmt.version() == qMakePair(3, 2)) {
- ver = QStringLiteral("150");
- } else {
- ver += QLatin1Char(fmt.majorVersion() + '0');
- ver += QLatin1Char(fmt.minorVersion() + '0');
- ver += QLatin1Char('0');
- }
- if (fmt.version() >= qMakePair(3, 2)) {
- if (fmt.profile() == QSurfaceFormat::CoreProfile)
- ver += QStringLiteral(" core");
- else if (fmt.profile() == QSurfaceFormat::CompatibilityProfile)
- ver += QStringLiteral(" compatibility");
- }
- }
- }
- return ver;
-}
-
-/*!
- \brief QQuickWindow::glslIsCoreProfile
- \since 5.4
- \return True if the window is rendering using OpenGL core profile.
-
- This is convenience function to check if the window's OpenGL context is a core profile
- context. It is more efficient to perform the check via this function than parsing the
- string returned from glslVersion().
-
- Resusable QML components will typically use this function in bindings in order to
- choose between core and non core profile compatible shader sources.
-
- To retrieve more information about the shading language, use glslVersion().
-
- \sa glslVersion(), setFormat()
- */
-bool QQuickWindow::glslIsCoreProfile() const
-{
- QOpenGLContext *ctx = openglContext();
- return ctx ? ctx->format().profile() == QSurfaceFormat::CoreProfile : false;
-}
-
-/*!
\qmlproperty string Window::title
The window's title in the windowing system.
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
Q_PROPERTY(QQuickItem* contentItem READ contentItem CONSTANT)
Q_PROPERTY(QQuickItem* activeFocusItem READ activeFocusItem NOTIFY activeFocusItemChanged REVISION 1)
- Q_PROPERTY(QString glslVersion READ glslVersion CONSTANT REVISION 2)
- Q_PROPERTY(bool glslIsCoreProfile READ glslIsCoreProfile CONSTANT REVISION 2)
Q_CLASSINFO("DefaultProperty", "data")
Q_DECLARE_PRIVATE(QQuickWindow)
public:
QOpenGLContext *openglContext() const;
- QString glslVersion() const;
- bool glslIsCoreProfile() const;
-
void scheduleRenderJob(QRunnable *job, RenderStage schedule);
static QQuickWindowAttached *qmlAttachedProperties(QObject *object);
void contentItemSize();
void defaultSurfaceFormat();
- void glslVersion();
void attachedProperty();
QSurfaceFormat::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")));
- }
-}
-
void tst_qquickwindow::attachedProperty()
{
QQuickView view(testFileUrl("windowattached.qml"));