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 <QtQuick3DRuntimeRender/private/qssglayerrenderdata_p.h> |
9 | |
10 | QT_BEGIN_NAMESPACE |
11 | |
12 | QSSGRenderLayer::QSSGRenderLayer() |
13 | : QSSGRenderNode(QSSGRenderNode::Type::Layer) |
14 | , firstEffect(nullptr) |
15 | , antialiasingMode(QSSGRenderLayer::AAMode::NoAA) |
16 | , antialiasingQuality(QSSGRenderLayer::AAQuality::High) |
17 | , background(QSSGRenderLayer::Background::Transparent) |
18 | , lightProbe(nullptr) |
19 | , probeExposure(1.0f) |
20 | , probeHorizon(-1.0f) |
21 | , temporalAAEnabled(false) |
22 | , temporalAAStrength(0.3f) |
23 | , ssaaEnabled(false) |
24 | , ssaaMultiplier(1.5f) |
25 | , specularAAEnabled(false) |
26 | , explicitCamera(nullptr) |
27 | , renderedCamera(nullptr) |
28 | , tonemapMode(TonemapMode::Linear) |
29 | { |
30 | flags = { FlagT(LocalState::Active) | FlagT(GlobalState::Active) }; // The layer node is alway active and not dirty. |
31 | } |
32 | |
33 | QSSGRenderLayer::~QSSGRenderLayer() |
34 | { |
35 | delete importSceneNode; |
36 | importSceneNode = nullptr; |
37 | delete renderData; |
38 | } |
39 | |
40 | void QSSGRenderLayer::setProbeOrientation(const QVector3D &angles) |
41 | { |
42 | if (angles != probeOrientationAngles) { |
43 | probeOrientationAngles = angles; |
44 | probeOrientation = QQuaternion::fromEulerAngles(eulerAngles: probeOrientationAngles).toRotationMatrix(); |
45 | } |
46 | } |
47 | |
48 | void QSSGRenderLayer::addEffect(QSSGRenderEffect &inEffect) |
49 | { |
50 | // Effects need to be rendered in reverse order as described in the file. |
51 | inEffect.m_nextEffect = firstEffect; |
52 | firstEffect = &inEffect; |
53 | } |
54 | |
55 | bool QSSGRenderLayer::hasEffect(QSSGRenderEffect *inEffect) const |
56 | { |
57 | for (auto currentEffect = firstEffect; currentEffect != nullptr; currentEffect = currentEffect->m_nextEffect) { |
58 | if (currentEffect == inEffect) |
59 | return true; |
60 | } |
61 | return false; |
62 | } |
63 | |
64 | void QSSGRenderLayer::setImportScene(QSSGRenderNode &rootNode) |
65 | { |
66 | // We create a dummy node to represent the imported scene tree, as we |
67 | // do absolutely not want to change the node links in that tree! |
68 | if (importSceneNode == nullptr) { |
69 | importSceneNode = new QSSGRenderNode(QSSGRenderGraphObject::Type::ImportScene); |
70 | // Now we can add the dummy node to the layers child list |
71 | children.push_back(inObj&: *importSceneNode); |
72 | } else { |
73 | importSceneNode->children.clear(); // Clear the list (or the list will modify the rootNode) |
74 | } |
75 | |
76 | // The imported scene root node is now a child of the dummy node |
77 | auto &importChildren = importSceneNode->children; |
78 | Q_ASSERT(importChildren.isEmpty()); |
79 | // We don't want the list to modify our node, so we set the tail and head manually. |
80 | importChildren.m_head = importChildren.m_tail = &rootNode; |
81 | } |
82 | |
83 | void QSSGRenderLayer::removeImportScene(QSSGRenderNode &rootNode) |
84 | { |
85 | if (importSceneNode && !importSceneNode->children.isEmpty()) { |
86 | if (&importSceneNode->children.back() == &rootNode) |
87 | importSceneNode->children.clear(); |
88 | } |
89 | } |
90 | |
91 | QT_END_NAMESPACE |
92 | |