QRhiVertexInputAttribute Class

描述单个顶点输入元素。更多

头文件: #include <rhi/qrhi.h>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::GuiPrivate)
qmake: QT += gui-private
Qt 6.6

公共类型

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

公共函数

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 &key, size_t seed = 0)
bool operator!=(const QRhiVertexInputAttribute &a, const QRhiVertexInputAttribute &b)
bool operator==(const QRhiVertexInputAttribute &a, const QRhiVertexInputAttribute &b)

详细说明

这些成员指定了单个顶点输入元素的绑定编号、位置、格式和偏移量。

注: 对于 HLSL,假定从 SPIR-V 翻译而来的顶点着色器使用TEXCOORD<location> 作为每个输入的语义。因此没有单独的语义名称和索引。

举例来说,假设顶点着色器有以下输入:

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

现在,让我们假设有 3 个组件顶点位置(x, y, z) 和 2 个组件纹理坐标(u, v) ,它们以非交错格式在一个缓冲区(甚至是单独的缓冲区)中提供。一旦定义了两个绑定,就可以将属性指定为:

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

一旦绑定了具有这种顶点输入布局的图形流水线,顶点输入的设置可如下所示,用于绘制具有 36 个顶点的立方体,假定我们有一个首先包含位置、然后包含纹理坐标的缓冲区:

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

在处理交错数据时,通常只有一个绑定点,多个属性指向同一个缓冲区绑定点:

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

然后:

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

注意: 这是一个 RHI API,兼容性保障有限,详情请参见QRhi

另请参阅 QRhiCommandBuffer::setVertexInput().

成员类型文档

enum QRhiVertexInputAttribute::Format

指定元素数据的类型。

常数描述
QRhiVertexInputAttribute::Float40四分量浮点矢量
QRhiVertexInputAttribute::Float31三分量浮点矢量
QRhiVertexInputAttribute::Float22两分量浮点矢量
QRhiVertexInputAttribute::Float3浮点
QRhiVertexInputAttribute::UNormByte44四分量归一化无符号字节向量
QRhiVertexInputAttribute::UNormByte25两分量归一化无符号字节向量
QRhiVertexInputAttribute::UNormByte6归一化无符号字节
QRhiVertexInputAttribute::UInt47四分量无符号整数向量
QRhiVertexInputAttribute::UInt38三分量无符号整数向量
QRhiVertexInputAttribute::UInt29两分量无符号整数向量
QRhiVertexInputAttribute::UInt10无符号整数
QRhiVertexInputAttribute::SInt411四分量有符号整数向量
QRhiVertexInputAttribute::SInt312三分量有符号整数向量
QRhiVertexInputAttribute::SInt213两分量有符号整数向量
QRhiVertexInputAttribute::SInt14带符号整数
QRhiVertexInputAttribute::Half415四分量半精度(16 位)浮点运算矢量
QRhiVertexInputAttribute::Half316三分量半精度(16 位)浮点运算矢量
QRhiVertexInputAttribute::Half217两分量半精度(16 位)浮点运算矢量
QRhiVertexInputAttribute::Half18半精度(16 位)浮点数
QRhiVertexInputAttribute::UShort419四分量无符号短(16 位)整数向量
QRhiVertexInputAttribute::UShort320三分量无符号短路(16 位)整数向量
QRhiVertexInputAttribute::UShort221两分量无符号短路(16 位)整数向量
QRhiVertexInputAttribute::UShort22无符号短(16 位)整数
QRhiVertexInputAttribute::SShort423四分量有符号短(16 位)整数向量
QRhiVertexInputAttribute::SShort324三分量有符号短(16 位)整数向量
QRhiVertexInputAttribute::SShort225两分量有符号短(16 位)整数向量
QRhiVertexInputAttribute::SShort26有符号短(16 位)整数

注: 运行时,QRhi::Feature::HalfAttributes 特征标志将显示对半精度浮点属性的支持。

注: Direct3D 11/12 支持 16 位输入属性,但不支持 Half3、UShort3 或 SShort3 类型。D3D 后端将 Half3 传递为 Half4,将 UShort3 传递为 UShort4,将 SShort3 传递为 SShort4。为确保跨平台兼容性,16 位输入应填充为 8 字节。

成员函数文档

[constexpr noexcept] QRhiVertexInputAttribute::QRhiVertexInputAttribute()

构建默认顶点输入属性描述。

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

用指定的binding 编号、locationformatoffset 构建顶点输入属性描述。

matrixSlice location - matrixSlice 必须始终等于展开矩阵第一行或第一列的 。location

int QRhiVertexInputAttribute::binding() const

返回绑定点索引。

另请参见 setBinding()。

QRhiVertexInputAttribute::Format QRhiVertexInputAttribute::format() const

返回顶点输入元素的格式。

另请参见 setFormat()。

int QRhiVertexInputAttribute::location() const

返回顶点输入元素的位置。

另请参见 setLocation()。

int QRhiVertexInputAttribute::matrixSlice() const

如果输入元素对应矩阵的行或列,则返回矩阵切片;如果不相关,则返回-1。

另请参见 setMatrixSlice()。

quint32 QRhiVertexInputAttribute::offset() const

返回输入元素的字节偏移量。

另请参见 setOffset()。

void QRhiVertexInputAttribute::setBinding(int b)

将绑定点索引设置为b 。默认值为 0。

另请参阅 binding().

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

将顶点输入元素的格式设置为f 。默认设置为 Float4。

另请参阅 format().

void QRhiVertexInputAttribute::setLocation(int loc)

将顶点输入元素的位置设置为loc 。默认设置为 0。

另请参见 location().

void QRhiVertexInputAttribute::setMatrixSlice(int slice)

设置矩阵slice 。默认设置为-1,只有当该属性对应于矩阵的某一行或某一列时(例如,4x4 矩阵变为 4 vec4s,消耗 4 个连续的顶点输入位置),才应将其设置为 >= 0 值,在这种情况下,它就是该行或该列的索引。location - matrixSlice 必须始终等于展开矩阵第一行或第一列的location

另请参见 matrixSlice() 。

void QRhiVertexInputAttribute::setOffset(quint32 ofs)

将输入元素的字节偏移量设置为ofs

另请参阅 offset() 。

相关非会员

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

返回key 的哈希值,使用seed 作为计算的种子。

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

如果两个QRhiVertexInputAttribute 对象ab 中的值相等,则返回false ;否则返回true

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

如果两个QRhiVertexInputAttribute 对象ab 中的值相等,则返回true

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.