1 | // Copyright (C) 2020 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 "rendercommand_p.h" |
5 | #include "rhigraphicspipeline_p.h" |
6 | |
7 | QT_BEGIN_NAMESPACE |
8 | |
9 | namespace Qt3DRender { |
10 | namespace Render { |
11 | namespace Rhi { |
12 | |
13 | bool RenderCommand::Pipeline::isValid() const noexcept |
14 | { |
15 | struct { |
16 | bool operator()(RHIGraphicsPipeline* pipeline) const noexcept { |
17 | return pipeline && pipeline->pipeline(); |
18 | } |
19 | bool operator()(RHIComputePipeline* pipeline) const noexcept { |
20 | return pipeline && pipeline->pipeline(); |
21 | } |
22 | bool operator()(std::monostate) const noexcept { |
23 | return false; |
24 | } |
25 | } visitor; |
26 | return this->visit(f&: visitor); |
27 | } |
28 | |
29 | RenderCommand::RenderCommand() |
30 | : m_rhiShader(nullptr), |
31 | m_stateSet(nullptr), |
32 | m_depth(0.0f), |
33 | m_changeCost(0), |
34 | m_type(RenderCommand::Draw), |
35 | m_workGroups(), |
36 | m_primitiveCount(0), |
37 | m_primitiveType(QGeometryRenderer::Triangles), |
38 | m_restartIndexValue(-1), |
39 | m_firstInstance(0), |
40 | m_firstVertex(0), |
41 | m_verticesPerPatch(0), |
42 | m_instanceCount(0), |
43 | m_indexOffset(0), |
44 | m_indexAttributeByteOffset(0), |
45 | m_indexAttributeDataType(Qt3DCore::QAttribute::UnsignedShort), |
46 | m_indirectAttributeByteOffset(0), |
47 | m_drawIndexed(false), |
48 | m_drawIndirect(false), |
49 | m_primitiveRestartEnabled(false), |
50 | m_isValid(false), |
51 | indexAttribute(nullptr), |
52 | indexBuffer(nullptr), |
53 | m_commandUBO(), |
54 | pipeline() |
55 | |
56 | { |
57 | m_workGroups[0] = 0; |
58 | m_workGroups[1] = 0; |
59 | m_workGroups[2] = 0; |
60 | } |
61 | |
62 | RenderCommand::~RenderCommand() |
63 | { |
64 | if (shaderResourceBindings) |
65 | shaderResourceBindings->deleteLater(); |
66 | } |
67 | |
68 | bool RenderCommand::isValid() const noexcept |
69 | { |
70 | return m_isValid && m_rhiShader && pipeline.isValid(); |
71 | } |
72 | |
73 | bool operator==(const RenderCommand &a, const RenderCommand &b) noexcept |
74 | { |
75 | return (a.m_rhiShader == b.m_rhiShader && a.m_material == b.m_material |
76 | && a.m_stateSet == b.m_stateSet && a.m_geometry == b.m_geometry |
77 | && a.m_geometryRenderer == b.m_geometryRenderer |
78 | && a.m_indirectDrawBuffer == b.m_indirectDrawBuffer |
79 | && a.m_activeAttributes == b.m_activeAttributes && a.m_depth == b.m_depth |
80 | && a.m_changeCost == b.m_changeCost && a.m_shaderId == b.m_shaderId |
81 | && a.m_workGroups[0] == b.m_workGroups[0] && a.m_workGroups[1] == b.m_workGroups[1] |
82 | && a.m_workGroups[2] == b.m_workGroups[2] && a.m_primitiveCount == b.m_primitiveCount |
83 | && a.m_primitiveType == b.m_primitiveType |
84 | && a.m_restartIndexValue == b.m_restartIndexValue |
85 | && a.m_firstInstance == b.m_firstInstance && a.m_firstVertex == b.m_firstVertex |
86 | && a.m_verticesPerPatch == b.m_verticesPerPatch |
87 | && a.m_instanceCount == b.m_instanceCount && a.m_indexOffset == b.m_indexOffset |
88 | && a.m_indexAttributeByteOffset == b.m_indexAttributeByteOffset |
89 | && a.m_drawIndexed == b.m_drawIndexed && a.m_drawIndirect == b.m_drawIndirect |
90 | && a.m_primitiveRestartEnabled == b.m_primitiveRestartEnabled |
91 | && a.m_isValid == b.m_isValid && a.m_computeCommand == b.m_computeCommand); |
92 | } |
93 | |
94 | bool operator==(const AttributeInfo &a, const AttributeInfo &b) |
95 | { |
96 | return a.nameId == b.nameId && |
97 | a.classification == b.classification && |
98 | a.stride == b.stride && |
99 | a.offset == b.offset && |
100 | a.divisor == b.divisor; |
101 | } |
102 | |
103 | bool operator!=(const AttributeInfo &a, const AttributeInfo &b) |
104 | { |
105 | return !(a == b); |
106 | } |
107 | |
108 | } // namespace Rhi |
109 | } // namespace Render |
110 | } // namespace Qt3DRender |
111 | |
112 | QT_END_NAMESPACE |
113 | |