QRhiVertexInputAttribute Class
描述了一个单顶点输入元素。更多...
| 头文件: | #include <rhi/qrhi.h> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS GuiPrivate) 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::Float4 | 0 | 四元浮点向量 |
QRhiVertexInputAttribute::Float3 | 1 | 三元浮点向量 |
QRhiVertexInputAttribute::Float2 | 2 | 双分量浮点向量 |
QRhiVertexInputAttribute::Float | 3 | 浮点数 |
QRhiVertexInputAttribute::UNormByte4 | 4 | 四分量归一化无符号字节向量 |
QRhiVertexInputAttribute::UNormByte2 | 5 | 两分量归一化无符号字节向量 |
QRhiVertexInputAttribute::UNormByte | 6 | 归一化无符号字节 |
QRhiVertexInputAttribute::UInt4 | 7 | 四分量无符号整数向量 |
QRhiVertexInputAttribute::UInt3 | 8 | 三元无符号整数向量 |
QRhiVertexInputAttribute::UInt2 | 9 | 两维无符号整数向量 |
QRhiVertexInputAttribute::UInt | 10 | 无符号整数 |
QRhiVertexInputAttribute::SInt4 | 11 | 四元有符号整数向量 |
QRhiVertexInputAttribute::SInt3 | 12 | 三元有符号整数向量 |
QRhiVertexInputAttribute::SInt2 | 13 | 两维带符号整数向量 |
QRhiVertexInputAttribute::SInt | 14 | 有符号整数 |
QRhiVertexInputAttribute::Half4 | 15 | 四分量半精度(16 位)浮点向量 |
QRhiVertexInputAttribute::Half3 | 16 | 三元素半精度(16 位)浮点向量 |
QRhiVertexInputAttribute::Half2 | 17 | 两元半精度(16 位)浮点向量 |
QRhiVertexInputAttribute::Half | 18 | 半精度(16 位)浮点数 |
QRhiVertexInputAttribute::UShort4 | 19 | 四分量无符号短整型(16 位)向量 |
QRhiVertexInputAttribute::UShort3 | 20 | 三元无符号短整型(16 位)向量 |
QRhiVertexInputAttribute::UShort2 | 21 | 两元无符号短整型(16 位)向量 |
QRhiVertexInputAttribute::UShort | 22 | 无符号短整数(16 位) |
QRhiVertexInputAttribute::SShort4 | 23 | 四分量有符号短整型(16 位)向量 |
QRhiVertexInputAttribute::SShort3 | 24 | 三元有符号短整数(16 位)向量 |
QRhiVertexInputAttribute::SShort2 | 25 | 两元有符号短整型(16 位)向量 |
QRhiVertexInputAttribute::SShort | 26 | 有符号短整数(16 位) 注: 对半精度浮点属性的支持 由运行时的QRhi::Feature::HalfAttributes 特性标志指示。 注意:Direct3D 11/12 支持 16 位输入属性,但不支持 Half3、UShort3 或 SShort3 类型。 D3D 后端将 Half3 作为 Half4 传递,将 UShort3 作为 UShort4 传递,将 SShort3 作为 SShort4 传递。为确保跨平台兼容性,16 位输入应补零至 8 字节。 |
成员函数文档
[constexpr noexcept default] QRhiVertexInputAttribute::QRhiVertexInputAttribute()
构建一个默认的顶点输入属性描述。
QRhiVertexInputAttribute::QRhiVertexInputAttribute(int binding, int location, QRhiVertexInputAttribute::Format format, quint32 offset, int matrixSlice = -1)
构建一个顶点输入属性描述,其中包含指定的binding 数值、location 、format 以及offset 。
matrixSlice 该值应为 -1,除非该属性对应于矩阵的一行或一列(例如,一个 4x4 矩阵将变为 4 个 vec4,占用 4 个连续的顶点输入位置),在这种情况下,该值即为该行或列的索引。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 个 vec4,占用 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 对象a 和b 中的值相等,则返回false ;否则返回true 。
[noexcept] bool operator==(const QRhiVertexInputAttribute &a, const QRhiVertexInputAttribute &b)
如果两个QRhiVertexInputAttribute 对象a 和b 中的值相等,则返回true 。
© 2026 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.