本页内容

QRhiShaderStage 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 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::Vertex0顶点阶段
QRhiShaderStage::TessellationControl1曲面细分控制(外壳着色器)阶段。仅在支持“QRhi::Tessellation ”功能时才可使用。
QRhiShaderStage::TessellationEvaluation2曲面细分评估(域着色器)阶段。仅在支持QRhi::Tessellation 功能时才必须使用。
QRhiShaderStage::Fragment4片段(像素着色器)阶段
QRhiShaderStage::Compute5计算阶段。仅当支持QRhi::Compute 功能时才必须使用。
QRhiShaderStage::Geometry3几何阶段。仅当支持QRhi::GeometryShader 功能时方可使用。

成员函数文档

[noexcept default] 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 。

© 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.