QRhiViewport Class

Specifies a viewport rectangle. More...

Header: #include <rhi/qrhi.h>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::GuiPrivate)
qmake: QT += gui-private
Since: Qt 6.6

Public Functions

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 &v, size_t seed = 0)
bool operator!=(const QRhiViewport &a, const QRhiViewport &b)
bool operator==(const QRhiViewport &a, const QRhiViewport &b)

Detailed Description

Used with QRhiCommandBuffer::setViewport().

QRhi assumes OpenGL-style viewport coordinates, meaning x and y are bottom-left. Negative width or height are not allowed.

Typical usage is like the following:

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);
// ...

Note: This is a RHI API with limited compatibility guarantees, see QRhi for details.

See also QRhiCommandBuffer::setViewport(), QRhi::clipSpaceCorrMatrix(), and QRhiScissor.

Member Function Documentation

[constexpr noexcept] QRhiViewport::QRhiViewport()

Constructs a viewport description with an empty rectangle and a depth range of 0.0f - 1.0f.

See also QRhi::clipSpaceCorrMatrix().

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

Constructs a viewport description with the rectangle specified by x, y, w, h and the depth range minDepth and maxDepth.

Note: x and y are assumed to be the bottom-left position. w and h should not be negative, the viewport will be ignored by QRhiCommandBuffer::setViewport() otherwise.

See also QRhi::clipSpaceCorrMatrix().

float QRhiViewport::maxDepth() const

Returns the maxDepth value of the depth range of the viewport.

See also setMaxDepth().

float QRhiViewport::minDepth() const

Returns the minDepth value of the depth range of the viewport.

See also setMinDepth().

void QRhiViewport::setMaxDepth(float maxDepth)

Sets the maxDepth of the depth range of the viewport. By default this is set to 1.0f.

See also maxDepth().

void QRhiViewport::setMinDepth(float minDepth)

Sets the minDepth of the depth range of the viewport. By default this is set to 0.0f.

See also minDepth().

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

Sets the viewport's position and size to x, y, w, and h.

Note: Viewports are specified in a coordinate system that has its origin in the bottom-left.

See also viewport().

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

Returns the viewport x, y, width, and height.

See also setViewport().

Related Non-Members

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

Returns the hash value for v, using seed to seed the calculation.

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

Returns false if the values in the two QRhiViewport objects a and b are equal; otherwise returns true.

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

Returns true if the values in the two QRhiViewport objects a and b are equal.

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