class QQuick3DTextureData

Base class for defining custom texture data. More

Inheritance diagram of PySide6.QtQuick3D.QQuick3DTextureData

Synopsis

Methods

Signals

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description

The QQuick3DTextureData class can be used to specify custom texture data for a Texture in a Qt Quick 3D scene.

While not strictly required, the typical usage is to inherit from this class. The subclass is then exposed to QML by registering it to the type system. The textureData property of a Texture can then be set to reference an instance of the registered type.

Example implementation:

class CustomTextureData : public QQuick3DTextureData
{
    Q_OBJECT
    ... properties ...

public:
    CustomTextureData() { regenerateTextureData(); }

    void setProperty(...)
    {
        // Change relevant internal data.
        // ...

        // Update the texture data
        regenerateTextureData();

        // Finally, trigger an update. This is relevant in case nothing else
        // is changed in the scene; this way we make sure a new frame will
        // be rendered
        update();
    }
private:
    void regenerateTextureData()
    {
        QByteArray textureData;
        textureData = generateTextureData();
        setTextureData(textureData);
        setSize(QSize(256, 256));
        setFormat(QQuick3DTextureData::Format::RGBA8)
        setHasTransparency(true);
    }
};

This class can then be registered as a QML type and used with Texture .

In Qt 5 type registration happened with qmlRegisterType:

qmlRegisterType<MyCustomTextureData>("Example", 1, 0, "MyCustomTextureData");

In Qt 6 the default approach is to use automatic registration with the help of the build system. Instead of calling qmlRegisterType, the .pro file can now contain:

CONFIG += qmltypes
QML_IMPORT_NAME = Example
QML_IMPORT_MAJOR_VERSION = 1

With CMake, automatic registration is the default behavior, so no special settings are needed beyond basic QML module setup:

qt_add_qml_module(application
    URI Example
    VERSION 1.0
)

The class implementation should add QML_NAMED_ELEMENT:

class CustomTextureData : public QQuick3DTextureData
{
    Q_OBJECT
    QML_NAMED_ELEMENT(MyCustomTextureData)
    ...
};

The QML code can then use the custom type:

import Example 1.0

Model {
    source: "#Cube"
    materials: [
        DefaultMaterial {
            diffuseMap: diffuseMapCustomTexture
        }
    ]
    Texture {
        id: diffuseMapCustomTexture
        textureData: MyCustomTextureData { }
    }
}
class Format

Returns the color format of the texture data assigned in textureData property.

Constant

Description

QQuick3DTextureData.None

The color format is not defined

QQuick3DTextureData.RGBA8

The color format is considered as 8-bit integer in R, G, B and alpha channels.

QQuick3DTextureData.RGBA16F

The color format is considered as 16-bit float in R,G,B and alpha channels.

QQuick3DTextureData.RGBA32F

The color format is considered as 32-bit float in R, G, B and alpha channels.

QQuick3DTextureData.RGBE8

The color format is considered as 8-bit mantissa in the R, G, and B channels and 8-bit shared exponent.

QQuick3DTextureData.R8

The color format is considered as 8-bit integer in R channel.

QQuick3DTextureData.R16

The color format is considered as 16-bit integer in R channel.

QQuick3DTextureData.R16F

The color format is considered as 16-bit float in R channel.

QQuick3DTextureData.R32F

The color format is considered as 32-bit float R channel.

QQuick3DTextureData.BC1

The color format is considred as BC1 compressed format with R, G, B, and alpha channels.

QQuick3DTextureData.BC2

The color format is considred as BC2 compressed format with R, G, B, and alpha channels.

QQuick3DTextureData.BC3

The color format is considred as BC3 compressed format with R, G, B, and alpha channels.

QQuick3DTextureData.BC4

The color format is considred as BC4 compressed format with one color channel.

QQuick3DTextureData.BC5

The color format is considred as BC5 compressed format with two color channels.

QQuick3DTextureData.BC6H

The color format is considred as BC6H compressed format with three high dynamic range color channels.

QQuick3DTextureData.BC7

The color format is considred as BC7 compressed format with R, G, B, and alpha channels.

QQuick3DTextureData.DXT1_RGBA

The color format is considered as DXT1 compressed format with R, G, B and alpha channels.

