Improvements to the core OpenGL enablers in Qt 5.3 & 5.4

News from the Graphics Stack:
Improvements to the core OpenGL enablers in Qt 5.3 & 5.4
Laszlo Agocs
The Qt Company
1
В© 2014 The Qt Company
Who am I?
в—Џ
Senior software engineer at The Qt Company (formerly Digia) in
Oslo, Norway
в—Џ
OpenGL, graphics, windowing systems, platform integration
в—Џ
Previously at ARM and Nokia
2
В© 2014 The Qt Company
Why are we here?
в—Џ
в—Џ
в—Џ
в—Џ
в—Џ
QQuickWidget
QQuickRenderControl
QOpenGLWidget
QOpenGLWindow
QRasterWindow
3
В© 2014 The Qt Company
The long road to QQuickWidget
4
В© 2014 The Qt Company
OpenGL in Qt 4
5
В© 2014 The Qt Company
Qt 4
Native windows
6
В© 2014 The Qt Company
Qt 5.0
в—Џ
в—Џ
в—Џ
QWindow, QOpenGLContext, QSurfaceFormat
QQuickWindow, QQuickView
QGL*
7
В© 2014 The Qt Company
Qt 5.1
в—Џ
QWidget::createWindowContainer()
8
В© 2014 The Qt Company
Qt 5.3
в—Џ
New concept: Avoid native windows, render offscreen and composite in the
widget stack
в—Џ
Essential for embedded
в—Џ
QQuickWidget
9
В© 2014 The Qt Company
QQuickWidget
is always
better than
10
В© 2014 The Qt Company
black has
alpha == 0
11
В© 2014 The Qt Company
And it just works. Even on embedded.
A Qt Quick 2 scene embedded into a widget UI
using QQuickWidget
A QWidget with two QOpenGLWidgets
running on i.MX6 Sabre LITE on eglfs
12
В© 2014 The Qt Company
Composition
в—Џ
Does this mean all widget apps require OpenGL from now on? No.
в—Џ
Does this support multisampling? Yes.
в—Џ
Qt::WA_AlwaysStackOnTop
13
В© 2014 The Qt Company
QQuickWidget API
в—Џ
Mirrors QQuickView
в—Џ
Except that it is a QWidget
14
В© 2014 The Qt Company
QQuickRenderControl
в—Џ
в—Џ
в—Џ
в—Џ
в—Џ
QQuickWidget
QQuickRenderControl
QOpenGLWidget
QOpenGLWindow
QRasterWindow
15
В© 2014 The Qt Company
QQuickRenderControl
16
В© 2014 The Qt Company
QQuickRenderControl
в—Џ
No on-screen QQuickWindow.
в—Џ
The rendering of the scene is redirected into a FBO.
в—Џ
Texture can be used in arbitrary ways. No costly readbacks.
в—Џ
Need to send input to Quick? QCoreApplication::sendEvent()
в—Џ
Integrate Quick into external engines, not the other way round.
17
В© 2014 The Qt Company
QOpenGLWidget
в—Џ
в—Џ
в—Џ
в—Џ
в—Џ
QQuickWidget
QQuickRenderControl
QOpenGLWidget
QOpenGLWindow
QRasterWindow
18
В© 2014 The Qt Company
Qt 5.4
в—Џ
Back to widgets. No more boring QML stuff.
в—Џ
QOpenGLWidget is here
в—Џ
R.I.P. QGLWidget
10 QOpenGLWidget instances in
one top-level window
19
В© 2014 The Qt Company
QOpenGLWidget
в—Џ
Basic API is familiar
в—Џ
Can open a QPainter on it
в—Џ
Utilities like bindTexture() are gone в†’ QOpenGLTexture
20
В© 2014 The Qt Company
QOpenGLWidget
One visible native window only, unlike
QGLWidget.
21
Animation
в—Џ
QTimer::singleShot(16, m_legacyQGLWidget, SLOT(updateGL()))
в—Џ
Swap interval defaults to 1 since Qt 5.3
в—Џ
QSurfaceFormat::setSwapInterval()
в—Џ
Schedule repaints with update() and rely on vsync
в—Џ
Timers with small intervals can be useful, but know what you are doing
22
В© 2014 The Qt Company
Formats and contexts
в—Џ
QSurfaceFormat::setDefaultFormat()
в—Џ
Easy to request OpenGL 3+ or core profile for everything in the app
в—Џ
в—Џ
The new compositing architecture relies heavily on multiple contexts and
resource sharing.
QOpenGLWidget comes with documentation. Use it.
23
В© 2014 The Qt Company
Formats and contexts, cont.
Window 1 with two
QOpenGLWidgets
Window 2 with two
QOpenGLWidgets
TLW context 1
Context 1 Context 2
24
TLW context 2
Context 3 Context 4
В© 2014 The Qt Company
Formats and contexts, cont.
Qt::AA_ShareOpenGLContexts
Window 1 with two
QOpenGLWidgets
TLW context 1
Context 1 Context 2
25
share
Global share context
share
в—Џ
Window 2 with two
QOpenGLWidgets
TLW context 2
Context 3 Context 4
В© 2014 The Qt Company
High DPI screens
в—Џ
OpenGL operates in pixel dimensions on retina screens.
в—Џ
new QOpenGLFramebufferObject(w->devicePixelRatio() * w->size())
в—Џ
Qt takes care of all the internal framebuffers and viewports. The rest is up to you.
в—Џ
Watch out for screen changes
в—Џ screenChanged(QScreen*) signal for QWindow
в—Џ ScreenChangeInternal event for QWidget
26
В© 2014 The Qt Company
QOpenGLWindow
в—Џ
в—Џ
в—Џ
в—Џ
в—Џ
QQuickWidget
QQuickRenderControl
QOpenGLWidget
QOpenGLWindow
QRasterWindow
27
В© 2014 The Qt Company
QWindow
в—Џ
Enough of widgets,
I don't want your push buttons.
в—Џ
QWindow is fine for you then.
в—Џ
Lightweight and powerful, but...
28
В© 2014 The Qt Company
QOpenGLWindow
29
В© 2014 The Qt Company
QRasterWindow
в—Џ
в—Џ
в—Џ
в—Џ
в—Џ
QQuickWidget
QQuickRenderControl
QOpenGLWidget
QOpenGLWindow
QRasterWindow
30
В© 2014 The Qt Company
QRasterWindow
в—Џ
QOpenGLWidget has a little brother: QRasterWindow
в—Џ
Exactly what the name suggests. Nothing more, nothing less.
31
В© 2014 The Qt Company
Summary
в—Џ
в—Џ
в—Џ
в—Џ
в—Џ
QQuickWidget
QQuickRenderControl
QOpenGLWidget
QOpenGLWindow
QRasterWindow
32
В© 2014 The Qt Company
Qt Quick 2 application
QQuickView or
QQmlApplicationEngine
OpenGL without any need for Qt
widgets
QOpenGLWindow
Custom QPainter-based drawing
without Qt widgets
QRasterWindow
OpenGL content in a widget-based
application
QOpenGLWidget
Qt Quick 2 content in a widgetbased application
QQuickWidget
Qt Quick 2 content used as a
texture in a custom OpenGL
renderer
QOpenGLWindow +
QQuickRenderControl
33
В© 2014 The Qt Company
What was left out
в—Џ
Dynamic OpenGL implementation loading on Windows
в—Џ
Adoption of existing native OpenGL contexts
34
В© 2014 The Qt Company
Thank you!
www.qt.io
В© 2014 The Qt Company
www.qt.io
See you there!
В© 2014 The Qt Company