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 // Now we can add the dummy node to the layers child list
93 // NOTE: We push front because this way we'll always index the imported scene first...
94 children.push_front(*importSceneNode);
95 } else {
96 importSceneNode->children.clear(); // Clear the list (or the list will modify the rootNode)
97 }
98
99 // The imported scene root node is now a child of the dummy node
100 auto &importChildren = importSceneNode->children;
101 Q_ASSERT(importChildren.isEmpty());
102 // We don't want the list to modify our node, so we set the tail and head manually.
103 importChildren.m_head = importChildren.m_tail = &importedNode;
104
105 // Mark all nodes as imported, this allows us to detect imported nodes later on.
106 importedNode.setState(QSSGRenderNode::LocalState::Imported);
107
108 // Now try to detect if the imported scene is used in a different window. This is not
109 // supported and might not function correctly, so we warn the user and try to be nice.
110 const bool warnAboutCrossWindowSharing = importedNode.rootNodeRef && QSSGRenderRoot::get(importedNode.rootNodeRef) != rootNode;
111 if (warnAboutCrossWindowSharing) {
112 qWarning("Sharing nodes across different windows is not supported and may lead to unexpected behavior!");
113 // NOTE: If there are multiple windows sharing the same imported scene, then we don't, and don't want
114 // to, keep track of that, so we mark the whole imported scene as dirty to force every window to
115 // update their data for the imported scene.
116 importSceneNode->markDirty(QSSGRenderNode::DirtyFlag::StickyDirty);
117 }
118}
119
120void QSSGRenderLayer::removeImportScene(QSSGRenderNode &rootNode)
121{
122 if (importSceneNode && !importSceneNode->children.isEmpty()) {
123 if (&importSceneNode->children.back() == &rootNode)
124 importSceneNode->children.clear();
125 }
126}
127
128QT_END_NAMESPACE
Combined button and popup list for selecting options.