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

source code of qtquick3d/src/runtimerender/graphobjects/qssgrenderlayer.cpp