Table of Contents

Struct Viewport

Namespace
Xui.GPU.Software
Assembly
Xui.Runtime.Software.dll

Defines the viewport transformation from normalized device coordinates to screen space.

public readonly struct Viewport
Inherited Members

Remarks

The viewport maps coordinates from NDC space [-1, 1] to screen space [x, x+width] and [y, y+height]. The depth range maps from NDC space [0, 1] to [minDepth, maxDepth].

Constructors

Viewport(float, float, float, float, float, float)

Creates a new viewport.

public Viewport(float x, float y, float width, float height, float minDepth = 0, float maxDepth = 1)

Parameters

x float

X coordinate of upper-left corner.

y float

Y coordinate of upper-left corner.

width float

Width in pixels. Must be greater than 0.

height float

Height in pixels. Must be greater than 0.

minDepth float

Minimum depth value (default 0.0).

maxDepth float

Maximum depth value (default 1.0).

Exceptions

ArgumentOutOfRangeException

Thrown when width or height is less than or equal to 0.

Fields

Height

Gets the height of the viewport in pixels.

public readonly float Height

Field Value

float

MaxDepth

Gets the maximum depth value (default 1.0).

public readonly float MaxDepth

Field Value

float

MinDepth

Gets the minimum depth value (default 0.0).

public readonly float MinDepth

Field Value

float

Width

Gets the width of the viewport in pixels.

public readonly float Width

Field Value

float

X

Gets the X coordinate of the viewport's upper-left corner in pixels.

public readonly float X

Field Value

float

Y

Gets the Y coordinate of the viewport's upper-left corner in pixels.

public readonly float Y

Field Value

float

Methods

FromFramebuffer(Framebuffer)

Creates a viewport that covers the entire framebuffer.

public static Viewport FromFramebuffer(Framebuffer framebuffer)

Parameters

framebuffer Framebuffer

The framebuffer to create a viewport for.

Returns

Viewport

A viewport covering the entire framebuffer.

Transform(float, float, float, out float, out float, out float)

Transforms a position from normalized device coordinates to screen space.

public void Transform(float ndcX, float ndcY, float ndcZ, out float screenX, out float screenY, out float depth)

Parameters

ndcX float

X coordinate in NDC space [-1, 1].

ndcY float

Y coordinate in NDC space [-1, 1].

ndcZ float

Z coordinate in NDC space [0, 1].

screenX float

Output X coordinate in screen space.

screenY float

Output Y coordinate in screen space.

depth float

Output depth value.

Remarks

NDC coordinates map as follows:

  • X: -1 (left) to +1 (right)
  • Y: -1 (top) to +1 (bottom) [Note: Y is inverted from standard GL convention]
  • Z: 0 (near) to 1 (far)