1// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "clearbuffers_p.h"
5#include <Qt3DRender/private/qclearbuffers_p.h>
6
7QT_BEGIN_NAMESPACE
8
9using namespace Qt3DCore;
10
11namespace Qt3DRender {
12namespace Render {
13
14static QVector4D vec4dFromColor(const QColor &color)
15{
16 if (!color.isValid())
17 return QVector4D(0.0f, 0.0f, 0.0f, 1.0f);
18 return QVector4D(float(color.redF()), float(color.greenF()), float(color.blueF()), float(color.alphaF()));
19}
20
21ClearBuffers::ClearBuffers()
22 : FrameGraphNode(FrameGraphNode::ClearBuffers)
23 , m_type(QClearBuffers::None)
24 , m_clearColorAsColor(Qt::black)
25 , m_clearColor(vec4dFromColor(color: m_clearColorAsColor))
26 , m_clearDepthValue(1.f)
27 , m_clearStencilValue(0)
28{
29}
30
31void ClearBuffers::syncFromFrontEnd(const QNode *frontEnd, bool firstTime)
32{
33 const QClearBuffers *node = qobject_cast<const QClearBuffers *>(object: frontEnd);
34 if (!node)
35 return;
36
37 FrameGraphNode::syncFromFrontEnd(frontEnd, firstTime);
38
39 if (m_clearColorAsColor != node->clearColor()) {
40 m_clearColorAsColor = node->clearColor();
41 m_clearColor = vec4dFromColor(color: node->clearColor());
42 markDirty(changes: AbstractRenderer::FrameGraphDirty);
43 }
44
45 if (!qFuzzyCompare(p1: m_clearDepthValue, p2: node->clearDepthValue())) {
46 m_clearDepthValue = node->clearDepthValue();
47 markDirty(changes: AbstractRenderer::FrameGraphDirty);
48 }
49
50 if (m_clearStencilValue != node->clearStencilValue()) {
51 m_clearStencilValue = node->clearStencilValue();
52 markDirty(changes: AbstractRenderer::FrameGraphDirty);
53 }
54
55 const QNodeId colorBufferId = qIdForNode(node: node->colorBuffer());
56 if (m_colorBufferId != colorBufferId) {
57 m_colorBufferId = colorBufferId;
58 markDirty(changes: AbstractRenderer::FrameGraphDirty);
59 }
60
61 if (m_type != node->buffers()) {
62 m_type = node->buffers();
63 markDirty(changes: AbstractRenderer::FrameGraphDirty);
64 }
65}
66
67QClearBuffers::BufferType ClearBuffers::type() const
68{
69 return m_type;
70}
71
72QColor ClearBuffers::clearColorAsColor() const
73{
74 return m_clearColorAsColor;
75}
76
77QVector4D ClearBuffers::clearColor() const
78{
79 return m_clearColor;
80}
81
82float ClearBuffers::clearDepthValue() const
83{
84 return m_clearDepthValue;
85}
86
87int ClearBuffers::clearStencilValue() const
88{
89 return m_clearStencilValue;
90}
91
92Qt3DCore::QNodeId ClearBuffers::bufferId() const
93{
94 return m_colorBufferId;
95}
96
97bool ClearBuffers::clearsAllColorBuffers() const
98{
99 return m_colorBufferId.isNull();
100}
101
102} // namespace Render
103} // namespace Qt3DRender
104
105QT_END_NAMESPACE
106

source code of qt3d/src/render/framegraph/clearbuffers.cpp