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 , tonemapMode(TonemapMode::Linear)
41{
42 flags = { FlagT(LocalState::Active) | FlagT(GlobalState::Active) }; // The layer node is alway active and not dirty.
43}
44
45QSSGRenderLayer::~QSSGRenderLayer()
46{
47 rootNode = nullptr;
48 rootNodeRef = nullptr;
49
50 delete importSceneNode;
51 importSceneNode = nullptr;
52
53 delete renderData;
54 renderData = nullptr;
55}
56
57void QSSGRenderLayer::setProbeOrientation(const QVector3D &angles)
58{
59 if (angles != lightProbeSettings.probeOrientationAngles) {
60 lightProbeSettings.probeOrientationAngles = angles;
61 lightProbeSettings.probeOrientation = QQuaternion::fromEulerAngles(lightProbeSettings.probeOrientationAngles).toRotationMatrix();
62 }
63}
64
65void QSSGRenderLayer::addEffect(QSSGRenderEffect &inEffect)
66{
67 // Effects need to be rendered in reverse order as described in the file.
68 inEffect.m_nextEffect = firstEffect;
69 firstEffect = &inEffect;
70}
71
72bool QSSGRenderLayer::hasEffect(QSSGRenderEffect *inEffect) const
73{
74 for (auto currentEffect = firstEffect; currentEffect != nullptr; currentEffect = currentEffect->m_nextEffect) {
75 if (currentEffect == inEffect)
76 return true;
77 }
78 return false;
79}
80
81void QSSGRenderLayer::setImportScene(QSSGRenderNode &importedNode)
82{
83 if (importedNode.parent != nullptr && !QSSGRenderGraphObjectUtils::isSceneRoot(importedNode.parent->type)) {
84 qWarning("The root of the imported scene node is already part of another scene graph.\n"
85 "Importing a sub-scene is unsupported and may not work as expected!");
86 }
87
88 // We create a dummy node to represent the imported scene tree, as we
89 // do absolutely not want to change the node links in that tree!
90 if (importSceneNode == nullptr) {
91 importSceneNode = new QSSGRenderNode(QSSGRenderGraphObject::Type::ImportScene);
92 addChild(*importSceneNode);
93 } else {
94 importSceneNode->children.clear(); // Clear the list (or the list will modify the rootNode)
95 }
96
97 // Mark all nodes as imported, this allows us to detect imported nodes later on.
98 importedNode.setState(QSSGRenderNode::LocalState::Imported);
99
100 auto &importChildren = importSceneNode->children;
101 Q_ASSERT(importChildren.isEmpty());
102 // We don't want the list to modify the imported node, so we set the tail and head manually.
103 importChildren.m_head = importChildren.m_tail = &importedNode;
104
105 // The import injects the node into the tree manually, so trigger a reindex.
106 if (rootNode != nullptr)
107 rootNode->markDirty(QSSGRenderRoot::DirtyFlag::TreeDirty);
108
109 // Now try to detect if the imported scene is used in a different window. This is not
110 // supported and might not function correctly, so we warn the user and try to be nice.
111 const bool warnAboutCrossWindowSharing = importedNode.rootNodeRef && QSSGRenderRoot::get(importedNode.rootNodeRef) != rootNode;
112 if (warnAboutCrossWindowSharing) {
113 qWarning("Sharing nodes across different windows is not supported and may lead to unexpected behavior!");
114 // NOTE: If there are multiple windows sharing the same imported scene, then we don't, and don't want
115 // to, keep track of that, so we mark the whole imported scene as dirty to force every window to
116 // update their data for the imported scene.
117 importSceneNode->markDirty(QSSGRenderNode::DirtyFlag::StickyDirty);
118 }
119}
120
121void QSSGRenderLayer::removeImportScene(QSSGRenderNode &importedNode)
122{
123 if (importSceneNode && !importSceneNode->children.isEmpty()
124 && &importSceneNode->children.back() == &importedNode) {
125 // The imported node may be shared by more than one view, so only reset state
126 // that the reindex triggered by the TreeDirty mark below will restore: that's
127 // the handle 'h' (see reindexChildNodes()). Do NOT clear LocalState::Imported
128 // or rootNodeRef here, neither is re-set by the update. The rootNodeRef will
129 // stay valid for the lifetime of the window.
130 importedNode.h = {};
131 importSceneNode->children.clear();
132 }
133
134 if (rootNode != nullptr)
135 rootNode->markDirty(QSSGRenderRoot::DirtyFlag::TreeDirty);
136}
137
138QT_END_NAMESPACE
Combined button and popup list for selecting options.