1 | // Copyright (C) 2022 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QSSGDEBUGDRAWSYSTEM_H |
5 | #define QSSGDEBUGDRAWSYSTEM_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtQuick3DRuntimeRender/private/qtquick3druntimerenderglobal_p.h> |
19 | #include <QtQuick3DRuntimeRender/private/qssgrhicontext_p.h> |
20 | #include <QtQuick3DUtils/private/qssgbounds3_p.h> |
21 | #include <QtGui/QVector3D> |
22 | #include <QtGui/QColor> |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | struct QSSGRenderSubset; |
27 | class QSSGBufferManager; |
28 | struct QSSGModelContext; |
29 | |
30 | class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGDebugDrawSystem |
31 | { |
32 | Q_DISABLE_COPY(QSSGDebugDrawSystem) |
33 | public: |
34 | QSSGDebugDrawSystem(); |
35 | ~QSSGDebugDrawSystem(); |
36 | |
37 | bool hasContent() const; |
38 | |
39 | void drawLine(const QVector3D &startPoint, |
40 | const QVector3D &endPoint, |
41 | const QColor &color, |
42 | bool isPersistent = false); |
43 | void drawBounds(const QSSGBounds3 &bounds, |
44 | const QColor &color, |
45 | bool isPersistent = false); |
46 | void drawPoint(const QVector3D &vertex, |
47 | const QColor &color, |
48 | bool isPersistent = false); |
49 | |
50 | void prepareGeometry(QSSGRhiContext *rhiCtx, QRhiResourceUpdateBatch *rub); |
51 | void recordRenderDebugObjects(QSSGRhiContext *rhiCtx, |
52 | QSSGRhiGraphicsPipelineState *ps, |
53 | QRhiShaderResourceBindings *srb, |
54 | QRhiRenderPassDescriptor *rpDesc); |
55 | |
56 | void setEnabled(bool v); |
57 | [[nodiscard]] bool isEnabled() const { return Mode(modes) != Mode::None; } |
58 | |
59 | private: |
60 | friend class QSSGLayerRenderData; |
61 | |
62 | enum class Mode : quint8 |
63 | { |
64 | None, |
65 | MeshLod = 0x1, |
66 | MeshLodNormal = 0x2, |
67 | Other = 0x4 |
68 | }; |
69 | using ModeFlagT = std::underlying_type_t<Mode>; |
70 | |
71 | struct LineData { |
72 | QVector3D startPoint; |
73 | QVector3D endPoint; |
74 | QColor color; |
75 | }; |
76 | struct BoundsData { |
77 | QSSGBounds3 bounds; |
78 | QColor color; |
79 | }; |
80 | struct VertexData { |
81 | QVector3D position; |
82 | QVector3D color; |
83 | }; |
84 | |
85 | |
86 | void generateLine(const LineData &line, QVector<VertexData> &vertexArray, QVector<quint32> &indexArray); |
87 | void generateBox(const BoundsData &bounds, QVector<VertexData> &vertexArray, QVector<quint32> &indexArray); |
88 | |
89 | // Internal helper functions |
90 | [[nodiscard]] bool isEnabled(Mode mode) const { return ((ModeFlagT(mode) & modes) != 0); } |
91 | [[nodiscard]] static QColor levelOfDetailColor(quint32 lod); |
92 | void debugNormals(QSSGBufferManager &bufferManager, const QSSGModelContext &theModelContext, const QSSGRenderSubset &theSubset, quint32 subsetLevelOfDetail, float lineLength); |
93 | |
94 | quint32 m_indexSize = 0; |
95 | quint32 m_pointsSize = 0; |
96 | QVector<LineData> m_persistentLines; |
97 | QVector<LineData> m_lines; |
98 | QVector<BoundsData> m_persistentBounds; |
99 | QVector<BoundsData> m_bounds; |
100 | QVector<VertexData> m_persistentPoints; |
101 | QVector<VertexData> m_points; |
102 | |
103 | QSSGRhiBufferPtr m_lineVertexBuffer; |
104 | QSSGRhiBufferPtr m_lineIndexBuffer; |
105 | QSSGRhiBufferPtr m_pointVertexBuffer; |
106 | |
107 | ModeFlagT modes { 0 }; |
108 | }; |
109 | |
110 | QT_END_NAMESPACE |
111 | |
112 | #endif // QSSGDEBUGDRAWSYSTEM_H |
113 | |