QRhiColorAttachment Class

描述渲染目标的单一颜色附件。更多

Header: #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

公共函数

QRhiColorAttachment()
QRhiColorAttachment(QRhiRenderBuffer *renderBuffer)
QRhiColorAttachment(QRhiTexture *texture)
int layer() const
int level() const
(since 6.7) int multiViewCount() const
QRhiRenderBuffer *renderBuffer() const
int resolveLayer() const
int resolveLevel() const
QRhiTexture *resolveTexture() const
void setLayer(int layer)
void setLevel(int level)
(since 6.7) void setMultiViewCount(int count)
void setRenderBuffer(QRhiRenderBuffer *rb)
void setResolveLayer(int layer)
void setResolveLevel(int level)
void setResolveTexture(QRhiTexture *tex)
void setTexture(QRhiTexture *tex)
QRhiTexture *texture() const

详细说明

QRhiColorAttachment 是QRhiTextureQRhiRenderBuffer 的颜色附件。大多数情况下使用前者,即设置texture() 时。QRhiColorAttachment 通常与QRhiTextureRenderTargetDescription 结合使用。

注意: texture() 和renderBuffer() 不能同时设置(同时为非空)。

只有在需要多采样时,才建议设置renderBuffer 。在实践中,使用QRhi::MultisampleRenderBuffer 比使用QRhi::MultisampleTexture 更好,因为前者在更多运行时配置中可用(例如,在 OpenGL ES 3.0 上运行时,它不支持多采样纹理,但支持多采样呈现缓冲区)。

当使用非多重采样纹理时,layer() 和level() 表示目标层(立方体贴图的面索引0-5 )和 mip 级别。对于三维纹理layer() 指定了要渲染的切片(三维纹理中的一个二维图像)。对于纹理数组layer() 是数组索引。

texture() 或renderBuffer() 为多采样时,可选择设置resolveTexture()。设置后,采样会在渲染结束时自动解析到该(非多重采样)纹理中。当渲染到多采样渲染缓冲区时,这是获得已解析的非多采样内容的唯一方法。多采样纹理允许在着色器中采样,因此这只是其中一种选择。

注意: 启用解析功能后,多采样数据可能根本不会被写出。这意味着在设置resolveTexture() 后,不得将多采样texture() 与着色器一起用于采样。

注意: 这是一个 RHI API,兼容性保障有限,详情请查看QRhi

另请参阅 QRhiTextureRenderTargetDescription

成员函数文档

[constexpr noexcept] QRhiColorAttachment::QRhiColorAttachment()

构建一个空的颜色附件描述。

QRhiColorAttachment::QRhiColorAttachment(QRhiRenderBuffer *renderBuffer)

构建颜色附件描述,指定renderBuffer 为相关颜色缓冲区。

QRhiColorAttachment::QRhiColorAttachment(QRhiTexture *texture)

构建颜色附件描述,指定texture 为相关颜色缓冲区。

int QRhiColorAttachment::layer() const

返回图层索引(cubemap 面或数组图层)。默认为 0。

另请参见 setLayer()。

int QRhiColorAttachment::level() const

返回 mip 级别。默认为 0。

另请参阅 setLevel().

[since 6.7] int QRhiColorAttachment::multiViewCount() const

返回当前设置的视图数。默认值为 0,这表明带有此颜色附件的呈现目标不会用于多视图呈现。

此函数在 Qt 6.7 中引入。

另请参阅 setMultiViewCount()。

QRhiRenderBuffer *QRhiColorAttachment::renderBuffer() const

返回此附件描述引用的呈现缓冲区,如果没有,则返回nullptr

在实践中,通过多采样color 渲染缓冲器设置多采样渲染时,将QRhiRenderBufferQRhiColorAttachment 关联是最合理的,因为多采样 渲染缓冲器会在渲染结束时解析为非多采样纹理。

另请参阅 setRenderBuffer().

int QRhiColorAttachment::resolveLayer() const

返回当前设置的分辨率纹理层。默认为 0。

另请参阅 setResolveLayer()。

int QRhiColorAttachment::resolveLevel() const

返回当前设置的分辨率纹理 mip 级别。默认为 0。

另请参阅 setResolveLevel()。

QRhiTexture *QRhiColorAttachment::resolveTexture() const

返回此附件描述引用的解析纹理,如果没有,则返回nullptr

设置一个非空的解析纹理适用于附件引用多采样纹理或呈现缓冲区的情况。这时,resolveTexture() 中的QRhiTexture 将是一个具有相同大小(但样本数为 1)的非多采样 2D 纹理(或纹理数组)。多采样内容会在每次渲染结束时自动解析到该纹理中。

