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
qquick3dshaderstoragebufferdata.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 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#include <QtQuick3D/private/qquick3dshaderstoragebufferdata_p.h>
6
7QT_BEGIN_NAMESPACE
8
9/*!
10 \qmltype ShaderStorageBufferData
11 \inqmlmodule QtQuick3D
12 \nativetype QQuick3DShaderStorageBufferData
13 \brief Base type for CPU-authored shader storage buffer content.
14 \since 6.13
15
16 ShaderStorageBufferData is the base type for providing application-generated
17 (CPU-side) content for a \l ShaderStorageBuffer, analogous to how
18 \l TextureData provides application-generated content for a \l Texture.
19 It cannot be instantiated directly from QML; instead, subclass
20 QQuick3DShaderStorageBufferData in C++, set the data with \l{QQuick3DShaderStorageBufferData::}{setBufferData()}
21 and register the subclass to QML. Once registered, it can be assigned
22 to a \l{ShaderStorageBuffer::bufferData}{ShaderStorageBuffer's bufferData} property.
23
24 The \c QQuick3DShaderStorageBufferData::bufferDataDirty() signal is emitted whenever the data
25 changes, so the ShaderStorageBuffer using it can pick up the new content
26 (and, if its size changed, propagate that too).
27
28 \sa ShaderStorageBuffer, TextureData
29*/
30
31/*!
32 \class QQuick3DShaderStorageBufferData
33 \inmodule QtQuick3D
34 \since 6.13
35 \brief Base class for defining custom shader storage buffer content.
36
37 The QQuick3DShaderStorageBufferData class is used to provide application-generated
38 (CPU-side) content for a \l ShaderStorageBuffer in a Qt Quick 3D scene,
39 analogous to how \l QQuick3DTextureData provides application-generated
40 content for a \l {QtQuick3D::Texture}{Texture}.
41
42 Instances are created by inheriting from this class and registering the
43 subclass to the QML type system. The \l{ShaderStorageBuffer::bufferData}{bufferData}
44 property of a \l ShaderStorageBuffer can then be set to an instance of the registered
45 type. Assigning a QQuick3DShaderStorageBufferData also makes the buffer's
46 \l{ShaderStorageBuffer::size}{size} follow the size of the buffer data.
47
48 Example implementation:
49
50 \code
51 class CustomBufferData : public QQuick3DShaderStorageBufferData
52 {
53 ... object and QML registration macros ...
54 public:
55 void setValues(const QList<float> &values)
56 {
57 QByteArray bytes(values.size() * int(sizeof(float)), Qt::Uninitialized);
58 memcpy(bytes.data(), values.constData(), bytes.size());
59 setBufferData(bytes);
60 }
61 };
62 \endcode
63
64 The layout of the buffer bytes has to match how the buffer is declared
65 in the shader's \c STORAGE_BUFFER block; the shader's block is what
66 determines the interpretation, this class only supplies the raw bytes.
67
68 \sa QQuick3DTextureData, ShaderStorageBuffer, ShaderStorageBufferData
69*/
70
71QQuick3DShaderStorageBufferData::QQuick3DShaderStorageBufferData(QObject *parent)
72 : QQuick3DShaderStorageBufferData(*new QQuick3DShaderStorageBufferDataPrivate, parent)
73{
74}
75
76/*!
77 \internal
78*/
79QQuick3DShaderStorageBufferData::QQuick3DShaderStorageBufferData(QQuick3DShaderStorageBufferDataPrivate &dd, QObject *parent)
80 : QObject(dd, parent)
81{
82}
83
84QQuick3DShaderStorageBufferData::~QQuick3DShaderStorageBufferData() = default;
85
86/*!
87 Returns the current buffer data.
88*/
89QByteArray QQuick3DShaderStorageBufferData::bufferData() const
90{
91 Q_D(const QQuick3DShaderStorageBufferData);
92 return d->bufferData;
93}
94
95/*!
96 Sets the buffer data to \a bufferData. The layout of the buffer bytes has to match
97 how the buffer is declared in the shader's \c STORAGE_BUFFER block;
98 the shader's block is what determines the interpretation, this
99 class only supplies the raw bytes.
100*/
101void QQuick3DShaderStorageBufferData::setBufferData(const QByteArray &bufferData)
102{
103 Q_D(QQuick3DShaderStorageBufferData);
104 d->bufferData = bufferData;
105 emit bufferDataDirty();
106}
107
108QT_END_NAMESPACE