Skip to content

Viewport

Generated from engine/render/viewport.h at 862e08b. The text under each declaration is the header's own comment, word for word. About the reference says how these pages are made.

Browse the render module

#include "engine/render/viewport.h" · namespace labrador

struct Viewport

A rectangle of the back buffer, plus a depth range, in the shape every graphics API wants it. A render type and not a mattmath one, because mattmath depends on nothing and knows nothing about drawing.

minDepth and maxDepth are camelCase because they mirror D3D11_VIEWPORT's last two fields, which that header spells MinDepth and MaxDepth - so this is the API's name lowered to CONVENTIONS' initial letter rather than the API's name verbatim. The other four are not mirrored at all: this struct says x/y/width/height where D3D11_VIEWPORT says TopLeftX/TopLeftY/Width/ Height.

x · y · width · height · minDepth · maxDepth

Section titled “x · y · width · height · minDepth · maxDepth”
float x = 0.0f;
float y = 0.0f;
float width = 0.0f;
float height = 0.0f;
float minDepth = 0.0f;
float maxDepth = 1.0f;
Viewport(const Viewport&) = default;
Viewport(float x, float y, float width, float height,
float minDepth = 0.0f, float maxDepth = 1.0f);
Viewport(const mattmath::RectangleF& rectangle,
float minDepth = 0.0f, float maxDepth = 1.0f);
Viewport(const mattmath::RectangleI& rectangle,
float minDepth = 0.0f, float maxDepth = 1.0f);
mattmath::RectangleF rectangle() const;
mattmath::Vector2F position() const;
mattmath::Vector2F size() const;
mattmath::RectangleI pixel_rect() const;

The whole pixels this viewport covers, and THE ONLY CONVERSION TO THEM ANY BACKEND IS ALLOWED TO PERFORM.

EACH EDGE, THEN THE DIFFERENCE, which is the rule sprite_geometry.h's build_sprite_quad already states for a destination rectangle and this is the same question about a bigger one. Truncating the position and the size separately is the obvious alternative and it loses rows: two panes splitting a height of 721 come out 360 and 360 that way, leaving the last row of the back buffer covered by neither, where each-edge-then-the-difference gives 360 and 361 and covers all of it.

IT EXISTS BECAUSE A BACKEND CANNOT BE TRUSTED TO AGREE WITH ITSELF. GL 3.3 core has no float glViewport - glViewportIndexedf is 4.1 - so the GL backend has to make this conversion whatever the seam says. Making it inline and then dividing by the UN-truncated float when building the pixels-to-clip transform has the rasteriser and the projection disagree about how big the viewport is, scaling every sprite in a fractional pane by the ratio between them. One rectangle, computed once, feeds both.

Viewport& operator=(const mattmath::RectangleF& rectangle);
Viewport& operator=(const mattmath::RectangleI& rectangle);
bool operator==(const Viewport& other) const;
bool operator!=(const Viewport& other) const;

Named in the public declarations above: RectangleF, RectangleI, Vector2F.

The files that include this header directly. A file can also reach it through another header.

Development documentation (unreleased). Built from Labrador 862e08b of 2026-10-08.