QSGMaterialShader::RenderState Class

class QSGMaterialShader::RenderState

在调用QSGMaterialShader::updateUniformData() 和其他update 类型的函数时封装当前的渲染状态。更多

公共类型

enum DirtyState { DirtyMatrix, DirtyOpacity, DirtyCachedMaterialData, DirtyAll }
flags DirtyStates

公共函数

QMatrix4x4 combinedMatrix() const
float determinant() const
float devicePixelRatio() const
QRect deviceRect() const
QSGMaterialShader::RenderState::DirtyStates dirtyStates() const
bool isMatrixDirty() const
bool isOpacityDirty() const
QMatrix4x4 modelViewMatrix() const
float opacity() const
QMatrix4x4 projectionMatrix() const
QRhiResourceUpdateBatch *resourceUpdateBatch()
QRhi *rhi()
QByteArray *uniformData()
QRect viewportRect() const

详细说明

渲染状态包含大量着色器需要遵守的访问器,以便与场景图的当前状态保持一致。

成员类型文档

枚举 RenderState::DirtyState
flags RenderState::DirtyStates

常量描述
QSGMaterialShader::RenderState::DirtyMatrix0x0001用于指示矩阵已更改且必须更新。
QSGMaterialShader::RenderState::DirtyOpacity0x0002用于指示不透明度已发生变化,必须更新。
QSGMaterialShader::RenderState::DirtyCachedMaterialData0x0004用于表示缓存的材质状态已更改,必须更新。
QSGMaterialShader::RenderState::DirtyAll0xFFFF用于表示所有内容都需要更新。

DirtyStates 类型是QFlags<DirtyState> 的类型定义。它存储 DirtyState 值的 OR 组合。

成员函数文档

QMatrix4x4 RenderState::combinedMatrix() const

返回模型视图矩阵和项目矩阵的组合矩阵。

float RenderState::determinant() const

返回用于渲染的模型视图行列式。

float RenderState::devicePixelRatio() const

返回渲染时使用的物理像素与设备无关像素之间的比例。

QRect RenderState::deviceRect() const

返回正在渲染的曲面的设备矩形。

QSGMaterialShader::RenderState::DirtyStates RenderState::dirtyStates() const

返回使用此材质渲染的几何体中,哪些渲染状态已发生变化并需要更新以符合当前渲染状态。

bool RenderState::isMatrixDirty() const

如果dirtyStates() 包含脏矩阵状态,则返回true ,否则返回false

bool RenderState::isOpacityDirty() const

如果dirtyStates() 包含 dirty 不透明度状态,则返回true ,否则返回false

QMatrix4x4 RenderState::modelViewMatrix() const

返回模型视图矩阵。

如果材质设置了 RequiresFullMatrix(需要完整矩阵)标志,则保证该矩阵是根据场景图计算出来的完整变换矩阵。

但是,如果未设置该标记,渲染器可能会选择更改该矩阵。例如,它可能会在 CPU 上对顶点进行预变换,并将此矩阵设置为一致。

在上述情况下,仍然可以通过在材质中设置 RequiresDeterminant(需要行列式)标记并调用determinant() 访问器来获取实际的矩阵行列式。

float RenderState::opacity() const

返回渲染时使用的累计不透明度。

QMatrix4x4 RenderState::projectionMatrix() const

返回投影矩阵。

QRhiResourceUpdateBatch *RenderState::resourceUpdateBatch()

返回一个资源更新批次,上传和复制操作可对其进行排队。QSGMaterialShader::updateSampledImage() 通常用它来排队更新纹理图像内容。

QRhi *RenderState::rhi()

返回当前QRhi

QByteArray *RenderState::uniformData()

返回着色器中统一(常量)缓冲区数据的指针。统一数据只能从QSGMaterialShader::updateUniformData() 更新。在其他可重新实现的函数(如QSGMaterialShader::updateSampledImage() 函数)中,返回值为空。

注意: 强烈建议在着色器中使用std140 声明统一块,并仔细研究 OpenGL 规范第 7.6.2.2 节中描述的标准统一块布局。QSGMaterialShader 的实现应确保数据放置在QByteArray 的正确位置,并考虑对齐要求。翻译成其他着色语言的着色器代码应使用相同的块成员偏移量,即使目标语言默认使用不同的打包规则。

注意: 除非已经验证 C++ 结构和 GLSL 统一块的布局相匹配,否则应避免从 C++ POD 类型(如结构体)复制以同时更新多个成员。

QRect RenderState::viewportRect() const

返回正在渲染的曲面的视口矩形。

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