summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@digia.com>2014-08-07 16:45:05 +0200
committerLaszlo Agocs <laszlo.agocs@digia.com>2014-08-08 07:29:29 +0200
commit22e439141384f49028770d2410fafb18ef8cad1f (patch)
treed30ada7a9da27083c464948654ad1d87b21d1f65 /src/gui/kernel
parent41a7072195eef0f7daa94d0ce75a3f68e721d1cb (diff)
Add default format to QSurfaceFormat
Add defaultFormat() and setDefaultFormat() statics to QSurfaceFormat. These define the default values for the requestedFormat members of QOpenGLContext, QWindow and QOpenGLWidget (and implicitly QOpenGLWindow, QQuickWindow, etc.) This replaces QQuickWindow::setDefaultFormat() which can now be removed. The main inspiration here is not the convenience (avoiding setFormat() calls for all windows/widgets), but robustness: by setting the format once at the start of the application, all windows and contexts, including the internal share context used by QOpenGLWidget and QQuickWidget, will use the same format, eliminating the possibility of failing due to trying to share between incompatible contexts. Furthermore, since such a functionality is anyway mandatory for QQuickWindow (due to the possibility of creating windows from QML code), extending it to QSurfaceFormat and QOpenGLContext/QWindow is the next logical step. Change-Id: Ie94486adc489d17fecfcebb7050fecedffd2688b Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qopenglcontext.cpp6
-rw-r--r--src/gui/kernel/qopenglcontext_p.h1
-rw-r--r--src/gui/kernel/qsurfaceformat.cpp40
-rw-r--r--src/gui/kernel/qsurfaceformat.h3
-rw-r--r--src/gui/kernel/qwindow.cpp10
5 files changed, 59 insertions, 1 deletions
diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp
index f6273fc6dd..71a1d1e074 100644
--- a/src/gui/kernel/qopenglcontext.cpp
+++ b/src/gui/kernel/qopenglcontext.cpp
@@ -489,6 +489,12 @@ QOpenGLContext::QOpenGLContext(QObject *parent)
/*!
Sets the \a format the OpenGL context should be compatible with. You need
to call create() before it takes effect.
+
+ When the format is not explicitly set via this function, the format returned
+ by QSurfaceFormat::defaultFormat() will be used. This means that when having
+ multiple contexts, individual calls to this function can be replaced by one
+ single call to QSurfaceFormat::setDefaultFormat() before creating the first
+ context.
*/
void QOpenGLContext::setFormat(const QSurfaceFormat &format)
{
diff --git a/src/gui/kernel/qopenglcontext_p.h b/src/gui/kernel/qopenglcontext_p.h
index 4447df5294..46e1572376 100644
--- a/src/gui/kernel/qopenglcontext_p.h
+++ b/src/gui/kernel/qopenglcontext_p.h
@@ -211,6 +211,7 @@ public:
, workaround_missingPrecisionQualifiers(false)
, active_engine(0)
{
+ requestedFormat = QSurfaceFormat::defaultFormat();
}
virtual ~QOpenGLContextPrivate()
diff --git a/src/gui/kernel/qsurfaceformat.cpp b/src/gui/kernel/qsurfaceformat.cpp
index 2b8e611dff..f077abc6a2 100644
--- a/src/gui/kernel/qsurfaceformat.cpp
+++ b/src/gui/kernel/qsurfaceformat.cpp
@@ -196,6 +196,9 @@ public:
/*!
Constructs a default initialized QSurfaceFormat.
+
+ \note By default OpenGL 2.0 is requested since this provides the highest
+ grade of portability between platforms and OpenGL implementations.
*/
QSurfaceFormat::QSurfaceFormat() : d(new QSurfaceFormatPrivate)
{
@@ -730,6 +733,43 @@ int QSurfaceFormat::swapInterval() const
return d->swapInterval;
}
+Q_GLOBAL_STATIC(QSurfaceFormat, qt_default_surface_format)
+
+/*!
+ Sets the global default surface \a format.
+
+ This format is used by default in QOpenGLContext, QWindow, QOpenGLWidget and
+ similar classes.
+
+ It can always be overridden on a per-instance basis by using the class in
+ question's own setFormat() function. However, it is often more convenient to
+ set the format for all windows once at the start of the application. It also
+ guarantees proper behavior in cases where shared contexts are required,
+ because settings the format via this function guarantees that all contexts
+ and surfaces, even the ones created internally by Qt, will use the same
+ format.
+
+ \since 5.4
+ \sa defaultFormat()
+ */
+void QSurfaceFormat::setDefaultFormat(const QSurfaceFormat &format)
+{
+ *qt_default_surface_format() = format;
+}
+
+/*!
+ Returns the global default surface format.
+
+ When setDefaultFormat() is not called, this is a default-constructed QSurfaceFormat.
+
+ \since 5.4
+ \sa setDefaultFormat()
+ */
+QSurfaceFormat QSurfaceFormat::defaultFormat()
+{
+ return *qt_default_surface_format();
+}
+
/*!
Returns \c true if all the options of the two QSurfaceFormat objects
\a a and \a b are equal.
diff --git a/src/gui/kernel/qsurfaceformat.h b/src/gui/kernel/qsurfaceformat.h
index 453beac5cd..05aba2f83c 100644
--- a/src/gui/kernel/qsurfaceformat.h
+++ b/src/gui/kernel/qsurfaceformat.h
@@ -138,6 +138,9 @@ public:
int swapInterval() const;
void setSwapInterval(int interval);
+ static void setDefaultFormat(const QSurfaceFormat &format);
+ static QSurfaceFormat defaultFormat();
+
private:
QSurfaceFormatPrivate *d;
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index 8159b7746e..8c0db2c0c7 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -224,6 +224,8 @@ void QWindowPrivate::init()
exit(1);
}
QGuiApplicationPrivate::window_list.prepend(q);
+
+ requestedFormat = QSurfaceFormat::defaultFormat();
}
/*!
@@ -672,7 +674,13 @@ void QWindow::setModality(Qt::WindowModality modality)
this function after create() has been called will not re-resolve the
surface format of the native surface.
- \sa create(), destroy()
+ When the format is not explicitly set via this function, the format returned
+ by QSurfaceFormat::defaultFormat() will be used. This means that when having
+ multiple windows, individual calls to this function can be replaced by one
+ single call to QSurfaceFormat::setDefaultFormat() before creating the first
+ window.
+
+ \sa create(), destroy(), QSurfaceFormat::setDefaultFormat()
*/
void QWindow::setFormat(const QSurfaceFormat &format)
{