另请参阅 setResolveTexture()。

void QRhiColorAttachment::setLayer(int layer)

设置layer 索引。

另请参见 layer().

void QRhiColorAttachment::setLevel(int level)

设置 miplevel

另请参见 level() 。

[since 6.7] void QRhiColorAttachment::setMultiViewCount(int count)

设置视图count 。如果设置的值大于 1,则表示带有此颜色附件的呈现目标将用于多视图呈现。默认值为 0,小于 2 表示不进行多视图渲染。

count 设置为2 或更高时,颜色附件必须与二维纹理数组关联。layer()和multiViewCount() 共同定义了多视图渲染时目标纹理数组元素的范围。

例如,如果layer0multiViewCount2 ,则纹理数组必须有 2 个(或更多)元素,多视图渲染将以元素 0 和 1 为目标。着色器中的gl_ViewIndex 变量值为01 ,其中视图0 对应纹理数组元素0 ,视图1 对应数组元素1

注意: count 设置为大于 1,使用纹理数组作为texture() ,并在带有此颜色附件的QRhiTextureRenderTarget 上调用beginPass() 意味着整个渲染过程都将进行多视图渲染。multiViewCount(除非希望进行多视图渲染,否则不应设置()。除二维纹理阵列外,多视图不能与其他纹理类型一起使用。(尽管三维纹理也可以使用,但这取决于图形 API 和后端;建议应用程序不要依赖三维纹理,只使用二维纹理阵列作为多视图渲染的渲染目标)。

有关多视图渲染的更多详情,请参阅GL_OVR_multiview。请注意,在 OpenGL (ES) 上运行时,Qt 还需要GL_OVR_multiview2

只有当isFeatureSupported() 报告支持MultiView 功能时,多视图渲染才可用。

注: 为了便于移植,请注意某些图形应用程序接口对多视图渲染的限制。建议多视图渲染传递不要依赖GL_OVR_multiview声明为不支持的任何功能。唯一的例外是gl_Position 以外的着色器阶段输出(取决于gl_ViewIndex ):可以依赖这些输出(即使使用 OpenGL),因为QRhiGL_OVR_multiview2 不存在的情况下,永远不会将多视图报告为受支持。

注意: 多视图渲染不支持与细分或几何着色器结合使用,尽管某些图形 API 的某些实现可能允许这样做。

此函数在 Qt 6.7 中引入。

另请参阅 multiViewCount()。

void QRhiColorAttachment::setRenderBuffer(QRhiRenderBuffer *rb)

设置 renderbufferrb

注意: texture() 和renderBuffer() 不能同时设置(同时非空)。

另请参阅 renderBuffer()。

void QRhiColorAttachment::setResolveLayer(int layer)

设置要使用的分辨率纹理layer

另请参阅 resolveLayer()。

void QRhiColorAttachment::setResolveLevel(int level)

设置要使用的分辨率纹理 miplevel

另请参阅 resolveLevel()。

void QRhiColorAttachment::setResolveTexture(QRhiTexture *tex)

设置解析纹理tex

tex 预计是二维纹理或二维纹理数组。在这两种情况下,解析的目标都是 的单层(数组元素)的单个 mip 层。mip 层和数组层由 () 和 () 指定。tex resolveLevel resolveLayer

multiview 是一个例外:当颜色附件与纹理数组相关联并启用多视图时,解析纹理也必须是一个纹理数组,并为所有视图提供足够的元素。在这种情况下,所有与视图相对应的元素都会自动解析;其行为类似于下面的伪代码:

for (i = 0; i < multiViewCount(); ++i)
    resolve texture's layer() + i into resolveTexture's resolveLayer() + i

设置非多重采样纹理,以便在渲染过程结束时自动解析多重采样纹理或渲染缓冲区,通常比使用多重采样纹理(不设置解析纹理)更可取,因为这样可以避免编写专门用于多重采样纹理的专用片段着色器(sampler2DMStexelFetch 等),而可以使用与附件纹理一开始就不是多重采样时相同的着色器。这样做的代价是需要额外的资源(非多重采样tex )。

另请参阅 resolveTexture().

void QRhiColorAttachment::setTexture(QRhiTexture *tex)

设置纹理tex

注意: texture() 和renderBuffer() 不能同时设置(同时非空)。

另请参阅 texture()。

QRhiTexture *QRhiColorAttachment::texture() const

返回此附件描述引用的纹理,如果没有,则返回nullptr

另请参阅 setTexture()。

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