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
5
6#include <QtQuick3DRuntimeRender/private/qssgrenderlayer_p.h>
7#include <QtQuick3DRuntimeRender/private/qssgrendereffect_p.h>
8#include "../rendererimpl/qssglayerrenderdata_p.h"
10
11#include <QtGui/qquaternion.h>
12
14
15void QSSGRenderLayer::markDirty(DirtyFlag dirtyFlag)
16{
17 m_layerDirtyFlags |= FlagT(dirtyFlag);
18 QSSGRenderNode::markDirty(QSSGRenderNode::DirtyFlag::SubNodeDirty);
19}
20
21void QSSGRenderLayer::clearDirty(DirtyFlag dirtyFlag)
22{
23 m_layerDirtyFlags &= ~FlagT(dirtyFlag);
24 QSSGRenderNode::clearDirty(QSSGRenderNode::DirtyFlag::SubNodeDirty);
25}
26
27QSSGRenderLayer::QSSGRenderLayer()
28 : QSSGRenderNode(QSSGRenderNode::Type::Layer)
29 , firstEffect(nullptr)
30 , antialiasingMode(QSSGRenderLayer::AAMode::NoAA)
31 , antialiasingQuality(QSSGRenderLayer::AAQuality::High)
32 , background(QSSGRenderLayer::Background::Transparent)
33 , temporalAAStrength(0.3f)
34 , ssaaMultiplier(1.5f)
35 , specularAAEnabled(false)
36 , oitMethod(OITMethod::None)
37 , oitMethodDirty(false)
38 , tonemapMode(TonemapMode::Linear)
39{
40 flags = { FlagT(LocalState::Active) | FlagT(GlobalState::Active) }; // The layer node is alway active and not dirty.
41}
42
43QSSGRenderLayer::~QSSGRenderLayer()
44{
45 rootNode = nullptr;
46 rootNodeRef = nullptr;
47
48 delete importSceneNode;
49 importSceneNode = nullptr;
50
51 delete renderData;
52 renderData = nullptr;
53}
54
55void QSSGRenderLayer::setProbeOrientation(const QVector3D &angles)
56{
57 if (angles != lightProbeSettings.probeOrientationAngles) {
58 lightProbeSettings.probeOrientationAngles = angles;
59 lightProbeSettings.probeOrientation = QQuaternion::fromEulerAngles(lightProbeSettings.probeOrientationAngles).toRotationMatrix();
60 }
61}
62
63void QSSGRenderLayer::addEffect(QSSGRenderEffect &inEffect)
64{
65 // Effects need to be rendered in reverse order as described in the file.
66 inEffect.m_nextEffect = firstEffect;
67 firstEffect = &inEffect;
68}
69
70bool QSSGRenderLayer::hasEffect(QSSGRenderEffect *inEffect) const
71{
72 for (auto currentEffect = firstEffect; currentEffect != nullptr; currentEffect = currentEffect->m_nextEffect) {
73 if (currentEffect == inEffect)
74 return true;
75 }
76 return false;
77}
78
79void QSSGRenderLayer::setImportScene(QSSGRenderNode &importedNode)
80{
81 if (importedNode.parent != nullptr) {
82 qWarning("The root of the imported scene node is already part of another scene graph.\n"
83 "Importing a sub-scene is unsupported and may not work as expected!");
84 }
85
86 // We create a dummy node to represent the imported scene tree, as we
87 // do absolutely not want to change the node links in that tree!
88 if (importSceneNode == nullptr) {
89 importSceneNode = new QSSGRenderNode(QSSGRenderGraphObject::Type::ImportScene);
90 // Now we can add the dummy node to the layers child list
91 // NOTE: We push front because this way we'll always index the imported scene first...
92 children.push_front(*importSceneNode);
93 } else {
94 importSceneNode->children.clear(); // Clear the list (or the list will modify the rootNode)
95 }
96
97 // The imported scene root node is now a child of the dummy node
98 auto &importChildren = importSceneNode->children;
99 Q_ASSERT(importChildren.isEmpty());
100 // We don't want the list to modify our node, so we set the tail and head manually.
101 importChildren.m_head = importChildren.m_tail = &importedNode;
102
103 // Mark all nodes as imported, this allows us to detect imported nodes later on.
104 importedNode.setState(QSSGRenderNode::LocalState::Imported);
105
106 // Now try to detect if the imported scene is used in a different window. This is not
107 // supported and might not function correctly, so we warn the user and try to be nice.
108 const bool warnAboutCrossWindowSharing = importedNode.rootNodeRef && QSSGRenderRoot::get(importedNode.rootNodeRef) != rootNode;
109 if (warnAboutCrossWindowSharing) {
110 qWarning("Sharing nodes across different windows is not supported and may lead to unexpected behavior!");
111 // NOTE: If there are multiple windows sharing the same imported scene, then we don't, and don't want
112 // to, keep track of that, so we mark the whole imported scene as dirty to force every window to
113 // update their data for the imported scene.
114 importSceneNode->markDirty(QSSGRenderNode::DirtyFlag::StickyDirty);
115 }
116}
117
118void QSSGRenderLayer::removeImportScene(QSSGRenderNode &rootNode)
119{
120 if (importSceneNode && !importSceneNode->children.isEmpty()) {
121 if (&importSceneNode->children.back() == &rootNode)
122 importSceneNode->children.clear();
123 }
124}
125
126QT_END_NAMESPACE
Combined button and popup list for selecting options.