- Qt 6.7
- Qt GUI
- C++ Classes
- QRhiVertexInputAttribute
- Qt 6.7.0 Reference Documentation

# QRhiVertexInputAttribute Class

Describes a single vertex input element. More...

Header: | #include <QRhiVertexInputAttribute>
CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: | QT += gui
Since: | Qt 6.6

- List of all members, including inherited members

## Public Types

enum | Format { Float4, Float3, Float2, Float, UNormByte4, …, Half }

## Public Functions

| QRhiVertexInputAttribute()
| QRhiVertexInputAttribute(int binding, int location, QRhiVertexInputAttribute::Format format, quint32 offset, int matrixSlice = -1)
int | binding() const
QRhiVertexInputAttribute::Format | format() const
int | location() const
int | matrixSlice() const
quint32 | offset() const
void | setBinding(int b)
void | setFormat(QRhiVertexInputAttribute::Format f)
void | setLocation(int loc)
void | setMatrixSlice(int slice)
void | setOffset(quint32 ofs)

## Related Non-Members

size_t | qHash(const QRhiVertexInputAttribute &v, size_t seed = 0)
bool | operator!=(const QRhiVertexInputAttribute &a, const QRhiVertexInputAttribute &b)
bool | operator==(const QRhiVertexInputAttribute &a, const QRhiVertexInputAttribute &b)

## Detailed Description

The members specify the binding number, location, format, and offset for a single vertex input element.

Note: For HLSL it is assumed that the vertex shader translated from SPIR-V uses `TEXCOORD<location>` as the semantic for each input. Hence no separate semantic name and index.

As an example, assume a vertex shader with the following inputs:

     layout(location = 0) in vec4 position;
     layout(location = 1) in vec2 texcoord;

Now let's assume that we have 3 component vertex positions `(x, y, z)` and 2 component texture coordinates `(u, v)` are provided in a non-interleaved format in a buffer (or separate buffers even). Once two bindings are defined, the attributes could be specified as:

     QRhiVertexInputLayout inputLayout;
     inputLayout.setBindings({
         { 3 * sizeof(float) },
         { 2 * sizeof(float) }
     });
     inputLayout.setAttributes({
         { 0, 0, QRhiVertexInputAttribute::Float3, 0 },
         { 1, 1, QRhiVertexInputAttribute::Float2, 0 }
     });

Once a graphics pipeline with this vertex input layout is bound, the vertex inputs could be set up like the following for drawing a cube with 36 vertices, assuming we have a single buffer with first the positions and then the texture coordinates:

     const QRhiCommandBuffer::VertexInput vbufBindings[] = {
         { cubeBuf, 0 },
         { cubeBuf, 36 * 3 * sizeof(float) }
     };
     cb->setVertexInput(0, 2, vbufBindings);

When working with interleaved data, there will typically be just one binding, with multiple attributes referring to that same buffer binding point:

     QRhiVertexInputLayout inputLayout;
     inputLayout.setBindings({
         { 5 * sizeof(float) }
     });
     inputLayout.setAttributes({
         { 0, 0, QRhiVertexInputAttribute::Float3, 0 },
         { 0, 1, QRhiVertexInputAttribute::Float2, 3 * sizeof(float) }
     });

and then:

     const QRhiCommandBuffer::VertexInput vbufBinding(interleavedCubeBuf, 0);
     cb->setVertexInput(0, 1, &vbufBinding);

Note: This is a RHI API with limited compatibility guarantees, see QRhi for details.

See also QRhiCommandBuffer::setVertexInput().

## Member Type Documentation

### enum QRhiVertexInputAttribute::Format

Specifies the type of the element data.

