Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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. It is also possible to disable
111this partial update behavior by setting the environment variable
112\c{QSG_SOFTWARE_RENDERER_FORCE_PARTIAL_UPDATES=0}, though doing so will have a negative impact on
113performance.
114
115\section2 Shader Effects
116
117ShaderEffect components in QtQuick 2 cannot be rendered by the Software adaptation.
118
119\section2 Particle Effects
120
121It is not possible to render particle effects with the Software adaptation. Whenever possible,
122remove particles completely from the scene. Otherwise, they will still require some processing,
123even though they are not visible.
124
125\section2 Rendering Text
126
127The text rendering with the Software adaptation is based on software rasterization and does not
128respond as well to transformations such as scaling, compared to when using a hardware-accelerated
1293D graphics API. The quality is similar to choosing \l [QML] {Text::renderType}{Text.NativeRendering}
130with \l [QML] {Text} items.
131
132
133\section2 High DPI
134
135The Software adaptation supports high DPI displays, but it does not support performing partial updates
136when the using fractional scaling. This means that when using a non-integer scaling factor, the partial
137update optimization is disabled, and the entire window is redrawn on every frame. This can be overridden
138by setting an environment variable to \c{QSG_SOFTWARE_RENDERER_FORCE_PARTIAL_UPDATES=1} which forces
139the Software adaptation to use partial updates even when fractional scaling is in use. However, this
140may result in artifacts when scaling is not an integer value, and it is not recommended to use this
141without thorough testing.
142
143*/
144
145
146/*!
147\title Qt Quick OpenVG Adaptation
148\page qtquick-visualcanvas-adaptations-openvg.html
149
150The OpenVG adaptation is an alternative renderer for \l{Qt Quick} 2 that renders the contents of
151the scene graph using OpenVG commands to provide hardware accelerated 2D vector and raster
152graphics. Much like the \l{qtquick-visualcanvas-adaptations-software.html}{Software Adaptation},
153some features and optimizations are no longer available. Most Qt Quick 2 applications will run
154without modification though any attempts to use unsupported features will be ignored.
155
156\section2 EGL Requirement
157
158Unlike the default OpenGL Renderer, there is no built-in support to acquire an OpenVG context.
159This means that the renderer is responsible for requesting and managing the the current context.
160To do this, you use EGL directly in the OpenVG renderer. Consequently, the OpenVG renderer can only
161be used with platform plugins that support creating QWindows with support for
162QSurfaceFormat::OpenVG. From this window, the renderer can get an EGLSurface which can then be used
163with an EGLContext to render OpenVG content.
164
165\section2 Renderer
166
167The OpenVG Renderer uses the OpenVG API to send commands and data to a Vector GPU that renders the
168scene graph in an accelerated manner, offloading graphics rendering from the CPU. Many operations
169like the rendering of rectangles and font glyphs are ideal for OpenVG because they can be
170represented as paths which are stroked and filled. Rendering scene graph items that would typically
171involve textures are handled in the OpenVG renderer using VGImage. Additionally, when you render
172to offscreen surfaces (like with Layers), the scene subtree is rendered to a VGImage which can be
173reused in the scene.
174
175\section2 Render Loop
176
177The OpenVG Renderer mirrors the behavior of the Basic render loop and it runs all OpenVG commands
178in a single thread.
179
180For more information on render loops, see
181\l{qtquick-visualcanvas-scenegraph.html}{Qt Quick Scene Graph}.
182
183\section2 Shader Effects
184
185ShaderEffect components in QtQuick 2 can't be rendered by the OpenVG adaptation. While it's
186possible to use ShaderEffectSource and QML Item Layers (which are both offscreen surfaces), it's
187not possible to apply shader effects to them via the ShaderEffect item. This is because OpenVG
188lacks an API for applying per vertex and per fragment shader operations. However, you may be able
189to take advantage of Image Filter operations in the OpenVG API to get effects that are similar to
190what ShaderEffects provides in custom items. To integrate custom OpenVG rendering, use
191QSGRenderNode in combination with QSGRendererInterface.
192
193\section2 Particle Effects
194
195It's not possible to render particle effects with the OpenVG adaptation. Whenever possible, remove
196particles completely from the scene. Otherwise they'll still require some processing, even though
197they are not visible.
198
199\section2 Rendering Text
200
201Text rendering with the OpenVG adaptation is based on rendering the glyph paths, and doesn't use
202the distance fields technique, unlike with the OpenGL backend.
203
204\section2 Perspective Transforms
205
206The OpenVG API doesn't allow paths to be transformed with non-affine transforms, but it's
207possible with Qt Quick. Consquently, when you render components using paths like Rectangles and
208Text while applying perspective transforms, the OpenVG backend first renders to a VGImage before
209applying transformations. This behavior uses more memory at runtime and takes more time; avoid it
210if possible.
211
212*/