QRhiViewport Class

指定视口矩形。更多

头文件: #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

公共函数

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] 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 指定的矩形以及深度范围minDepthmaxDepth 构建视口描述。

注意: xy 假定为左下角位置。wh 不应为负数,否则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 对象ab 中的值相等,则返回false ;否则返回true

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

如果两个QRhiViewport 对象ab 中的值相等,则返回true

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