Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qssgrenderableobjects_p.h
Go to the documentation of this file.
1// Copyright (C) 2008-2012 NVIDIA Corporation.
2// Copyright (C) 2019 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
4
5#ifndef QSSG_RENDER_IMPL_RENDERABLE_OBJECTS_H
6#define QSSG_RENDER_IMPL_RENDERABLE_OBJECTS_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtQuick3DRuntimeRender/private/qssgrendermodel_p.h>
20#include <QtQuick3DRuntimeRender/private/qssgrenderdefaultmaterial_p.h>
21#include <QtQuick3DRuntimeRender/private/qssgrendercustommaterial_p.h>
22#include <QtQuick3DRuntimeRender/private/qssgrenderparticles_p.h>
23#include <QtQuick3DRuntimeRender/private/qssgrendermesh_p.h>
24#include <QtQuick3DRuntimeRender/private/qssgrendershaderkeys_p.h>
25#include <QtQuick3DRuntimeRender/private/qssgrendershadercache_p.h>
26#include <QtQuick3DRuntimeRender/private/qssgrenderableimage_p.h>
27#include <QtQuick3DRuntimeRender/private/qssgrenderlight_p.h>
28#include <QtQuick3DRuntimeRender/private/qssgrenderreflectionprobe_p.h>
29
30#include <QtQuick3DUtils/private/qssginvasivelinkedlist_p.h>
31
33
35{
36 HasTransparency = 1 << 0,
37 CompletelyTransparent = 1 << 1,
38 Dirty = 1 << 2,
39 CastsShadows = 1 << 3,
40 ReceivesShadows = 1 << 4,
41 HasAttributePosition = 1 << 5,
42 HasAttributeNormal = 1 << 6,
43 HasAttributeTexCoord0 = 1 << 7,
44 HasAttributeTexCoord1 = 1 << 8,
45 HasAttributeTangent = 1 << 9,
46 HasAttributeBinormal = 1 << 10,
47 HasAttributeColor = 1 << 11,
49 IsPointsTopology = 1 << 13,
50 // The number of target models' attributes are too many
51 // to store in a renderable flag.
52 // They will be recorded in shaderKey.
54 RequiresScreenTexture = 1 << 15,
55 ReceivesReflections = 1 << 16,
56 UsedInBakedLighting = 1 << 17,
57 RendersWithLightmap = 1 << 18,
59 CastsReflections = 1 << 20
60};
61
62struct QSSGRenderableObjectFlags : public QFlags<QSSGRenderableObjectFlag>
63{
64 void setHasTransparency(bool inHasTransparency)
65 {
67 }
69 void setCompletelyTransparent(bool inTransparent)
70 {
72 }
74 {
76 }
77 void setDirty(bool inDirty) { setFlag(QSSGRenderableObjectFlag::Dirty, inDirty); }
78 bool isDirty() const { return this->operator&(QSSGRenderableObjectFlag::Dirty); }
79
80 void setCastsShadows(bool inCastsShadows) { setFlag(QSSGRenderableObjectFlag::CastsShadows, inCastsShadows); }
82
83 void setReceivesShadows(bool inReceivesShadows) { setFlag(QSSGRenderableObjectFlag::ReceivesShadows, inReceivesShadows); }
85
86 void setReceivesReflections(bool inReceivesReflections) { setFlag(QSSGRenderableObjectFlag::ReceivesReflections, inReceivesReflections); }
88
89 void setCastsReflections(bool inCastsReflections) { setFlag(QSSGRenderableObjectFlag::CastsReflections, inCastsReflections); }
91
92 void setUsedInBakedLighting(bool inUsedInBakedLighting) { setFlag(QSSGRenderableObjectFlag::UsedInBakedLighting, inUsedInBakedLighting); }
94
95 void setRendersWithLightmap(bool inRendersWithLightmap) { setFlag(QSSGRenderableObjectFlag::RendersWithLightmap, inRendersWithLightmap); }
97
100
103
106
109
112
115
118
121
123 }
125
127 }
129
131 {
133 }
134 bool isPointsTopology() const
135 {
137 }
139 {
141 }
144 }
145};
146
148{
150 bool shadows = false;
152
153 inline bool operator < (const QSSGShaderLight &o) const
154 {
155 // sort by light type
156 if (light->type < o.light->type)
157 return true;
158 // then shadow lights first
159 if (shadows > o.shadows)
160 return true;
161 return false;
162 }
163};
164
166{
170 bool enabled = false;
172};
173
174// Having this as a QVLA is beneficial mainly because QVector would need to
175// detach somewhere in QSSGLayerRenderPreparationData::prepareForRender so the
176// implicit sharing's benefits do not outweigh the cost of allocations in this case.
179
181
183
184typedef void (*TRenderFunction)(QSSGRenderableObject &inObject, const QVector2D &inCameraProperties);
185
187
189{
191 // TODO: We should have an index here for look-up and store the data in a table,
192 // er already have the index from when we collect the nodes. We might cull some items at a later
193 // stage but that should be fine. The sort data can be just a float and the index to this...
194 mutable QSSGRenderMesh *mesh = nullptr;
197 bool isNull() const { return (node == nullptr); }
200};
201
202// Used for sorting
204{
207 : obj(o)
208 , cameraDistanceSq(camDistSq)
209 {}
211 float cameraDistanceSq = 0.0f;
212};
214
216
218{
219 enum class Type : quint8
220 {
224 };
225
226 // Variables used for picking
230
232 // For rough sorting for transparency and for depth
234 float depthBiasSq; // Squared as our sorting is based on the square distance!
235 float camdistSq = 0.0f;
237 const Type type;
240
243 const QVector3D &inWorldCenterPt,
244 const QMatrix4x4 &inGlobalTransform,
245 const QSSGBounds3 &inBounds,
246 float inDepthBias,
247 float inMinThreshold = -1,
248 float inMaxThreshold = -1)
249
250 : globalTransform(inGlobalTransform)
251 , bounds(inBounds)
252 , globalBounds(inBounds)
253 , renderableFlags(inFlags)
254 , worldCenterPoint(inWorldCenterPt)
255 , depthBiasSq(inDepthBias)
256 , type(ty)
257 , instancingLodMin(inMinThreshold)
258 , instancingLodMax(inMaxThreshold)
259 {
260 }
261};
262
263Q_STATIC_ASSERT(std::is_trivially_destructible<QSSGRenderableObject>::value);
264
266
267// Different subsets from the same model will get the same
268// model context so we can generate the MVP and normal matrix once
269// and only once per subset.
271{
275
276 QSSGModelContext(const QSSGRenderModel &inModel, const QMatrix4x4 &inViewProjection) : model(inModel)
277 {
278 // For skinning, node's global transformation will be ignored and
279 // an identity matrix will be used for the normalMatrix
280 if (model.usesBoneTexture()) {
281 modelViewProjection = inViewProjection;
283 } else {
285 }
286 }
287
289};
290
291Q_STATIC_ASSERT(std::is_trivially_destructible<QSSGModelContext>::value);
292
293class QSSGRenderer;
295struct QSSGShadowMapEntry;
296
297struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGSubsetRenderable : public QSSGRenderableObject
298{
299 int reflectionProbeIndex = -1;
301 quint32 subsetLevelOfDetail = 0;
306 QRhiBuffer *instanceBuffer = nullptr;
307 float opacity;
312
313 struct {
314 // Transient (due to the subsetRenderable being allocated using a
315 // per-frame allocator on every frame), not owned refs from the
316 // rhi-prepare step, used by the rhi-render step.
317 struct {
318 QRhiGraphicsPipeline *pipeline = nullptr;
320 } mainPass;
321 struct {
322 QRhiGraphicsPipeline *pipeline = nullptr;
323 QRhiShaderResourceBindings *srb = nullptr;
324 } depthPrePass;
325 struct {
326 QRhiGraphicsPipeline *pipeline = nullptr;
327 QRhiShaderResourceBindings *srb[6] = {};
328 } shadowPass;
329 struct {
330 QRhiGraphicsPipeline *pipeline = nullptr;
331 QRhiShaderResourceBindings *srb[6] = {};
332 } reflectionPass;
333 } rhiRenderData;
334
337 const QVector3D &inWorldCenterPt,
338 QSSGRenderer *rendr,
339 const QSSGRenderSubset &inSubset,
340 const QSSGModelContext &inModelContext,
341 float inOpacity,
342 quint32 inSubsetLevelOfDetail,
343 const QSSGRenderGraphObject &mat,
344 QSSGRenderableImage *inFirstImage,
346 const QSSGShaderLightListView &inLights);
347
349 {
350 Q_ASSERT(QSSGRenderGraphObject::isMaterial(material.type) && material.type != QSSGRenderGraphObject::Type::CustomMaterial);
351 return static_cast<const QSSGRenderDefaultMaterial &>(material);
352 }
354 {
355 Q_ASSERT(material.type == QSSGRenderGraphObject::Type::CustomMaterial);
356 return static_cast<const QSSGRenderCustomMaterial &>(material);
357 }
358 bool prepareInstancing(QSSGRhiContext *rhiCtx, const QVector3D &cameraDirection, const QVector3D &cameraPosition, float minThreshold, float maxThreshold);
359};
360
361Q_STATIC_ASSERT(std::is_trivially_destructible<QSSGSubsetRenderable>::value);
362
366struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGParticlesRenderable : public QSSGRenderableObject
367{
373 float opacity;
374
375 struct {
376 // Transient (due to the subsetRenderable being allocated using a
377 // per-frame allocator on every frame), not owned refs from the
378 // rhi-prepare step, used by the rhi-render step.
379 struct {
380 QRhiGraphicsPipeline *pipeline = nullptr;
382 } mainPass;
383 struct {
384 QRhiGraphicsPipeline *pipeline = nullptr;
385 QRhiShaderResourceBindings *srb = nullptr;
386 } depthPrePass;
387 struct {
388 QRhiGraphicsPipeline *pipeline = nullptr;
389 QRhiShaderResourceBindings *srb[6] = {};
390 } shadowPass;
391 struct {
392 QRhiGraphicsPipeline *pipeline = nullptr;
393 QRhiShaderResourceBindings *srb[6] = {};
394 } reflectionPass;
395 } rhiRenderData;
396
398 const QVector3D &inWorldCenterPt,
399 QSSGRenderer *rendr,
400 const QSSGRenderParticles &inParticles,
401 QSSGRenderableImage *inFirstImage,
402 QSSGRenderableImage *inColorTable,
403 const QSSGShaderLightListView &inLights,
404 float inOpacity);
405};
406
407Q_STATIC_ASSERT(std::is_trivially_destructible<QSSGParticlesRenderable>::value);
408
410
411#endif
constexpr QFlags operator&(int mask) const noexcept
Definition qflags.h:112
constexpr QFlags & setFlag(QSSGRenderableObjectFlag flag, bool on=true) noexcept
Definition qflags.h:130
Definition qlist.h:74
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition qmatrix4x4.h:25
\inmodule QtGui
Definition qrhi.h:834
\inmodule QtGui
Definition qrhi.h:1241
\inmodule QtGui
Definition qrhi.h:1190
Class representing 3D range or axis aligned bounding box.
The QVector2D class represents a vector or vertex in 2D space.
Definition qvectornd.h:31
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:171
Combined button and popup list for selecting options.
#define Q_STATIC_ASSERT(Condition)
Definition qassert.h:105
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
QGenericMatrix< 3, 3, float > QMatrix3x3
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLenum type
GLhandleARB obj
[2]
GLbyte ty
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
void(* TRenderFunction)(QSSGRenderableObject &inObject, const QVector2D &inCameraProperties)
QVarLengthArray< QSSGShaderLight, 16 > QSSGShaderLightList
QSSGRenderableObjectFlag
@ Q_PRIMITIVE_TYPE
Definition qtypeinfo.h:144
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:163
unsigned int quint32
Definition qtypes.h:45
unsigned char quint8
Definition qtypes.h:41
QSvgRenderer * renderer
[0]
const QSSGRenderModel & model
QSSGModelContext(const QSSGRenderModel &inModel, const QMatrix4x4 &inViewProjection)
QSSGDataRef< QSSGSubsetRenderable > subsets
QSSGRenderableImage * colorTable
const QSSGShaderLightListView & lights
QSSGRenderableImage * firstImage
const QSSGRenderParticles & particles
static Q_REQUIRED_RESULT constexpr bool isMaterial(Type type) Q_DECL_NOTHROW
bool usesBoneTexture() const
void calculateMVPAndNormalMatrix(const QMatrix4x4 &inViewProjection, QMatrix4x4 &outMVP, QMatrix3x3 &outNormalMatrix) const
QSSGShaderLightListView lights
QSSGRenderableNodeEntry(QSSGRenderNode &inNode)
QSSGRenderableNodeEntry()=default
void setRendersWithLightmap(bool inRendersWithLightmap)
void setCompletelyTransparent(bool inTransparent)
void setCastsReflections(bool inCastsReflections)
void setCastsShadows(bool inCastsShadows)
void setReceivesReflections(bool inReceivesReflections)
void setUsedInBakedLighting(bool inUsedInBakedLighting)
void setHasTransparency(bool inHasTransparency)
void setReceivesShadows(bool inReceivesShadows)
QSSGRenderableObjectHandle(QSSGRenderableObject *o, float camDistSq)
QSSGRenderableObjectHandle()=default
const QMatrix4x4 & globalTransform
QSSGRenderableObjectFlags renderableFlags
QSSGRenderableObject(Type ty, QSSGRenderableObjectFlags inFlags, const QVector3D &inWorldCenterPt, const QMatrix4x4 &inGlobalTransform, const QSSGBounds3 &inBounds, float inDepthBias, float inMinThreshold=-1, float inMaxThreshold=-1)
bool operator<(const QSSGShaderLight &o) const
QSSGRenderLight * light
const QSSGShaderLightListView & lights
QSSGShaderReflectionProbe reflectionProbe
const QSSGRenderSubset & subset
const QSSGRenderCustomMaterial & customMaterial() const
QSSGShaderDefaultMaterialKey shaderDescription
QSSGRenderableImage * firstImage
const QSSGRenderDefaultMaterial & defaultMaterial() const
const QSSGModelContext & modelContext
const QSSGRenderGraphObject & material
Definition moc.h:24