summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPasi Keränen <pasi.keranen@qt.io>2019-06-04 07:44:46 +0300
committerPasi Keränen <pasi.keranen@qt.io>2019-06-06 07:29:59 +0300
commit765dcd24261026c3fc625cabaf25d7aad35e00c5 (patch)
tree8a0ef12126bbe187eecd3fe3d3128e8d88ccb11e
parent33d8c8e8eae5dcf14dcaacca1d9fafcf9ba46759 (diff)
Add Runtime 2 style surfaceFormat method to API
Task-number: QT3DS-3302 Change-Id: Iab3614d8a77a89588ed8dc2ffcd184a0539c31c7 Reviewed-by: Jari Karppinen <jari.karppinen@qt.io> Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
-rw-r--r--src/Runtime/ogl-runtime/src/api/studio3d/qstudio3dglobal.h12
-rw-r--r--src/Runtime/ogl-runtime/src/api/studio3d/studio3d.pro12
-rw-r--r--src/Runtime/ogl-runtime/src/foundation/qt/formatdiscovery.cpp126
3 files changed, 148 insertions, 2 deletions
diff --git a/src/Runtime/ogl-runtime/src/api/studio3d/qstudio3dglobal.h b/src/Runtime/ogl-runtime/src/api/studio3d/qstudio3dglobal.h
index d1960634..52b49ad1 100644
--- a/src/Runtime/ogl-runtime/src/api/studio3d/qstudio3dglobal.h
+++ b/src/Runtime/ogl-runtime/src/api/studio3d/qstudio3dglobal.h
@@ -31,6 +31,7 @@
#define QSTUDIO3D_GLOBAL_H
#include <QtCore/qglobal.h>
+#include <QtGui/qsurfaceformat.h>
QT_BEGIN_NAMESPACE
@@ -44,6 +45,17 @@ QT_BEGIN_NAMESPACE
# define Q_STUDIO3D_EXPORT
#endif
+namespace Q3DS {
+/*!
+ * \brief surfaceFormat Detects highest available OpenGL or OpenGL ES version and pre-configures
+ * \l {QSurfaceFormat} that uses that OpenGL version and has 24-bit depth buffer and 8-bit stencil
+ * buffer attachments.
+ * \return Best fit \l {QSurfaceFormat} for the platform.
+ * \note This method requires that \l {QGuiApplication} has already been created.
+ */
+Q_STUDIO3D_EXPORT QSurfaceFormat surfaceFormat();
+}
+
QT_END_NAMESPACE
#endif // QSTUDIO3D_GLOBAL_H
diff --git a/src/Runtime/ogl-runtime/src/api/studio3d/studio3d.pro b/src/Runtime/ogl-runtime/src/api/studio3d/studio3d.pro
index 62d0613f..8b9fbb03 100644
--- a/src/Runtime/ogl-runtime/src/api/studio3d/studio3d.pro
+++ b/src/Runtime/ogl-runtime/src/api/studio3d/studio3d.pro
@@ -51,6 +51,14 @@ SOURCES += q3dsdataoutput.cpp \
q3dsdatainput.cpp \
q3dsgeometry.cpp
-load(qt_module)
+# Platform specific surface format discovery functions
+#TODO: QT3DS-3608 Implement OpenGL version discovery for Windows
+#TODO: QT3DS-3609 Implement OpenGL version discovery for Linux
+#TODO: QT3DS-3610 Implement OpenGL version discovery for QNX
+#TODO: QT3DS-3611 Implement OpenGL version discovery for Integrity
+#TODO: QT3DS-3612 Implement OpenGL version discovery for macOS
+#TODO: QT3DS-3613 Implement OpenGL version discovery for Android
+SOURCES += \
+ ../../foundation/qt/formatdiscovery.cpp
-OTHER_FILES += $$PWD/../../../doc/src/12-cpp-reference/*
+load(qt_module)
diff --git a/src/Runtime/ogl-runtime/src/foundation/qt/formatdiscovery.cpp b/src/Runtime/ogl-runtime/src/foundation/qt/formatdiscovery.cpp
new file mode 100644
index 00000000..7ea762b2
--- /dev/null
+++ b/src/Runtime/ogl-runtime/src/foundation/qt/formatdiscovery.cpp
@@ -0,0 +1,126 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of Qt 3D Studio.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/qopenglcontext.h>
+#include <QtGui/qoffscreensurface.h>
+#include <QtGui/qopenglfunctions.h>
+#include <QtGui/qopengltexture.h>
+
+#include "qstudio3dglobal.h"
+#include "Qt3DSFoundation.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace Q3DS {
+
+static QSurfaceFormat findIdealGLVersion()
+{
+ QSurfaceFormat fmt;
+ fmt.setProfile(QSurfaceFormat::CoreProfile);
+
+ // Advanced: Try 4.3 core (so we get compute shaders for instance)
+ fmt.setVersion(4, 3);
+ QOpenGLContext ctx;
+ ctx.setFormat(fmt);
+ if (ctx.create() && ctx.format().version() >= qMakePair(4, 3)) {
+ qDebug("Requesting OpenGL 4.3 core context succeeded");
+ return ctx.format();
+ }
+
+ // Basic: Stick with 3.3 for now to keep less fortunate, Mesa-based systems happy
+ fmt.setVersion(3, 3);
+ ctx.setFormat(fmt);
+ if (ctx.create() && ctx.format().version() >= qMakePair(3, 3)) {
+ qDebug("Requesting OpenGL 3.3 core context succeeded");
+ return ctx.format();
+ }
+
+ qWarning("Failed to get OpenGL 3.3 or OpenGL 4.3 context!");
+ return fmt;
+}
+
+static QSurfaceFormat findIdealGLESVersion()
+{
+ QSurfaceFormat fmt;
+
+ // Advanced: Try 3.1 (so we get compute shaders for instance)
+ fmt.setVersion(3, 1);
+ QOpenGLContext ctx;
+ ctx.setFormat(fmt);
+
+ // Now, it's important to check the format with the actual version (parsed
+ // back from GL_VERSION) since some implementations, ANGLE for instance,
+ // are broken and succeed the 3.1 context request even though they only
+ // support and return a 3.0 context. This is against the spec since 3.0 is
+ // obviously not backwards compatible with 3.1, but hey...
+ if (ctx.create() && ctx.format().version() >= qMakePair(3, 1)) {
+ qDebug("Requesting OpenGL ES 3.1 context succeeded");
+ return ctx.format();
+ }
+
+ // Basic: OpenGL ES 3.0 is a hard requirement at the moment since we can
+ // only generate 300 ES shaders, uniform buffers are mandatory.
+ fmt.setVersion(3, 0);
+ ctx.setFormat(fmt);
+ if (ctx.create() && ctx.format().version() >= qMakePair(3, 0)) {
+ qDebug("Requesting OpenGL ES 3.0 context succeeded");
+ return ctx.format();
+ }
+
+ fmt.setVersion(2, 0);
+ ctx.setFormat(fmt);
+ if (ctx.create()) {
+ qDebug("Requesting OpenGL ES 2.0 context succeeded");
+ return fmt;
+ }
+
+ qWarning("Failed to get OpenGL ES 2.0, 3.0 or 3.1 context");
+ return fmt;
+}
+
+QSurfaceFormat surfaceFormat()
+{
+ static const QSurfaceFormat f = [] {
+ QSurfaceFormat fmt;
+ // works in dynamic gl builds too because there's a qguiapp already
+ // this requirement is also a problem, see QT3DS-3603
+ if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL)
+ fmt = findIdealGLVersion();
+ else
+ fmt = findIdealGLESVersion();
+ fmt.setDepthBufferSize(24);
+ fmt.setStencilBufferSize(8);
+ // Ignore MSAA here as that is a per-layer setting.
+ return fmt;
+ }();
+ return f;
+}
+} // End namespace Q3DS
+
+QT_END_NAMESPACE