QRhiVertexInputBinding 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 | Classification { PerVertex, PerInstance } |
公共函数
QRhiVertexInputBinding() | |
QRhiVertexInputBinding(quint32 stride, QRhiVertexInputBinding::Classification cls = PerVertex, quint32 stepRate = 1) | |
QRhiVertexInputBinding::Classification | classification() const |
quint32 | instanceStepRate() const |
void | setClassification(QRhiVertexInputBinding::Classification c) |
void | setInstanceStepRate(quint32 rate) |
void | setStride(quint32 s) |
quint32 | stride() const |
相关非成员
size_t | qHash(const QRhiVertexInputBinding &key, size_t seed = 0) |
bool | operator!=(const QRhiVertexInputBinding &a, const QRhiVertexInputBinding &b) |
bool | operator==(const QRhiVertexInputBinding &a, const QRhiVertexInputBinding &b) |
详细说明
指定步长(以字节为单位,必须是 4 的倍数)、分类以及可选的实例步速。
举例来说,假设顶点着色器的输入如下:
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) } });
由于不使用实例化,因此只有跨距在这里比较重要。绑定编号由QRhiVertexInputLayout 的绑定向量中 QRhiVertexInputBinding 元素的索引给出。
一旦绑定了具有这种顶点输入布局的图形流水线,就可以像下面这样设置顶点输入,以绘制具有 36 个顶点的立方体,前提是我们有一个首先包含位置、然后包含纹理坐标的缓冲区:
const QRhiCommandBuffer::VertexInput vbufBindings[] = { { cubeBuf, 0 }, { cubeBuf, 36 * 3 * sizeof(float) } }; cb->setVertexInput(0, 2, vbufBindings);
请注意startBinding + i
所定义的索引(其中i
是setVertexInput() 的第二个参数中的索引)与QRhiVertexInputLayout 的bindings
向量中相应条目的索引是如何匹配的。
注意: stride 必须始终是 4 的倍数。
注意: 这是一个 RHI API,具有有限的兼容性保证,详情请参见QRhi 。
另请参阅 QRhiCommandBuffer::setVertexInput() 。
成员类型文档
enum QRhiVertexInputBinding::Classification
描述输入数据的分类。
常数 | 值 | 说明 |
---|---|---|
QRhiVertexInputBinding::PerVertex | 0 | 每个顶点的数据 |
QRhiVertexInputBinding::PerInstance | 1 | 数据按实例 |
成员函数文档
[constexpr noexcept]
QRhiVertexInputBinding::QRhiVertexInputBinding()
构建默认顶点输入绑定描述。
QRhiVertexInputBinding::QRhiVertexInputBinding(quint32 stride, QRhiVertexInputBinding::Classification cls = PerVertex, quint32 stepRate = 1)
用指定的stride 、分类cls 和实例步长率stepRate 构建顶点输入绑定描述。
注: 只有在报告支持QRhi::CustomInstanceStepRate 时,才支持 1 以外的stepRate 。
QRhiVertexInputBinding::Classification QRhiVertexInputBinding::classification() const
返回输入数据的分类。
另请参见 setClassification()。
quint32 QRhiVertexInputBinding::instanceStepRate() const
返回实例步进率。
另请参见 setInstanceStepRate().
void QRhiVertexInputBinding::setClassification(QRhiVertexInputBinding::Classification c)
设置输入数据分类c 。默认设置为PerVertex 。
另请参阅 classification() 。
void QRhiVertexInputBinding::setInstanceStepRate(quint32 rate)
设置实例步长rate 。默认设置为 1。
另请参阅 instanceStepRate() 。
void QRhiVertexInputBinding::setStride(quint32 s)
将跨距设置为s 。
另请参阅 stride() 。
quint32 QRhiVertexInputBinding::stride() const
以字节为单位返回字符串长度。
另请参阅 setStride()。
相关非成员
[noexcept]
size_t qHash(const QRhiVertexInputBinding &key, size_t seed = 0)
返回key 的哈希值,使用seed 作为计算的种子。
[noexcept]
bool operator!=(const QRhiVertexInputBinding &a, const QRhiVertexInputBinding &b)
如果两个QRhiVertexInputBinding 对象a 和b 中的值相等,则返回false
;否则返回true
。
[noexcept]
bool operator==(const QRhiVertexInputBinding &a, const QRhiVertexInputBinding &b)
如果两个QRhiVertexInputBinding 对象a 和b 中的值相等,则返回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.