QQuick3DShaderStorageBufferData Class

Base class for defining custom shader storage buffer content. More...

Header: #include <QQuick3DShaderStorageBufferData>
Since: Qt 6.13
In QML: ShaderStorageBufferData

Public Functions

QByteArray bufferData() const
void setBufferData(const QByteArray &bufferData)

Signals

void bufferDataDirty()

Detailed Description

The QQuick3DShaderStorageBufferData class is used to provide application-generated (CPU-side) content for a ShaderStorageBuffer in a Qt Quick 3D scene, analogous to how QQuick3DTextureData provides application-generated content for a Texture.

Instances are created by inheriting from this class and registering the subclass to the QML type system. The bufferData property of a ShaderStorageBuffer can then be set to an instance of the registered type. Assigning a QQuick3DShaderStorageBufferData also makes the buffer's size follow the size of the buffer data.

Example implementation:

 class CustomBufferData : public QQuick3DShaderStorageBufferData
 {
     ... object and QML registration macros ...
 public:
     void setValues(const QList<float> &values)
     {
         QByteArray bytes(values.size() * int(sizeof(float)), Qt::Uninitialized);
         memcpy(bytes.data(), values.constData(), bytes.size());
         setBufferData(bytes);
     }
 };

The layout of the buffer bytes has to match how the buffer is declared in the shader's STORAGE_BUFFER block; the shader's block is what determines the interpretation, this class only supplies the raw bytes.

See also QQuick3DTextureData, ShaderStorageBuffer, and ShaderStorageBufferData.

Member Function Documentation

QByteArray QQuick3DShaderStorageBufferData::bufferData() const

Returns the current buffer data.

See also setBufferData().

[signal] void QQuick3DShaderStorageBufferData::bufferDataDirty()

void QQuick3DShaderStorageBufferData::setBufferData(const QByteArray &bufferData)

Sets the buffer data to bufferData. The layout of the buffer bytes has to match how the buffer is declared in the shader's STORAGE_BUFFER block; the shader's block is what determines the interpretation, this class only supplies the raw bytes.

See also bufferData().