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_RENDER_OPENGL_RENDERVIEWJOBUTILS_P_H
41#define QT3DRENDER_RENDER_OPENGL_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#include <shadervariables_p.h>
63
64QT_BEGIN_NAMESPACE
65
66namespace Qt3DCore {
67class QFrameAllocator;
68}
69
70namespace Qt3DRender {
71namespace Render {
72
73class FrameGraphNode;
74class ParameterManager;
75class Effect;
76class Entity;
77class Material;
78class RenderPass;
79class Technique;
80class TechniqueFilter;
81class RenderPassFilter;
82class NodeManagers;
83class ShaderDataManager;
84class ShaderData;
85class TextureManager;
86class RenderStateManager;
87class RenderStateCollection;
88class RenderStateSet;
89
90namespace OpenGL {
91class Renderer;
92class RenderView;
93struct ShaderUniform;
94
95Q_AUTOTEST_EXPORT void setRenderViewConfigFromFrameGraphLeafNode(RenderView *rv,
96 const FrameGraphNode *fgLeaf);
97
98Q_AUTOTEST_EXPORT Technique *findTechniqueForEffect(NodeManagers *manager,
99 const TechniqueFilter *techniqueFilter,
100 Effect *effect);
101
102typedef QVarLengthArray<RenderPass*, 4> RenderPassList;
103Q_AUTOTEST_EXPORT RenderPassList findRenderPassesForTechnique(NodeManagers *manager,
104 const RenderPassFilter *passFilter,
105 Technique *technique);
106
107// Extracts the type T from a QVariant v without using QVariant::value which is slow
108// Note: Assumes you are 100% sure about the type you requested
109template<typename T>
110inline T variant_value(const QVariant &v)
111{
112 return *reinterpret_cast<const T *>(v.data());
113}
114
115struct ParameterInfo
116{
117 explicit ParameterInfo(const int nameId = -1, const HParameter &handle = HParameter());
118
119 int nameId;
120 HParameter handle;
121
122 bool operator<(const int otherNameId) const Q_DECL_NOEXCEPT;
123 bool operator<(const ParameterInfo &other) const Q_DECL_NOEXCEPT;
124};
125typedef QVector<ParameterInfo> ParameterInfoList;
126
127struct RenderPassParameterData
128{
129 RenderPass *pass;
130 ParameterInfoList parameterInfo;
131};
132QT3D_DECLARE_TYPEINFO_3(Qt3DRender, Render, OpenGL, RenderPassParameterData, Q_MOVABLE_TYPE)
133
134using MaterialParameterGathererData = QMultiHash<Qt3DCore::QNodeId, QVector<RenderPassParameterData>>;
135
136Q_AUTOTEST_EXPORT void parametersFromMaterialEffectTechnique(ParameterInfoList *infoList,
137 ParameterManager *manager,
138 Material *material,
139 Effect *effect,
140 Technique *technique);
141
142Q_AUTOTEST_EXPORT void addParametersForIds(ParameterInfoList *params, ParameterManager *manager,
143 const QVector<Qt3DCore::QNodeId> &parameterIds);
144
145template<class T>
146void parametersFromParametersProvider(ParameterInfoList *infoList,
147 ParameterManager *manager,
148 T *provider)
149{
150 addParametersForIds(infoList, manager, provider->parameters());
151}
152
153Q_AUTOTEST_EXPORT ParameterInfoList::const_iterator findParamInfo(ParameterInfoList *infoList,
154 const int nameId);
155
156Q_AUTOTEST_EXPORT void addStatesToRenderStateSet(RenderStateSet *stateSet,
157 const QVector<Qt3DCore::QNodeId> stateIds,
158 RenderStateManager *manager);
159
160typedef QHash<int, QVariant> UniformBlockValueBuilderHash;
161
162struct Q_AUTOTEST_EXPORT UniformBlockValueBuilder
163{
164 UniformBlockValueBuilder();
165 ~UniformBlockValueBuilder();
166
167 QT3D_ALIGNED_MALLOC_AND_FREE()
168
169 void buildActiveUniformNameValueMapHelper(const ShaderData *currentShaderData,
170 const QString &blockName,
171 const QString &qmlPropertyName,
172 const QVariant &value);
173 void buildActiveUniformNameValueMapStructHelper(const ShaderData *rShaderData,
174 const QString &blockName,
175 const QString &qmlPropertyName = QString());
176
177 bool updatedPropertiesOnly;
178 QHash<QString, ShaderUniform> uniforms;
179 UniformBlockValueBuilderHash activeUniformNamesToValue;
180 ShaderDataManager *shaderDataManager;
181 TextureManager *textureManager;
182 Matrix4x4 viewMatrix;
183};
184
185} // namespace OpenGL
186} // namespace Render
187} // namespace Qt3DRender
188
189QT_END_NAMESPACE
190
191#endif // QT3DRENDER_RENDER_OPENGL_RENDERVIEWJOBUTILS_P_H
192

source code of qt3d/src/plugins/renderers/opengl/jobs/renderviewjobutils_p.h