Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qssgmeshbvh_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QSSGMESHBVH_H
5#define QSSGMESHBVH_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 <QtQuick3DUtils/private/qtquick3dutilsglobal_p.h>
19#include <QtQuick3DUtils/private/qssgbounds3_p.h>
20#include <QtQuick3DUtils/private/qssgassert_p.h>
21
22#include <QtGui/QVector2D>
23#include <QtCore/QVector>
24
26
27class QSSGMeshBVH;
28
29class Q_QUICK3DUTILS_EXPORT QSSGMeshBVHNode
30{
31public:
32 class Handle
33 {
34 public:
35 Handle() = default;
36 bool isNull() const { return !m_owner || m_idx < size_t(FallbackIndex::Count); }
37
38 inline explicit operator const QSSGMeshBVHNode *() const;
39 inline QSSGMeshBVHNode *operator->() const;
40 private:
41 friend class QSSGMeshBVH;
42 Handle(QSSGMeshBVH *owner, size_t idx)
43 : m_owner(owner)
44 , m_idx(idx)
45 {}
46 QSSGMeshBVH *m_owner = nullptr;
47 size_t m_idx = 0;
48 };
49
50 // Internal
54 //splitAxis
55
56 // Leaf
57 int offset = 0;
58 int count = 0;
59
60private:
61 friend class QSSGMeshBVH;
62 friend class QSSGMeshBVHBuilder;
63
64 enum class FallbackIndex : quint8
65 {
66 InvalidRead = 0,
67 InvalidWrite = 1,
68 Count
69 };
70};
71
82
83using QSSGMeshBVHTriangles = std::vector<QSSGMeshBVHTriangle>;
84using QSSGMeshBVHRoots = std::vector<QSSGMeshBVHNode::Handle>;
85using QSSGMeshBVHNodes = std::vector<QSSGMeshBVHNode>;
86
87class Q_QUICK3DUTILS_EXPORT QSSGMeshBVH
88{
89public:
90 QSSGMeshBVH() = default;
92
94 {
95 m_nodes.emplace_back();
96 return { this, m_nodes.size() - 1 };
97 }
98
99 [[nodiscard]] const QSSGMeshBVHTriangles &triangles() const { return m_triangles; }
100 [[nodiscard]] const QSSGMeshBVHRoots &roots() const { return m_roots; }
101 [[nodiscard]] const QSSGMeshBVHNodes &nodes() const { return m_nodes; }
102
103private:
105 friend class QSSGMeshBVHBuilder;
106 using FallbackIndex = QSSGMeshBVHNode::FallbackIndex;
107 size_t getNodeIndex(size_t idx, FallbackIndex op) const
108 {
109 const bool valid = (idx >= size_t(FallbackIndex::Count) && idx < m_nodes.size());
110 return (valid * idx) + (!valid * size_t(op));
111 }
112
113 QSSGMeshBVHNode &mutableValue(qsizetype idx)
114 {
115 return m_nodes[getNodeIndex(idx, FallbackIndex::InvalidWrite)];
116 }
117
118 const QSSGMeshBVHNode &value(qsizetype idx) const
119 {
120 return m_nodes[getNodeIndex(idx, FallbackIndex::InvalidRead)];
121 }
122
123 QSSGMeshBVHRoots m_roots;
124 QSSGMeshBVHNodes m_nodes { { /* 0 - reserved for invalid reads */ }, { /* 1 - reserved for invalid writes */ } };
125 QSSGMeshBVHTriangles m_triangles;
126};
127
128QSSGMeshBVHNode::Handle::operator const QSSGMeshBVHNode *() const
129{
130 return &m_owner->value(m_idx);
131}
132
134{
135 return &m_owner->mutableValue(m_idx);
136}
137
139
140#endif // QSSGMESHBVH_H
Class representing 3D range or axis aligned bounding box.
QSSGMeshBVHNode * operator->() const
QSSGBounds3 boundingData
QSSGMeshBVHNode::Handle newHandle()
QSSGMeshBVH()=default
const QSSGMeshBVHRoots & roots() const
const QSSGMeshBVHNodes & nodes() const
const QSSGMeshBVHTriangles & triangles() const
The QVector2D class represents a vector or vertex in 2D space.
Definition qvectornd.h:31
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:171
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLenum GLenum GLsizei count
GLenum GLuint GLintptr offset
std::vector< QSSGMeshBVHNode > QSSGMeshBVHNodes
std::vector< QSSGMeshBVHNode::Handle > QSSGMeshBVHRoots
std::vector< QSSGMeshBVHTriangle > QSSGMeshBVHTriangles
ptrdiff_t qsizetype
Definition qtypes.h:165
unsigned char quint8
Definition qtypes.h:46