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