1/****************************************************************************
2**
3** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QT3DRENDER_RENDERVIEWJOBUTILS_P_H
41#define QT3DRENDER_RENDERVIEWJOBUTILS_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists for the convenience
48// of other Qt classes. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <Qt3DRender/qt3drender_global.h>
55#include <Qt3DCore/qnodeid.h>
56#include <QtCore/qhash.h>
57#include <QtCore/qvariant.h>
58#include <QMatrix4x4>
59#include <Qt3DRender/private/uniform_p.h>
60#include <Qt3DRender/private/handle_types_p.h>
61#include <Qt3DRender/private/aligned_malloc_p.h>
62
63QT_BEGIN_NAMESPACE
64
65namespace Qt3DCore {
66class QFrameAllocator;
67}
68
69namespace Qt3DRender {
70namespace Render {
71
72class FrameGraphNode;
73class ParameterManager;
74class Effect;
75class Entity;
76class Material;
77class RenderPass;
78class RenderStateSet;
79class Technique;
80class RenderView;
81class TechniqueFilter;
82class RenderPassFilter;
83class Renderer;
84class NodeManagers;
85class ShaderDataManager;
86struct ShaderUniform;
87class ShaderData;
88class TextureManager;
89class RenderStateManager;
90class RenderStateCollection;
91
92Q_AUTOTEST_EXPORT void setRenderViewConfigFromFrameGraphLeafNode(RenderView *rv,
93 const FrameGraphNode *fgLeaf);
94
95Q_AUTOTEST_EXPORT Technique *findTechniqueForEffect(NodeManagers *manager,
96 const TechniqueFilter *techniqueFilter,
97 Effect *effect);
98
99typedef QVarLengthArray<RenderPass*, 4> RenderPassList;
100Q_AUTOTEST_EXPORT RenderPassList findRenderPassesForTechnique(NodeManagers *manager,
101 const RenderPassFilter *passFilter,
102 Technique *technique);
103
104// Extracts the type T from a QVariant v without using QVariant::value which is slow
105// Note: Assumes you are 100% sure about the type you requested
106template<typename T>
107inline T variant_value(const QVariant &v)
108{
109 return *reinterpret_cast<const T *>(v.data());
110}
111
112struct ParameterInfo
113{
114 explicit ParameterInfo(const int nameId = -1, const HParameter &handle = HParameter());
115
116 int nameId;
117 HParameter handle;
118
119 bool operator<(const int otherNameId) const Q_DECL_NOEXCEPT;
120 bool operator<(const ParameterInfo &other) const Q_DECL_NOEXCEPT;
121};
122typedef QVector<ParameterInfo> ParameterInfoList;
123
124struct RenderPassParameterData
125{
126 RenderPass *pass;
127 ParameterInfoList parameterInfo;
128};
129QT3D_DECLARE_TYPEINFO_2(Qt3DRender, Render, RenderPassParameterData, Q_MOVABLE_TYPE)
130
131using MaterialParameterGathererData = QHash<Qt3DCore::QNodeId, QVector<RenderPassParameterData>>;
132
133Q_AUTOTEST_EXPORT void parametersFromMaterialEffectTechnique(ParameterInfoList *infoList,
134 ParameterManager *manager,
135 Material *material,
136 Effect *effect,
137 Technique *technique);
138
139Q_AUTOTEST_EXPORT void addParametersForIds(ParameterInfoList *params, ParameterManager *manager,
140 const QVector<Qt3DCore::QNodeId> &parameterIds);
141
142template<class T>
143void parametersFromParametersProvider(ParameterInfoList *infoList,
144 ParameterManager *manager,
145 T *provider)
146{
147 addParametersForIds(infoList, manager, provider->parameters());
148}
149
150Q_AUTOTEST_EXPORT ParameterInfoList::const_iterator findParamInfo(ParameterInfoList *infoList,
151 const int nameId);
152
153Q_AUTOTEST_EXPORT void addUniqueStatesToRenderStateSet(RenderStateSet *stateSet,
154 const QVector<Qt3DCore::QNodeId> stateIds,
155 RenderStateManager *manager);
156
157typedef QHash<int, QVariant> UniformBlockValueBuilderHash;
158
159struct Q_AUTOTEST_EXPORT UniformBlockValueBuilder
160{
161 UniformBlockValueBuilder();
162 ~UniformBlockValueBuilder();
163
164 QT3D_ALIGNED_MALLOC_AND_FREE()
165
166 void buildActiveUniformNameValueMapHelper(ShaderData *currentShaderData,
167 const QString &blockName,
168 const QString &qmlPropertyName,
169 const QVariant &value);
170 void buildActiveUniformNameValueMapStructHelper(ShaderData *rShaderData,
171 const QString &blockName,
172 const QString &qmlPropertyName = QString());
173
174 bool updatedPropertiesOnly;
175 QHash<QString, ShaderUniform> uniforms;
176 UniformBlockValueBuilderHash activeUniformNamesToValue;
177 ShaderDataManager *shaderDataManager;
178 TextureManager *textureManager;
179 Matrix4x4 viewMatrix;
180};
181
182} // namespace Render
183} // namespace Qt3DRender
184
185QT_END_NAMESPACE
186
187#endif // QT3DRENDER_RENDERVIEWJOBUTILS_P_H
188