Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qssgrenderlayer.cpp
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// Qt-Security score:significant reason:default
5
6
7
8#include <QtQuick3DRuntimeRender/private/qssgrenderlayer_p.h>
9#include <QtQuick3DRuntimeRender/private/qssgrendereffect_p.h>
10#include "../rendererimpl/qssglayerrenderdata_p.h"
12
13#include <QtGui/qquaternion.h>
14
16
17void QSSGRenderLayer::markDirty(DirtyFlag dirtyFlag)
18{
19 m_layerDirtyFlags |= FlagT(dirtyFlag);
20 QSSGRenderNode::markDirty(QSSGRenderNode::DirtyFlag::SubNodeDirty);
21}
22
23void QSSGRenderLayer::clearDirty(DirtyFlag dirtyFlag)
24{
25 m_layerDirtyFlags &= ~FlagT(dirtyFlag);
26 QSSGRenderNode::clearDirty(QSSGRenderNode::DirtyFlag::SubNodeDirty);
27}
28
29QSSGRenderLayer::QSSGRenderLayer()
30 : QSSGRenderNode(QSSGRenderNode::Type::Layer)
31 , firstEffect(nullptr)
32 , antialiasingMode(QSSGRenderLayer::AAMode::NoAA)
33 , antialiasingQuality(QSSGRenderLayer::AAQuality::High)
34 , background(QSSGRenderLayer::Background::Transparent)
35 , temporalAAStrength(0.3f)
36 , ssaaMultiplier(1.5f)
37 , specularAAEnabled(false)
38 , oitMethod(OITMethod::None)
39 , oitMethodDirty(false)
40 , oitNodeCount(0)
41 , tonemapMode(TonemapMode::Linear)
42{
43 flags = { FlagT(LocalState::Active) | FlagT(GlobalState::Active) }; // The layer node is alway active and not dirty.
44}
45
46QSSGRenderLayer::~QSSGRenderLayer()
47{
48 rootNode = nullptr;
49 rootNodeRef = nullptr;
50
51 delete importSceneNode;
52 importSceneNode = nullptr;
53
54 delete renderData;
55 renderData = nullptr;
56}
57
58void QSSGRenderLayer::setProbeOrientation(const QVector3D &angles)
59{
60 if (angles != lightProbeSettings.probeOrientationAngles) {
61 lightProbeSettings.probeOrientationAngles = angles;
62 lightProbeSettings.probeOrientation = QQuaternion::fromEulerAngles(lightProbeSettings.probeOrientationAngles).toRotationMatrix();
63 }
64}
65
66void QSSGRenderLayer::addEffect(QSSGRenderEffect &inEffect)
67{
68 // Effects need to be rendered in reverse order as described in the file.
69 inEffect.m_nextEffect = firstEffect;
70 firstEffect = &inEffect;
71}
72
73bool QSSGRenderLayer::hasEffect(QSSGRenderEffect *inEffect) const
74{
75 for (auto currentEffect = firstEffect; currentEffect != nullptr; currentEffect = currentEffect->m_nextEffect) {
76 if (currentEffect == inEffect)
77 return true;
78 }
79 return false;
80}
81
82void QSSGRenderLayer::setImportScene(QSSGRenderNode &importedNode)
83{
84 if (importedNode.parent != nullptr && !QSSGRenderGraphObjectUtils::isSceneRoot(importedNode.parent->type)) {
85 qWarning("The root of the imported scene node is already part of another scene graph.\n"
86 "Importing a sub-scene is unsupported and may not work as expected!");
87 }
88
89 // We create a dummy node to represent the imported scene tree, as we
90 // do absolutely not want to change the node links in that tree!
91 if (importSceneNode == nullptr) {
92 importSceneNode = new QSSGRenderNode(QSSGRenderGraphObject::Type::ImportScene);
93 addChild(*importSceneNode);
94 } else {
95 importSceneNode->children.clear(); // Clear the list (or the list will modify the rootNode)
96 }
97
98 // Mark all nodes as imported, this allows us to detect imported nodes later on.
99 importedNode.setState(QSSGRenderNode::LocalState::Imported);
100
101 auto &importChildren = importSceneNode->children;
102 Q_ASSERT(importChildren.isEmpty());
103 // We don't want the list to modify the imported node, so we set the tail and head manually.
104 importChildren.m_head = importChildren.m_tail = &importedNode;
105
106 // The import injects the node into the tree manually, so trigger a reindex.
107 if (rootNode != nullptr)
108 rootNode->markDirty(QSSGRenderRoot::DirtyFlag::TreeDirty);
109
110 // Now try to detect if the imported scene is used in a different window. This is not
111 // supported and might not function correctly, so we warn the user and try to be nice.
112 const bool warnAboutCrossWindowSharing = importedNode.rootNodeRef && QSSGRenderRoot::get(importedNode.rootNodeRef) != rootNode;
113 if (warnAboutCrossWindowSharing) {
114 qWarning("Sharing nodes across different windows is not supported and may lead to unexpected behavior!");
115 // NOTE: If there are multiple windows sharing the same imported scene, then we don't, and don't want
116 // to, keep track of that, so we mark the whole imported scene as dirty to force every window to
117 // update their data for the imported scene.
118 importSceneNode->markDirty(QSSGRenderNode::DirtyFlag::StickyDirty);
119 }
120}
121
122void QSSGRenderLayer::removeImportScene(QSSGRenderNode &importedNode)
123{
124 if (importSceneNode && !importSceneNode->children.isEmpty()
125 && &importSceneNode->children.back() == &importedNode) {
126 // The imported node may be shared by more than one view, so only reset state
127 // that the reindex triggered by the TreeDirty mark below will restore: that's
128 // the handle 'h' (see reindexChildNodes()). Do NOT clear LocalState::Imported
129 // or rootNodeRef here, neither is re-set by the update. The rootNodeRef will
130 // stay valid for the lifetime of the window.
131 importedNode.h = {};
132 importSceneNode->children.clear();
133 }
134
135 if (rootNode != nullptr)
136 rootNode->markDirty(QSSGRenderRoot::DirtyFlag::TreeDirty);
137}
138
139QT_END_NAMESPACE
Combined button and popup list for selecting options.