QQuick3DTextureData.DXT1_RGB

The color format is considered as DXT1 compressed format with R, G and B channels.

QQuick3DTextureData.DXT3_RGBA

The color format is considered as DXT3 compressed format with R, G, B and alpha channels.

QQuick3DTextureData.DXT5_RGBA

The color format is considered as DXT5 compressed format with R, G, B and alpha channels.

QQuick3DTextureData.ETC2_RGB8

The color format is considered as ETC2 compressed format for RGB888 data

QQuick3DTextureData.ETC2_RGB8A1

The color format is considered as ETC2 compressed format for RGBA data where alpha is 1-bit.

QQuick3DTextureData.ETC2_RGBA8

The color format is considered as ETC2 compressed format with RGBA8888 data.

QQuick3DTextureData.ASTC_4x4

The color format is considered as ASTC compressed format with 4x4 block footprint.

QQuick3DTextureData.ASTC_5x4

The color format is considered as ASTC compressed format with 5x4 block footprint.

QQuick3DTextureData.ASTC_5x5

The color format is considered as ASTC compressed format with 5x5 block footprint.

QQuick3DTextureData.ASTC_6x5

The color format is considered as ASTC compressed format with 6x5 block footprint.

QQuick3DTextureData.ASTC_6x6

The color format is considered as ASTC compressed format with 6x6 block footprint.

QQuick3DTextureData.ASTC_8x5

The color format is considered as ASTC compressed format with 8x5 block footprint.

QQuick3DTextureData.ASTC_8x6

The color format is considered as ASTC compressed format with 8x6 block footprint.

QQuick3DTextureData.ASTC_8x8

The color format is considered as ASTC compressed format with 8x8 block footprint.

QQuick3DTextureData.ASTC_10x5

The color format is considered as ASTC compressed format with 10x5 block footprint.

QQuick3DTextureData.ASTC_10x6

The color format is considered as ASTC compressed format with 10x6 block footprint.

QQuick3DTextureData.ASTC_10x8

The color format is considered as ASTC compressed format with 10x8 block footprint.

QQuick3DTextureData.ASTC_10x10

The color format is considered as ASTC compressed format with 10x10 block footprint.

QQuick3DTextureData.ASTC_12x10

The color format is considered as ASTC compressed format with 12x10 block footprint.

QQuick3DTextureData.ASTC_12x12

The color format is considered as ASTC compressed format with 12x12 block footprint.

Note

With the exception of RGBA8, not every format is supported at runtime as this depends on which backend is being used as well which hardware is being used.

Note

RGBE is internally represented as an RGBA8 but is intepreted as described when used as a lightProbe or skybox texture.

Note

Using the value None will assume the default value of RGBA8

__init__([parent=None])
Parameters:

parentQQuick3DObject

depth()
Return type:

int

Returns the depth of the texture data in pixels.

See also

setDepth()

format()
Return type:

Format

Returns the format of the texture data.

See also

setFormat()

hasTransparency()
Return type:

bool

Returns true if the texture data has transparency.

The default value is false.

setDepth(depth)
Parameters:

depth – int

Sets the depth of the texture data in pixels. Setting the depth above 0 means that the texture is handled as a 3D texture.

See also

depth()

setFormat(format)
Parameters:

formatFormat

Sets the format of the texture data.

The default format is /c RGBA8

See also

format()

setHasTransparency(hasTransparency)
Parameters:

hasTransparency – bool

Set hasTransparency to true if the texture data has an active alpha channel with non-opaque values.

This is used as an optimization by the engine so that for formats that do support an alpha channel do not need to have each value checked for non-opaque values.

setSize(size)
Parameters:

sizeQSize

Sets the size of the texture data in pixels.

See also

size()

setTextureData(data)
Parameters:

dataQByteArray

Sets the texture data. The contents of data must respect the size and format properties as the backend will try and upload and use the data as if it were a texture of size and format, and if there is any deviation the result will be somewhere between incorrect rendering of the texture, or potentially a crash.

See also

textureData()

size()
Return type:

QSize

Returns the size of the texture data in pixels.

See also

setSize()

textureData()
Return type:

QByteArray

Returns the current texture data defined by this item.

See also

setTextureData()

textureDataNodeDirty()