本页内容

QRhiViewport 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

公共函数

QRhiViewport()
QRhiViewport(float x, float y, float w, float h, float minDepth = 0.0f, float maxDepth = 1.0f)
float maxDepth() const
float minDepth() const
void setMaxDepth(float maxDepth)
void setMinDepth(float minDepth)
void setViewport(float x, float y, float w, float h)
std::array<float, 4> viewport() const
size_t qHash(const QRhiViewport &key, size_t seed = 0)
bool operator!=(const QRhiViewport &a, const QRhiViewport &b)
bool operator==(const QRhiViewport &a, const QRhiViewport &b)

详细说明

与QRhiCommandBuffer::setViewport() 配合使用。

QRhi 假设采用 OpenGL 风格的视口坐标系,即 x 和 y 以左下角为原点。不允许宽度和高度为负数。

典型用法如下:

const QSize outputSizeInPixels = swapchain->currentPixelSize();
const QRhiViewport viewport(0, 0, outputSizeInPixels.width(), outputSizeInPixels.height());
cb->beginPass(swapchain->currentFrameRenderTarget(), Qt::black, { 1.0f, 0 });
cb->setGraphicsPipeline(ps);
cb->setViewport(viewport);
// ...

注意:这是一个 兼容性保证有限的 RHI API,详情请参阅QRhi 。

另请参阅 QRhiCommandBuffer::setViewport()、QRhi::clipSpaceCorrMatrix() 以及QRhiScissor 。

成员函数文档

[constexpr noexcept default] QRhiViewport::QRhiViewport()

构建一个视口描述,其中包含一个空矩形,深度范围为 0.0f 至 1.0f。

另请参阅 QRhi::clipSpaceCorrMatrix()。

QRhiViewport::QRhiViewport(float x, float y, float w, float h, float minDepth = 0.0f, float maxDepth = 1.0f)

根据由x 、y 、w 、h 指定的矩形,以及由minDepth 和maxDepth 指定的深度范围,构建一个视口描述。

注意: x 和y 默认表示左下角位置。w 和h 不应为负数,否则QRhiCommandBuffer::setViewport() 将忽略该视口。

另请参阅 QRhi::clipSpaceCorrMatrix()。

float QRhiViewport::maxDepth() const

返回视口深度范围的 maxDepth 值。

另请参阅 ` setMaxDepth()`。

float QRhiViewport::minDepth() const

返回视口深度范围的 minDepth 值。

另请参阅 setMinDepth()。

void QRhiViewport::setMaxDepth(float maxDepth)

设置视口深度范围的maxDepth 值。默认值为1.0f。

另请参阅 maxDepth()。

void QRhiViewport::setMinDepth(float minDepth)

设置视口深度范围的minDepth 。默认值为0.0f。

另请参阅 minDepth()。

void QRhiViewport::setViewport(float x, float y, float w, float h)

将视口的的位置和大小分别设置为x 、y 、w 和h 。

注意:视口的 坐标系原点位于左下角。

另请参阅 viewport()。

std::array<float, 4> QRhiViewport::viewport() const

返回视口的 x、y、宽度和高度。

另请参阅 ` setViewport()`。

相关的非成员

[noexcept] size_t qHash(const QRhiViewport &key, size_t seed = 0)

返回key 的哈希值,并使用seed 作为计算的种子。

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

如果两个QRhiViewport 对象a 和b 中的值相等,则返回false ;否则返回true 。

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

如果两个QRhiViewport 对象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.