QRhiShaderStage 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 | Type { Vertex, TessellationControl, TessellationEvaluation, Fragment, Compute, Geometry } |
公共函数
QRhiShaderStage() | |
QRhiShaderStage(QRhiShaderStage::Type type, const QShader &shader, QShader::Variant v = QShader::StandardShader) | |
void | setShader(const QShader &s) |
void | setShaderVariant(QShader::Variant v) |
void | setType(QRhiShaderStage::Type t) |
QShader | shader() const |
QShader::Variant | shaderVariant() const |
QRhiShaderStage::Type | type() const |
相关非成员
size_t | qHash(const QRhiShaderStage &key, size_t seed = 0) |
bool | operator!=(const QRhiShaderStage &a, const QRhiShaderStage &b) |
bool | operator==(const QRhiShaderStage &a, const QRhiShaderStage &b) |
详细说明
设置QRhiGraphicsPipeline 时,会指定着色器阶段集合。QRhiShaderStage 包含一个QShader 和一些相关元数据,如图形流水线阶段和要选择的shader variant 。无需指定着色器语言或版本,因为运行时使用的QRhi 后端会从QShader 的集合中选择合适的着色器版本。
典型的用法是与QRhiGraphicsPipeline::setShaderStages() 结合使用,这里展示了一种从离线或构建时生成的.qsb
文件加载QShader 的简单方法:
QShader getShader(const QString &name) { QFile f(name); return f.open(QIODevice::ReadOnly) ? QShader::fromSerialized(f.readAll()) : QShader(); } QShader vs = getShader("material.vert.qsb"); QShader fs = getShader("material.frag.qsb"); pipeline->setShaderStages({ { QRhiShaderStage::Vertex, vs }, { QRhiShaderStage::Fragment, fs } });
注: 这是一个 RHI API,兼容性保证有限,详情请参见QRhi 。
成员类型文档
enum QRhiShaderStage::Type
指定着色器阶段的类型。
常量 | 值 | 描述 |
---|---|---|
QRhiShaderStage::Vertex | 0 | 顶点阶段 |
QRhiShaderStage::TessellationControl | 1 | 细分控制(曲面着色器)阶段。必须仅在支持QRhi::Tessellation 功能时使用。 |
QRhiShaderStage::TessellationEvaluation | 2 | 细分评估(域着色器)阶段。必须仅在支持QRhi::Tessellation 功能时使用。 |
QRhiShaderStage::Fragment | 4 | 片段(像素着色器)阶段 |
QRhiShaderStage::Compute | 5 | 计算阶段。必须在支持QRhi::Compute 功能时使用。 |
QRhiShaderStage::Geometry | 3 | 几何图形阶段。必须仅在支持QRhi::GeometryShader 功能时使用。 |
成员函数文档
[noexcept]
QRhiShaderStage::QRhiShaderStage()
为顶点阶段构建着色器阶段描述,其中QShader 为空。
QRhiShaderStage::QRhiShaderStage(QRhiShaderStage::Type type, const QShader &shader, QShader::Variant v = QShader::StandardShader)
构建着色器舞台描述,其中包含舞台的type 和shader 。
着色器变体v 默认为QShader::StandardShader 。QShader 包含着色器的多个源代码和二进制版本。此外,它还可以包含代码略有修改的着色器变体。v ,然后可以用来选择所需的变体。
void QRhiShaderStage::setShader(const QShader &s)
设置着色器集合s 。
另请参阅 shader() 。
void QRhiShaderStage::setShaderVariant(QShader::Variant v)
设置所请求的着色器变量v 。
另请参阅 shaderVariant() 。
void QRhiShaderStage::setType(QRhiShaderStage::Type t)
将舞台类型设置为t 。实际应用中很少需要设置器。大多数应用程序在大多数情况下都会使用QRhiShaderStage 构造函数。
另请参见 type()。
QShader QRhiShaderStage::shader() const
返回图形流水线中该阶段使用的QShader 。
另请参阅 setShader().
QShader::Variant QRhiShaderStage::shaderVariant() const
返回请求的着色器变量。
另请参见 setShaderVariant().
QRhiShaderStage::Type QRhiShaderStage::type() const
返回舞台的类型。
另请参阅 setType()。
相关非会员
[noexcept]
size_t qHash(const QRhiShaderStage &key, size_t seed = 0)
返回key 的哈希值,使用seed 作为计算的种子。
[noexcept]
bool operator!=(const QRhiShaderStage &a, const QRhiShaderStage &b)
如果两个QRhiShaderStage 对象a 和b 中的值相等,则返回false
;否则返回true
。
[noexcept]
bool operator==(const QRhiShaderStage &a, const QRhiShaderStage &b)
如果两个QRhiShaderStage 对象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.