Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
spheregeometry_p.h
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5
6#ifndef SPHEREGEOMETRY_P_H
7#define SPHEREGEOMETRY_P_H
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists purely as an
14// implementation detail. This header file may change from version to
15// version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include <QtQuick3DHelpers/qtquick3dhelpersexports.h>
21#include <QQuick3DGeometry>
22#include <QQmlEngine>
23#include <QVector3D>
24
25#if QT_CONFIG(concurrent)
26#include <QFuture>
27#include <QFutureWatcher>
28#endif
29
31
32class Q_QUICK3DHELPERS_EXPORT SphereGeometry : public QQuick3DGeometry
33{
34 Q_OBJECT
35 Q_PROPERTY(float radius READ radius WRITE setRadius NOTIFY radiusChanged FINAL)
36 Q_PROPERTY(int rings READ rings WRITE setRings NOTIFY ringsChanged FINAL)
37 Q_PROPERTY(int segments READ segments WRITE setSegments NOTIFY segmentsChanged FINAL)
38 Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged)
39 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
40 QML_ELEMENT
41 QML_ADDED_IN_VERSION(6, 9)
42public:
43 enum Status { Null, Ready, Loading, Error };
44 Q_ENUM(Status)
45
46 explicit SphereGeometry(QQuick3DObject *parent = nullptr);
47 ~SphereGeometry() override;
48 float radius() const;
49 void setRadius(float newRadius);
50 int rings() const;
51 void setRings(int newRings);
52
53 int segments() const;
54 void setSegments(int newSegments);
55
56 bool asynchronous() const;
57 void setAsynchronous(bool newAsynchronous);
58
59 Status status() const;
60
61private Q_SLOTS:
62 void doUpdateGeometry();
63 void requestFinished();
64
65Q_SIGNALS:
66 void radiusChanged();
67 void ringsChanged();
68 void segmentsChanged();
69 void asynchronousChanged();
70 void statusChanged();
71
72private:
73 struct GeometryData {
74 QByteArray vertexData;
75 QByteArray indexData;
76 QVector3D boundsMin;
77 QVector3D boundsMax;
78 };
79
80 void scheduleGeometryUpdate();
81 void updateGeometry(const GeometryData &geometryData);
82
83 static SphereGeometry::GeometryData generateSphereGeometry(float radius,
84 int rings,
85 int segments);
86#if QT_CONFIG(concurrent)
87 static void generateSphereGeometryAsync(QPromise<SphereGeometry::GeometryData> &promise,
88 float radius,
89 int rings,
90 int segments);
91#endif
92
93 float m_radius = 100.0f;
94 int m_rings = 16;
95 int m_segments = 32;
96 bool m_asynchronous = true;
97 Status m_status = Null;
98#if QT_CONFIG(concurrent)
99 QFuture<GeometryData> m_geometryDataFuture;
100 QFutureWatcher<GeometryData> m_geometryDataWatcher;
101#endif
102 bool m_geometryUpdateRequested = false;
103 bool m_pendingAsyncUpdate = false;
104};
105
106QT_END_NAMESPACE
107
108#endif // SPHEREGEOMETRY_P_H