Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
adaptations.qdoc
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\title Scene Graph Adaptations
6\page qtquick-visualcanvas-adaptations.html
7
8\section1 Scene Graph Adaptations in Qt Quick
9
10In Qt 5.0, Qt Quick always relied on OpenGL (OpenGL ES 2.0 or OpenGL 2.0) to
11parse the scene graph and render the results to a render target.
12
13From Qt 5.8 onwards, Qt Quick also supports rendering in software, and with
14OpenVG. This is realized by having additional scene graph adaptations, either
15in form of plugins (openvg) or built-in to the Qt Quick library
16(software). The default adaptation continues to rely directly on OpenGL.
17
18From Qt 5.14 onwards, the default adaptation gains the option of rendering via
19a graphics abstraction layer, the Qt Rendering Hardware Interface (RHI),
20provided by the \l [QtGui]{Qt GUI} module. When enabled, no direct OpenGL calls are made.
21Rather, the scene graph renders by using the APIs provided by the abstraction
22layer, which is then translated into OpenGL, Vulkan, Metal, or Direct 3D calls.
23Shader handling is also unified by writing shader code once, compiling to
24\l{https://www.khronos.org/spir/}{SPIR-V}, and then translating to the language
25appropriate for the various graphics APIs.
26
27Starting with Qt 6.0, the RHI-based rendering model is the default, and there is
28no option to fall back to directly using OpenGL.
29
30\target Switching Between the Adaptation Used by the Application
31\section1 Switch Between Adaptations in Your Application
32
33Unlike \c software, the RHI-based renderer is not an additional adaptation, and
34is always built-in. As of Qt 6.0 it is always enabled. On platforms where
35multiple graphics APIs are available, the scenegraph makes a platform-specific
36choice. If this is not desired, applications can force a specified graphics API
37by setting the environment variable \c{QSG_RHI_BACKEND} or via \l
38QQuickWindow::setGraphicsApi() in combination with \l
39QSGRendererInterface::GraphicsApi.
40
41Switching to a different adaptation can be achieved in two ways:
42
43\list
44 \li Use an environment variable - Set the \c{QT_QUICK_BACKEND} or the legacy
45 \c{QMLSCENE_DEVICE} environment variable before launching applications.
46 \li Use a C++ API - Call QQuickWindow::setSceneGraphBackend() early on in the application's
47 main() function.
48\endlist
49
50The following backends are supported:
51
52\list
53 \li Default - Request with the \c{"rhi"} string or a QSGRendererInterface::GraphicsApi enum value
54 different than the ones listed below.
55 \li Software - Request with the \c{"software"} string or the QSGRendererInterface::Software
56 enum value.
57 \li OpenVG - Request with the \c{"openvg"} string or the QSGRendererInterface::OpenVG enum
58 value.
59\endlist
60
61To find out which backend is in use, you can enable basic scene graph information logging via the
62\c{QSG_INFO} environment variable or the \c{qt.scenegraph.general} logging category. This results
63in some information being printed onto the debug output, during application startup.
64
65\note In Qt builds with both OpenGL and Vulkan disabled, the default adaptation
66is \c software. This does not apply to Windows or \macos however, because these
67platforms always have Direct 3D or Metal support, respectively, enabled.
68
69\note Typically, adaptations other than the default one come with a set of
70limitations as they are unlikely to provide a feature set that's 100%
71compatible with OpenGL. However, these adaptations may provide their own
72specific advantages in certain areas. For more information on the various
73adaptations, refer to the sections below.
74
75\section1 Default Adaptation
76
77When using OpenGL directly, the default adaptation is capable of providing the
78full Qt Quick 2 feature set. For more details, see
79\l{qtquick-visualcanvas-scenegraph-renderer.html}{Default Adaptation}.
80
81\section1 Software Adaptation
82
83The Software adaptation is an alternative renderer for \l{Qt Quick} 2 that uses the raster paint
84engine to render the contents of the scene graph. For more details, see
85\l{qtquick-visualcanvas-adaptations-software.html}{Software Adaptation}.
86
87\section1 OpenVG
88
89The OpenVG adaptation is an alternative renderer for \l{Qt Quick} 2 that renders the contents of
90the scene graph using OpenVG commands to provide hardware-accelerated 2D vector and raster
91graphics. For more details, see
92\l{qtquick-visualcanvas-adaptations-openvg.html}{OpenVG Adaptation}.
93*/
94
95
96/*!
97\title Qt Quick Software Adaptation
98\page qtquick-visualcanvas-adaptations-software.html
99
100The Software adaptation is an alternative renderer for \l {Qt Quick} 2 that uses the Raster paint
101engine to render the contents of the scene graph, instead of a hardware-accelerated 3D graphics API.
102Consequently, some features and optimizations are not available. Most Qt Quick 2 applications can run
103without any modification, but any attempts to use unsupported features are ignored.
104By using the Software adaptation, it is possible to run Qt Quick 2 applications on hardware and
105platforms that do not have \l{topics-graphics}{hardware-accelerated 3D graphics API} support.
106
107The Software adaptation was previously known as the Qt Quick 2D Renderer. However, unlike the 2D
108Renderer, this new, integrated version supports partial updates. This means that a full update
109of the window or screen contents is now avoided; only the changed areas are flushed. Partial
110updates can significantly improve performance for many applications.
111
112\section2 Shader Effects
113
114ShaderEffect components in QtQuick 2 cannot be rendered by the Software adaptation.
115
116\section2 Particle Effects
117
118It is not possible to render particle effects with the Software adaptation. Whenever possible,
119remove particles completely from the scene. Otherwise, they will still require some processing,
120even though they are not visible.
121
122\section2 Rendering Text
123
124The text rendering with the Software adaptation is based on software rasterization and does not
125respond as well to transformations such as scaling, compared to when using a hardware-accelerated
1263D graphics API. The quality is similar to choosing \l [QML] {Text::renderType}{Text.NativeRendering}
127with \l [QML] {Text} items.
128*/
129
130
131/*!
132\title Qt Quick OpenVG Adaptation
133\page qtquick-visualcanvas-adaptations-openvg.html
134
135The OpenVG adaptation is an alternative renderer for \l{Qt Quick} 2 that renders the contents of
136the scene graph using OpenVG commands to provide hardware accelerated 2D vector and raster
137graphics. Much like the \l{qtquick-visualcanvas-adaptations-software.html}{Software Adaptation},
138some features and optimizations are no longer available. Most Qt Quick 2 applications will run
139without modification though any attempts to use unsupported features will be ignored.
140
141\section2 EGL Requirement
142
143Unlike the default OpenGL Renderer, there is no built-in support to acquire an OpenVG context.
144This means that the renderer is responsible for requesting and managing the the current context.
145To do this, you use EGL directly in the OpenVG renderer. Consequently, the OpenVG renderer can only
146be used with platform plugins that support creating QWindows with support for
147QSurfaceFormat::OpenVG. From this window, the renderer can get an EGLSurface which can then be used
148with an EGLContext to render OpenVG content.
149
150\section2 Renderer
151
152The OpenVG Renderer uses the OpenVG API to send commands and data to a Vector GPU that renders the
153scene graph in an accelerated manner, offloading graphics rendering from the CPU. Many operations
154like the rendering of rectangles and font glyphs are ideal for OpenVG because they can be
155represented as paths which are stroked and filled. Rendering scene graph items that would typically
156involve textures are handled in the OpenVG renderer using VGImage. Additionally, when you render
157to offscreen surfaces (like with Layers), the scene subtree is rendered to a VGImage which can be
158reused in the scene.
159
160\section2 Render Loop
161
162The OpenVG Renderer mirrors the behavior of the Basic render loop and it runs all OpenVG commands
163in a single thread.
164
165For more information on render loops, see
166\l{qtquick-visualcanvas-scenegraph.html}{Qt Quick Scene Graph}.
167
168\section2 Shader Effects
169
170ShaderEffect components in QtQuick 2 can't be rendered by the OpenVG adaptation. While it's
171possible to use ShaderEffectSource and QML Item Layers (which are both offscreen surfaces), it's
172not possible to apply shader effects to them via the ShaderEffect item. This is because OpenVG
173lacks an API for applying per vertex and per fragment shader operations. However, you may be able
174to take advantage of Image Filter operations in the OpenVG API to get effects that are similar to
175what ShaderEffects provides in custom items. To integrate custom OpenVG rendering, use
176QSGRenderNode in combination with QSGRendererInterface.
177
178\section2 Particle Effects
179
180It's not possible to render particle effects with the OpenVG adaptation. Whenever possible, remove
181particles completely from the scene. Otherwise they'll still require some processing, even though
182they are not visible.
183
184\section2 Rendering Text
185
186Text rendering with the OpenVG adaptation is based on rendering the glyph paths, and doesn't use
187the distance fields technique, unlike with the OpenGL backend.
188
189\section2 Perspective Transforms
190
191The OpenVG API doesn't allow paths to be transformed with non-affine transforms, but it's
192possible with Qt Quick. Consquently, when you render components using paths like Rectangles and
193Text while applying perspective transforms, the OpenVG backend first renders to a VGImage before
194applying transformations. This behavior uses more memory at runtime and takes more time; avoid it
195if possible.
196
197*/