Constant | Value | Description
--- | --- | ---
`QRhiVertexInputAttribute::Float4` | `0` | Four component float vector
`QRhiVertexInputAttribute::Float3` | `1` | Three component float vector
`QRhiVertexInputAttribute::Float2` | `2` | Two component float vector
`QRhiVertexInputAttribute::Float` | `3` | Float
`QRhiVertexInputAttribute::UNormByte4` | `4` | Four component normalized unsigned byte vector
`QRhiVertexInputAttribute::UNormByte2` | `5` | Two component normalized unsigned byte vector
`QRhiVertexInputAttribute::UNormByte` | `6` | Normalized unsigned byte
`QRhiVertexInputAttribute::UInt4` | `7` | Four component unsigned integer vector
`QRhiVertexInputAttribute::UInt3` | `8` | Three component unsigned integer vector
`QRhiVertexInputAttribute::UInt2` | `9` | Two component unsigned integer vector
`QRhiVertexInputAttribute::UInt` | `10` | Unsigned integer
`QRhiVertexInputAttribute::SInt4` | `11` | Four component signed integer vector
`QRhiVertexInputAttribute::SInt3` | `12` | Three component signed integer vector
`QRhiVertexInputAttribute::SInt2` | `13` | Two component signed integer vector
`QRhiVertexInputAttribute::SInt` | `14` | Signed integer
`QRhiVertexInputAttribute::Half4` | `15` | Four component half precision (16 bit) float vector
`QRhiVertexInputAttribute::Half3` | `16` | Three component half precision (16 bit) float vector
`QRhiVertexInputAttribute::Half2` | `17` | Two component half precision (16 bit) float vector
`QRhiVertexInputAttribute::Half` | `18` | Half precision (16 bit) float

Note: Support for half precision floating point attributes is indicated at run time by the QRhi::Feature::HalfAttributes feature flag. Note that Direct3D 11/12 supports half input attributes, but does not support the Half3 type. The D3D backends pass through Half3 as Half4. To ensure cross platform compatibility, Half3 inputs should be padded to 8 bytes.

## Member Function Documentation

### `[constexpr noexcept]` QRhiVertexInputAttribute::QRhiVertexInputAttribute()

Constructs a default vertex input attribute description.

### QRhiVertexInputAttribute::QRhiVertexInputAttribute(int binding, int location, QRhiVertexInputAttribute::Format format, quint32 offset, int matrixSlice = -1)

Constructs a vertex input attribute description with the specified binding number, location, format, and offset.

matrixSlice should be -1 except when this attribute corresponds to a row or column of a matrix (for example, a 4x4 matrix becomes 4 vec4s, consuming 4 consecutive vertex input locations), in which case it is the index of the row or column. `location - matrixSlice` must always be equal to the `location` for the first row or column of the unrolled matrix.

### int QRhiVertexInputAttribute::binding() const

Returns the binding point index.

See also setBinding().

### QRhiVertexInputAttribute::Format QRhiVertexInputAttribute::format() const

Returns the format of the vertex input element.

See also setFormat().

### int QRhiVertexInputAttribute::location() const

Returns the location of the vertex input element.

See also setLocation().

### int QRhiVertexInputAttribute::matrixSlice() const

Returns the matrix slice if the input element corresponds to a row or column of a matrix, or -1 if not relevant.

See also setMatrixSlice().

### quint32 QRhiVertexInputAttribute::offset() const

Returns the byte offset for the input element.

See also setOffset().

### void QRhiVertexInputAttribute::setBinding(int b)

Sets the binding point index to b. By default this is set to 0.

See also binding().

### void QRhiVertexInputAttribute::setFormat(QRhiVertexInputAttribute::Format f)

Sets the format of the vertex input element to f. By default this is set to Float4.

See also format().

### void QRhiVertexInputAttribute::setLocation(int loc)

Sets the location of the vertex input element to loc. By default this is set to 0.

See also location().

### void QRhiVertexInputAttribute::setMatrixSlice(int slice)

Sets the matrix slice. By default this is set to -1, and should be set to a >= 0 value only when this attribute corresponds to a row or column of a matrix (for example, a 4x4 matrix becomes 4 vec4s, consuming 4 consecutive vertex input locations), in which case it is the index of the row or column. `location - matrixSlice` must always be equal to the `location` for the first row or column of the unrolled matrix.

See also matrixSlice().

### void QRhiVertexInputAttribute::setOffset(quint32 ofs)

Sets the byte offset for the input element to ofs.

See also offset().

## Related Non-Members

### `[noexcept]` size_t qHash(const QRhiVertexInputAttribute &v, size_t seed = 0)

Returns the hash value for v, using seed to seed the calculation.

### `[noexcept]` bool operator!=(const QRhiVertexInputAttribute &a, const QRhiVertexInputAttribute &b)

Returns `false` if the values in the two QRhiVertexInputAttribute objects a and b are equal; otherwise returns `true`.

### `[noexcept]` bool operator==(const QRhiVertexInputAttribute &a, const QRhiVertexInputAttribute &b)

Returns `true` if the values in the two QRhiVertexInputAttribute objects a and b are equal.