QRhiVertexInputAttribute Class

Describes a single vertex input element. 更多...

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

公共类型

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

公共函数

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 )
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 )

详细描述

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

注意: 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);
					

注意: This is a RHI API with limited compatibility guarantees, see QRhi 了解细节。

另请参阅 QRhiCommandBuffer::setVertexInput ().

成员类型文档编制

enum QRhiVertexInputAttribute:: Format

Specifies the type of the element data.

常量 描述
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

注意: 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.

成员函数文档编制

[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 ,和 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.

另请参阅 setBinding ().

QRhiVertexInputAttribute::Format QRhiVertexInputAttribute:: format () const

Returns the format of the vertex input element.

另请参阅 setFormat ().

int QRhiVertexInputAttribute:: location () const

Returns the location of the vertex input element.

另请参阅 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.

另请参阅 setMatrixSlice ().

quint32 QRhiVertexInputAttribute:: offset () const

Returns the byte offset for the input element.

另请参阅 setOffset ().

void QRhiVertexInputAttribute:: setBinding ( int b )

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

另请参阅 binding ().

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

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

另请参阅 format ().

void QRhiVertexInputAttribute:: setLocation ( int loc )

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

另请参阅 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.

另请参阅 matrixSlice ().

void QRhiVertexInputAttribute:: setOffset ( quint32 ofs )

Sets the byte offset for the input element to ofs .

另请参阅 offset ().

相关非成员

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

返回哈希值为 v ,使用 seed 做计算种子。

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

返回 false if the values in the two QRhiVertexInputAttribute 对象 a and b 相等;否则返回 true .

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

返回 true if the values in the two QRhiVertexInputAttribute 对象 a and b 相等。