Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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#include <QtQuick3DRuntimeRender/private/qssgrenderclippingfrustum_p.h>
30
31#include <QtQuick3DUtils/private/qssginvasivelinkedlist_p.h>
32
34
36{
37 HasTransparency = 1 << 0,
38 CompletelyTransparent = 1 << 1,
39 Dirty = 1 << 2,
40 CastsShadows = 1 << 3,
41 ReceivesShadows = 1 << 4,
42 HasAttributePosition = 1 << 5,
43 HasAttributeNormal = 1 << 6,
44 HasAttributeTexCoord0 = 1 << 7,
45 HasAttributeTexCoord1 = 1 << 8,
46 HasAttributeTangent = 1 << 9,
47 HasAttributeBinormal = 1 << 10,
48 HasAttributeColor = 1 << 11,
50 IsPointsTopology = 1 << 13,
51 // The number of target models' attributes are too many
52 // to store in a renderable flag.
53 // They will be recorded in shaderKey.
55 RequiresScreenTexture = 1 << 15,
56 ReceivesReflections = 1 << 16,
57 UsedInBakedLighting = 1 << 17,
58 RendersWithLightmap = 1 << 18,
60 CastsReflections = 1 << 20
61};
62
63struct QSSGRenderableObjectFlags : public QFlags<QSSGRenderableObjectFlag>
64{
65 void setHasTransparency(bool inHasTransparency)
66 {
68 }
70 void setCompletelyTransparent(bool inTransparent)
71 {
73 }
78 void setDirty(bool inDirty) { setFlag(QSSGRenderableObjectFlag::Dirty, inDirty); }
79 bool isDirty() const { return this->operator&(QSSGRenderableObjectFlag::Dirty); }
80
81 void setCastsShadows(bool inCastsShadows) { setFlag(QSSGRenderableObjectFlag::CastsShadows, inCastsShadows); }
83
84 void setReceivesShadows(bool inReceivesShadows) { setFlag(QSSGRenderableObjectFlag::ReceivesShadows, inReceivesShadows); }
86
87 void setReceivesReflections(bool inReceivesReflections) { setFlag(QSSGRenderableObjectFlag::ReceivesReflections, inReceivesReflections); }
89
90 void setCastsReflections(bool inCastsReflections) { setFlag(QSSGRenderableObjectFlag::CastsReflections, inCastsReflections); }
92
93 void setUsedInBakedLighting(bool inUsedInBakedLighting) { setFlag(QSSGRenderableObjectFlag::UsedInBakedLighting, inUsedInBakedLighting); }
95
96 void setRendersWithLightmap(bool inRendersWithLightmap) { setFlag(QSSGRenderableObjectFlag::RendersWithLightmap, inRendersWithLightmap); }
98
101
104
107
110
113
116
119
122
126
130
135 bool isPointsTopology() const
136 {
138 }
146};
147
149{
151 bool shadows = false;
153
154 inline bool operator < (const QSSGShaderLight &o) const
155 {
156 // sort by light type
157 if (light->type < o.light->type)
158 return true;
159 // then shadow lights first
160 if (shadows > o.shadows)
161 return true;
162 return false;
163 }
164};
165
174
175// Having this as a QVLA is beneficial mainly because QVector would need to
176// detach somewhere in QSSGLayerRenderPreparationData::prepareForRender so the
177// implicit sharing's benefits do not outweigh the cost of allocations in this case.
178typedef QVarLengthArray<QSSGShaderLight, 16> QSSGShaderLightList;
179using QSSGShaderLightListView = QSSGDataView<QSSGShaderLight>;
180
182
184{
193
195 // TODO: We should have an index here for look-up and store the data in a table,
196 // er already have the index from when we collect the nodes. We might cull some items at a later
197 // stage but that should be fine. The sort data can be just a float and the index to this...
199 mutable QSSGRenderMesh *mesh = nullptr;
200 mutable QVector<QSSGRenderGraphObject *> materials;
202 mutable float globalOpacity { 1.0f };
204
205 bool isNull() const { return (node == nullptr); }
208};
209
210// Used for sorting
222
223using QSSGRenderableObjectList = QVector<QSSGRenderableObjectHandle>;
224
226{
233
234 // Variables used for picking
238
240 // For rough sorting for transparency and for depth
242 float depthBiasSq; // Squared as our sorting is based on the square distance!
243 float camdistSq = 0.0f;
245 const Type type;
248
251 const QVector3D &inWorldCenterPt,
252 const QMatrix4x4 &inGlobalTransform,
253 const QSSGBounds3 &inBounds,
254 float inDepthBias,
255 float inMinThreshold = -1,
256 float inMaxThreshold = -1)
257
258 : globalTransform(inGlobalTransform)
259 , bounds(inBounds)
260 , globalBounds(inBounds)
261 , renderableFlags(inFlags)
262 , worldCenterPoint(inWorldCenterPt)
263 , depthBiasSq(inDepthBias)
264 , type(ty)
265 , instancingLodMin(inMinThreshold)
266 , instancingLodMax(inMaxThreshold)
267 {
268 }
269};
270
271Q_STATIC_ASSERT(std::is_trivially_destructible<QSSGRenderableObject>::value);
272
274{
276 std::optional<QSSGClippingFrustum> clippingFrustum;
277 QVector3D direction { 0.0f, 0.0f, -1.0f };
279};
280
281using QSSGRenderCameraList = QVarLengthArray<QSSGRenderCamera *, 2>;
282using QSSGRenderCameraDataList = QVarLengthArray<QSSGRenderCameraData, 2>;
283using QSSGRenderMvpArray = std::array<QMatrix4x4, 2>; // cannot be dynamic due to QSSGModelContext, must stick with 2 for now
284
286
287// Different subsets from the same model will get the same
288// model context so we can generate the MVP and normal matrix once
289// and only once per subset.
291{
295
297 const QMatrix4x4 &globalTransform,
298 const QSSGRenderCameraDataList &allCameraData)
299 : model(inModel)
300 {
301 Q_ASSERT_X(allCameraData.size() <= qsizetype(modelViewProjections.size()), __FUNCTION__, "QSSGModelContext has no space for all MVPs");
302 int mvpCount = 0;
303 // For skinning, node's global transformation will be ignored and
304 // an identity matrix will be used for the normalMatrix
305 if (model.usesBoneTexture()) {
306 for (const QSSGRenderCameraData &cameraData : allCameraData) {
307 modelViewProjections[mvpCount++] = cameraData.viewProjection;
309 }
310 } else {
311 for (const QSSGRenderCameraData &cameraData : allCameraData)
312 QSSGRenderNode::calculateMVPAndNormalMatrix(globalTransform, cameraData.viewProjection, modelViewProjections[mvpCount++], normalMatrix);
313 }
314 }
315
316 QSSGDataRef<QSSGSubsetRenderable> subsets;
317};
318
319Q_STATIC_ASSERT(std::is_trivially_destructible<QSSGModelContext>::value);
320
321class QSSGRenderer;
323struct QSSGShadowMapEntry;
324
325struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGSubsetRenderable : public QSSGRenderableObject
326{
327 int reflectionProbeIndex = -1;
329 quint32 subsetLevelOfDetail = 0;
334 QRhiBuffer *instanceBuffer = nullptr;
335 float opacity;
340
341 struct {
342 // Transient (due to the subsetRenderable being allocated using a
343 // per-frame allocator on every frame), not owned refs from the
344 // rhi-prepare step, used by the rhi-render step.
345 struct {
346 QRhiGraphicsPipeline *pipeline = nullptr;
348 } mainPass;
349 struct {
350 QRhiGraphicsPipeline *pipeline = nullptr;
351 QRhiShaderResourceBindings *srb = nullptr;
352 } depthPrePass;
353 struct {
354 QRhiGraphicsPipeline *pipeline = nullptr;
355 QRhiShaderResourceBindings *srb[6] = {};
356 } shadowPass;
357 struct {
358 QRhiGraphicsPipeline *pipeline = nullptr;
359 QRhiShaderResourceBindings *srb[6] = {};
360 } reflectionPass;
361 } rhiRenderData;
362
365 const QVector3D &inWorldCenterPt,
366 QSSGRenderer *rendr,
367 const QSSGRenderSubset &inSubset,
368 const QSSGModelContext &inModelContext,
369 float inOpacity,
370 quint32 inSubsetLevelOfDetail,
371 const QSSGRenderGraphObject &mat,
372 QSSGRenderableImage *inFirstImage,
374 const QSSGShaderLightListView &inLights);
375
376 [[nodiscard]] const QSSGRenderGraphObject &getMaterial() const { return material; }
377};
378
379Q_STATIC_ASSERT(std::is_trivially_destructible<QSSGSubsetRenderable>::value);
380
384struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGParticlesRenderable : public QSSGRenderableObject
385{
391 float opacity;
392
393 struct {
394 // Transient (due to the subsetRenderable being allocated using a
395 // per-frame allocator on every frame), not owned refs from the
396 // rhi-prepare step, used by the rhi-render step.
397 struct {
398 QRhiGraphicsPipeline *pipeline = nullptr;
400 } mainPass;
401 struct {
402 QRhiGraphicsPipeline *pipeline = nullptr;
403 QRhiShaderResourceBindings *srb = nullptr;
404 } depthPrePass;
405 struct {
406 QRhiGraphicsPipeline *pipeline = nullptr;
407 QRhiShaderResourceBindings *srb[6] = {};
408 } shadowPass;
409 struct {
410 QRhiGraphicsPipeline *pipeline = nullptr;
411 QRhiShaderResourceBindings *srb[6] = {};
412 } reflectionPass;
413 } rhiRenderData;
414
416 const QVector3D &inWorldCenterPt,
417 QSSGRenderer *rendr,
418 const QSSGRenderParticles &inParticles,
419 QSSGRenderableImage *inFirstImage,
420 QSSGRenderableImage *inColorTable,
421 const QSSGShaderLightListView &inLights,
422 float inOpacity);
423};
424
425Q_STATIC_ASSERT(std::is_trivially_destructible<QSSGParticlesRenderable>::value);
426
428
429#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:75
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition qmatrix4x4.h:25
\inmodule QtGui
Definition qrhi.h:846
\inmodule QtGui
Definition qrhi.h:1270
\inmodule QtGui
Definition qrhi.h:1214
Class representing 3D range or axis aligned bounding box.
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:108
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_X(cond, x, msg)
Definition qrandom.cpp:48
QSSGRenderableObjectFlag
std::array< QMatrix4x4, 2 > QSSGRenderMvpArray
QVarLengthArray< QSSGShaderLight, 16 > QSSGShaderLightList
@ Q_PRIMITIVE_TYPE
Definition qtypeinfo.h:157
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:180
unsigned int quint32
Definition qtypes.h:50
unsigned short quint16
Definition qtypes.h:48
ptrdiff_t qsizetype
Definition qtypes.h:165
unsigned char quint8
Definition qtypes.h:46
QSvgRenderer * renderer
[0]
QSSGRenderMvpArray modelViewProjections
const QSSGRenderModel & model
QSSGModelContext(const QSSGRenderModel &inModel, const QMatrix4x4 &globalTransform, const QSSGRenderCameraDataList &allCameraData)
QSSGDataRef< QSSGSubsetRenderable > subsets
QSSGRenderableImage * colorTable
const QSSGShaderLightListView & lights
QSSGRenderableImage * firstImage
const QSSGRenderParticles & particles
std::optional< QSSGClippingFrustum > clippingFrustum
bool usesBoneTexture() const
void calculateMVPAndNormalMatrix(const QMatrix4x4 &inViewProjection, QMatrix4x4 &outMVP, QMatrix3x3 &outNormalMatrix) const
QSSGShaderLightListView lights
QSSGRenderableNodeEntry(QSSGRenderNode &inNode)
QSSGRenderableNodeEntry()=default
QVector< QSSGRenderGraphObject * > materials
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 QSSGRenderGraphObject & getMaterial() const
QSSGShaderDefaultMaterialKey shaderDescription
QSSGRenderableImage * firstImage
const QSSGModelContext & modelContext
const QSSGRenderGraphObject & material
Definition moc.h:23