QRhiShaderStage Class

Specifies the type and the shader code for a shader stage in the pipeline. 更多...

头: #include <QRhiShaderStage>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
Since: 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 & v , size_t seed = 0)
bool operator!= (const QRhiShaderStage & a , const QRhiShaderStage & b )
bool operator== (const QRhiShaderStage & a , const QRhiShaderStage & b )

详细描述

When setting up a QRhiGraphicsPipeline , a collection of shader stages are specified. The QRhiShaderStage contains a QShader and some associated metadata, such as the graphics pipeline stage, and the shader variant to select. There is no need to specify the shader language or version because the QRhi backend in use at runtime will take care of choosing the appropriate shader version from the collection within the QShader .

The typical usage is in combination with QRhiGraphicsPipeline::setShaderStages (), shown here with a simple approach to load the QShader from .qsb files generated offline or at build time:

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 }
});
					

注意: This is a RHI API with limited compatibility guarantees, see QRhi 了解细节。

成员类型文档编制

enum QRhiShaderStage:: Type

Specifies the type of the shader stage.

常量 描述
QRhiShaderStage::Vertex 0 Vertex stage
QRhiShaderStage::TessellationControl 1 Tessellation control (hull shader) stage. Must be used only when the QRhi::Tessellation feature is supported.
QRhiShaderStage::TessellationEvaluation 2 Tessellation evaluation (domain shader) stage. Must be used only when the QRhi::Tessellation feature is supported.
QRhiShaderStage::Fragment 4 Fragment (pixel shader) stage
QRhiShaderStage::Compute 5 Compute stage. Must be used only when the QRhi::Compute feature is supported.
QRhiShaderStage::Geometry 3 Geometry stage. Must be used only when the QRhi::GeometryShader feature is supported.

成员函数文档编制

[noexcept] QRhiShaderStage:: QRhiShaderStage ()

Constructs a shader stage description for the vertex stage with an empty QShader .

QRhiShaderStage:: QRhiShaderStage ( QRhiShaderStage::Type type , const QShader & shader , QShader::Variant v = QShader::StandardShader)

Constructs a shader stage description with the type of the stage and the shader .

The shader variant v 默认为 QShader::StandardShader QShader contains multiple source and binary versions of a shader. In addition, it can also contain variants of the shader with slightly modified code. v can then be used to select the desired variant.

void QRhiShaderStage:: setShader (const QShader & s )

Sets the shader collection s .

另请参阅 shader ().

void QRhiShaderStage:: setShaderVariant ( QShader::Variant v )

Sets the requested shader variant v .

另请参阅 shaderVariant ().

void QRhiShaderStage:: setType ( QRhiShaderStage::Type t )

Sets the type of the stage to t . Setters should rarely be needed in pratice. Most applications will likely use the QRhiShaderStage constructor in most cases.

另请参阅 type ().

QShader QRhiShaderStage:: shader () const

返回 QShader to be used for this stage in the graphics pipeline.

另请参阅 setShader ().

QShader::Variant QRhiShaderStage:: shaderVariant () const

Returns the requested shader variant.

另请参阅 setShaderVariant ().

QRhiShaderStage::Type QRhiShaderStage:: type () const

Returns the type of the stage.

另请参阅 setType ().

相关非成员

[noexcept] size_t qHash (const QRhiShaderStage & v , size_t seed = 0)

返回哈希值为 v ,使用 seed 做计算种子。

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

返回 false if the values in the two QRhiShaderStage 对象 a and b 相等;否则返回 true .

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

返回 true if the values in the two QRhiShaderStage 对象 a and b 相等。