summaryrefslogtreecommitdiffstats
path: root/src/doc/src/qt3drender-protips.qdoc
blob: c78f3d59837bc3c21e11b4db17cd81b0d05b0411 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/****************************************************************************
**
** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt3D module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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 Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or 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.GPL2 and 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-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \page qt3drender-protips.html
    \title Qt 3D Render Pro Tips

    \brief This sections tries to make you aware of various pitfalls inherent
    to 3D rendering and ways to prevent them.

    To render even the simplest shapes, Qt 3D needs to perform various
    operations through several stages. If anything goes wrong at any of these
    stages you may end up, in the best cases with something different than what
    you expected, in the worst cases with a black screen.

    \list
        \li \l {Technique Selection}
        \li \l {Order Matters}
        \li \l {Blending}
        \li \l {Useful Tools}
    \endlist

    \section2 Technique Selection

     Qt 3D provides a technique selection mechanism allowing you to provide
     shaders for various rendering APIs and versions of these APIs.

     In order to avoid unnecessary waste of your time, you should make sure
     that your technique's API filter data is correct for the platform you are
     targeting.

     \section2 Order Matters

     The order of the draw calls performed by the renderer is not necessarily
     the same as the order of the entities in the scene.

     The renderer tries to optimize calls that are sent to the graphics API.
     It orders draw calls based on the material/shader being used, the render
     states that are defined for a given material, their depth, the parameters
     shared in common between two materials, etc.

     If your rendering depends on a specific draw order you should then have
     a few options:

    \list

     \li Filtering with a Qt3DRender::QLayer component and
     Qt3DRender::QLayerFilter in the FrameGraph

     \li RenderPass or Technique filtering using Qt3DRender::QRenderPassFilter
     or Qt3DRender::QTechniqueFilter in the FrameGraph

     \endlist

     \section2 Blending

     Mastering blending with proper arguments and functions is an art in
     itself. Therefore obtaining the proper visual result is often hit and
     miss.

     \l {http://www.andersriggelsen.dk/glblendfunc.php}{Anders Riggelsen's
     online visualizer} may help you find out which arguments and functions
     work for you.

     \section3 Blending with Scene3D

     When rendering a Qt 3D scene through a Qt Quick scene with the Scene3D
     element you should be aware that you might have to adjust the blending
     arguments of your render state to obtain a sensible rendering. This is
     because of the way Qt 3D first renders a scene into an offscreen texture
     which is then blended in with the rest of the Qt Quick scene.

     Sensible values are often Qt3DRender::QBlendEquationArguments::Zero for
     the source alpha and Qt3DRender::QBlendEquationArguments::One for the
     destination alpha.

     \section2 Useful Tools

     Given the rather limited of troubleshooting given by Qt 3D in its first
     versions it sometimes helps to have tools to capture OpenGL draw calls and
     get more clues about what's happening

     \list
     \li \l {https://github.com/apitrace/apitrace}{apitrace}
     \li \l {https://github.com/ValveSoftware/vogl}{vogl}
     \endlist

     These tools allow you to gather traces of all the OpenGL calls being made
     by a Qt 3D application. Having a look at a generated trace file may help
     you verify that draw calls are being made, textures correctly uploaded,
     uniforms set with proper values, ...

     There are plans for Qt 3D tooling in later releases.
 */