# Xui.GPU.Software

Assembly: **Xui.Runtime.Software** · [C# declarations](index.cs) · [Assembly overview](../index.md)

## Types

- [`enum BlendMode`](#api-c621d3681aa634a8)
- [`class ColorTarget`](#api-01a3a20bdc2f965f)
- [`enum CullMode`](#api-3e020a7c8bc2f40d)
- [`struct Framebuffer`](#api-e56f6bedc132544c)
- [`enum PrimitiveTopology`](#api-2b70e777c3561a82)
- [`class RenderContext`](#api-c96d3d152e487cab)
- [`class SampledTexture`](#api-ad9612394f01a20e)
- [`struct VertexSource<T>`](#api-853a50cf0b1aa91a)
- [`readonly struct Viewport`](#api-6d7c46961af5d96f)

<a id="api-c621d3681aa634a8"></a>

## `enum BlendMode`

Defines blend modes for color blending operations.

```csharp
public enum BlendMode
{
    Alpha,
    Add,
    Multiply,
    Screen,
    Overlay,
    Replace
}
```

<a id="api-49c85b7f4b90d303"></a>

### [`BlendMode.Add`](#api-49c85b7f4b90d303)


```csharp
Add
```

Additive blending - colors are added together. result = src.rgb + dst.rgb

<a id="api-6730ff612d783c97"></a>

### [`BlendMode.Alpha`](#api-6730ff612d783c97)


```csharp
Alpha
```

Standard alpha blending (source over destination). result = src.rgb * src.a + dst.rgb * (1 - src.a)

<a id="api-3eae6cb36b5343b1"></a>

### [`BlendMode.Multiply`](#api-3eae6cb36b5343b1)


```csharp
Multiply
```

Multiplicative blending - colors are multiplied. result = src.rgb * dst.rgb

<a id="api-07ef4170592f227e"></a>

### [`BlendMode.Overlay`](#api-07ef4170592f227e)


```csharp
Overlay
```

Overlay blending - combination of multiply and screen. Darkens dark colors, lightens light colors.

<a id="api-90397ca96dd5df4c"></a>

### [`BlendMode.Replace`](#api-90397ca96dd5df4c)


```csharp
Replace
```

Replace mode - source completely replaces destination. result = src.rgb

<a id="api-31a20b2efaf69450"></a>

### [`BlendMode.Screen`](#api-31a20b2efaf69450)


```csharp
Screen
```

Screen blending - inverted multiplicative. result = 1 - (1 - src.rgb) * (1 - dst.rgb)


<a id="api-01a3a20bdc2f965f"></a>

## `class ColorTarget`

Represents a color attachment target for rendering operations.

Provides conversion utilities between shader Color4 types and RGBA32 packed format.

```csharp
public static class ColorTarget
{
    public static uint ToRgba32(Color4 color);
    public static Color4 FromRgba32(uint rgba32);
    public static Color4 Blend(Color4 src, Color4 dst);
    public static uint BlendRgba32(uint src, uint dst);
    public static Color4 BlendWith(Color4 src, Color4 dst, BlendMode mode);
    public static Color4 Add(Color4 src, Color4 dst);
    public static Color4 Multiply(Color4 src, Color4 dst);
    public static Color4 Screen(Color4 src, Color4 dst);
    public static Color4 Overlay(Color4 src, Color4 dst);
}
```

<a id="api-d75210eea5747c8a"></a>

### [`Color4 ColorTarget.Add(Color4 src, Color4 dst)`](#api-d75210eea5747c8a)


```csharp
public static Color4 Add(Color4 src, Color4 dst);
```

Additive blending - adds source and destination colors.

- **`src`** — Source color.

- **`dst`** — Destination color.

**Returns:** Added color (clamped to [0, 1]).

<a id="api-fa16648161da5b79"></a>

### [`Color4 ColorTarget.Blend(Color4 src, Color4 dst)`](#api-fa16648161da5b79)


```csharp
public static Color4 Blend(Color4 src, Color4 dst);
```

Blends two colors using alpha blending (source over destination).

- **`src`** — Source color with premultiplied alpha.

- **`dst`** — Destination color.

**Returns:** Blended color.

Uses standard alpha blending formula: result = src.rgb * src.a + dst.rgb * (1 - src.a)

<a id="api-1e4e288c5e622478"></a>

### [`uint ColorTarget.BlendRgba32(uint src, uint dst)`](#api-1e4e288c5e622478)


```csharp
public static uint BlendRgba32(uint src, uint dst);
```

Blends a source color onto a destination using packed RGBA32 format.

- **`src`** — Source RGBA32 color.

- **`dst`** — Destination RGBA32 color.

**Returns:** Blended RGBA32 color.

<a id="api-1740a7b5a800933f"></a>

### [`Color4 ColorTarget.BlendWith(Color4 src, Color4 dst, BlendMode mode)`](#api-1740a7b5a800933f)


```csharp
public static Color4 BlendWith(Color4 src, Color4 dst, BlendMode mode);
```

Blends two colors using the specified blend mode.

- **`src`** — Source color.

- **`dst`** — Destination color.

- **`mode`** — The blend mode to use.

**Returns:** Blended color.

<a id="api-9a24cefb2843385f"></a>

### [`Color4 ColorTarget.FromRgba32(uint rgba32)`](#api-9a24cefb2843385f)


```csharp
public static Color4 FromRgba32(uint rgba32);
```

Converts packed RGBA32 format to a Color4 value.

- **`rgba32`** — Packed RGBA32 color value (0xRRGGBBAA).

**Returns:** Color4 value with components in range [0.0, 1.0].

<a id="api-82a296791792506b"></a>

### [`Color4 ColorTarget.Multiply(Color4 src, Color4 dst)`](#api-82a296791792506b)


```csharp
public static Color4 Multiply(Color4 src, Color4 dst);
```

Multiplicative blending - multiplies source and destination colors.

- **`src`** — Source color.

- **`dst`** — Destination color.

**Returns:** Multiplied color.

<a id="api-2694558854f6ddba"></a>

### [`Color4 ColorTarget.Overlay(Color4 src, Color4 dst)`](#api-2694558854f6ddba)


```csharp
public static Color4 Overlay(Color4 src, Color4 dst);
```

Overlay blending - combination of multiply and screen based on destination luminance.

- **`src`** — Source color.

- **`dst`** — Destination color.

**Returns:** Overlay-blended color.

<a id="api-7ee043c5579992f9"></a>

### [`Color4 ColorTarget.Screen(Color4 src, Color4 dst)`](#api-7ee043c5579992f9)


```csharp
public static Color4 Screen(Color4 src, Color4 dst);
```

Screen blending - inverted multiplicative blending.

- **`src`** — Source color.

- **`dst`** — Destination color.

**Returns:** Screen-blended color.

<a id="api-ad32afacae2312f8"></a>

### [`uint ColorTarget.ToRgba32(Color4 color)`](#api-ad32afacae2312f8)


```csharp
public static uint ToRgba32(Color4 color);
```

Converts a Color4 value to packed RGBA32 format (0xRRGGBBAA).

- **`color`** — Color4 value with components in range [0.0, 1.0].

**Returns:** Packed RGBA32 color value.

Color components are clamped to [0.0, 1.0] and converted to 8-bit values.


<a id="api-3e020a7c8bc2f40d"></a>

## `enum CullMode`

Specifies which triangle faces to cull during software rasterization.

```csharp
public enum CullMode
{
    None = 0,
    Back = 1,
    Front = 2,
}
```

<a id="api-c83206b01e2dfd16"></a>

### [`CullMode.Back`](#api-c83206b01e2dfd16)


```csharp
Back = 1
```

Back-facing triangles are culled (default).

<a id="api-482ac9d072229718"></a>

### [`CullMode.Front`](#api-482ac9d072229718)


```csharp
Front = 2
```

Front-facing triangles are culled.

<a id="api-7a876f0cf8014315"></a>

### [`CullMode.None`](#api-7a876f0cf8014315)


```csharp
None = 0
```

No culling — all triangles are rendered.


<a id="api-e56f6bedc132544c"></a>

## `struct Framebuffer`

Represents a framebuffer with RGBA32 color data and optional depth buffer.

The framebuffer stores pixel data in RGBA format with 8 bits per channel. Coordinates are in screen space with origin at top-left (0,0).

```csharp
public unsafe struct Framebuffer : IDisposable
{
    public readonly int Width { get; }
    public readonly int Height { get; }
    public readonly uint* ColorData { get; }
    public readonly float* DepthData { get; }
    public readonly bool HasDepthBuffer { get; }

    public Framebuffer(int width, int height, bool withDepthBuffer = true);
    public Framebuffer(int width, int height, uint* colorData, float* depthData = null);
    public readonly void ClearColor(uint color);
    public readonly void ClearDepth(float depth = 1.0f);
    public readonly void SetColor(int x, int y, uint color);
    public readonly uint GetColor(int x, int y);
    public readonly void SetDepth(int x, int y, float depth);
    public readonly float GetDepth(int x, int y);
    public readonly byte[] ToByteArray();
    public void Dispose();
}
```

<a id="api-ec77f24ded6f71cb"></a>

### [`Framebuffer.Framebuffer(int width, int height, bool withDepthBuffer = true)`](#api-ec77f24ded6f71cb)


```csharp
public Framebuffer(int width, int height, bool withDepthBuffer = true);
```

Creates a new framebuffer with the specified dimensions.

- **`width`** — Width in pixels. Must be greater than 0.

- **`height`** — Height in pixels. Must be greater than 0.

- **`withDepthBuffer`** — Whether to allocate a depth buffer.

**Throws** `
Thrown when width or height is less than or equal to 0.
`: Thrown when width or height is less than or equal to 0.

<a id="api-ff6fa613b2656c59"></a>

### [`Framebuffer.Framebuffer(int width, int height, uint* colorData, float* depthData = null)`](#api-ff6fa613b2656c59)


```csharp
public Framebuffer(int width, int height, uint* colorData, float* depthData = null);
```

Creates a framebuffer wrapping existing memory buffers.

- **`width`** — Width in pixels.

- **`height`** — Height in pixels.

- **`colorData`** — Pointer to RGBA32 color data.

- **`depthData`** — Optional pointer to depth buffer data.

This constructor does not take ownership of the memory buffers. The caller is responsible for managing the lifetime of the buffers.

<a id="api-4654a66d07d67849"></a>

### [`readonly void Framebuffer.ClearColor(uint color)`](#api-4654a66d07d67849)


```csharp
public readonly void ClearColor(uint color);
```

Clears the color buffer to the specified color.

- **`color`** — RGBA32 color value (0xRRGGBBAA).

<a id="api-5b9c37b33d42beb9"></a>

### [`readonly void Framebuffer.ClearDepth(float depth = 1)`](#api-5b9c37b33d42beb9)


```csharp
public readonly void ClearDepth(float depth = 1.0f);
```

Clears the depth buffer to the specified depth value.

- **`depth`** — Depth value in range [0.0, 1.0]. Default is 1.0 (far plane).

**Throws** `
Thrown when the framebuffer has no depth buffer.
`: Thrown when the framebuffer has no depth buffer.

<a id="api-245fe3a26ee9b6fb"></a>

### [`readonly uint* Framebuffer.ColorData`](#api-245fe3a26ee9b6fb)


```csharp
public readonly uint* ColorData { get; }
```

Gets a pointer to the RGBA32 color data.

Color data is stored as packed RGBA with 8 bits per channel. Format: 0xRRGGBBAA

<a id="api-cdba3082847adc93"></a>

### [`readonly float* Framebuffer.DepthData`](#api-cdba3082847adc93)


```csharp
public readonly float* DepthData { get; }
```

Gets a pointer to the depth buffer data, or null if no depth buffer.

Depth values are stored as normalized floats in range [0.0, 1.0]. 0.0 represents the near plane, 1.0 represents the far plane.

<a id="api-063176dffc87ab27"></a>

### [`void Framebuffer.Dispose()`](#api-063176dffc87ab27)


```csharp
public void Dispose();
```

Releases the framebuffer memory if owned by this instance.

<a id="api-052bc6d7c0ec4b19"></a>

### [`readonly uint Framebuffer.GetColor(int x, int y)`](#api-052bc6d7c0ec4b19)


```csharp
public readonly uint GetColor(int x, int y);
```

Gets the color at the specified pixel coordinate.

- **`x`** — X coordinate in pixels.

- **`y`** — Y coordinate in pixels.

**Returns:** RGBA32 color value, or 0 if coordinates are out of bounds.

<a id="api-a30d89a4e80e8a9a"></a>

### [`readonly float Framebuffer.GetDepth(int x, int y)`](#api-a30d89a4e80e8a9a)


```csharp
public readonly float GetDepth(int x, int y);
```

Gets the depth at the specified pixel coordinate.

- **`x`** — X coordinate in pixels.

- **`y`** — Y coordinate in pixels.

**Returns:** Depth value in range [0.0, 1.0], or 1.0 if coordinates are out of bounds or no depth buffer.

<a id="api-9edfdd1c4dda858e"></a>

### [`readonly bool Framebuffer.HasDepthBuffer`](#api-9edfdd1c4dda858e)


```csharp
public readonly bool HasDepthBuffer { get; }
```

Gets whether this framebuffer has a depth buffer.

<a id="api-b5825fbfdd215560"></a>

### [`readonly int Framebuffer.Height`](#api-b5825fbfdd215560)


```csharp
public readonly int Height { get; }
```

Gets the height of the framebuffer in pixels.

<a id="api-bebfccf86608b4d6"></a>

### [`readonly void Framebuffer.SetColor(int x, int y, uint color)`](#api-bebfccf86608b4d6)


```csharp
public readonly void SetColor(int x, int y, uint color);
```

Sets the color at the specified pixel coordinate.

- **`x`** — X coordinate in pixels.

- **`y`** — Y coordinate in pixels.

- **`color`** — RGBA32 color value.

<a id="api-86031944a7d3cfa5"></a>

### [`readonly void Framebuffer.SetDepth(int x, int y, float depth)`](#api-86031944a7d3cfa5)


```csharp
public readonly void SetDepth(int x, int y, float depth);
```

Sets the depth at the specified pixel coordinate.

- **`x`** — X coordinate in pixels.

- **`y`** — Y coordinate in pixels.

- **`depth`** — Depth value in range [0.0, 1.0].

<a id="api-4f6f98eadeb8276b"></a>

### [`readonly byte[] Framebuffer.ToByteArray()`](#api-4f6f98eadeb8276b)


```csharp
public readonly byte[] ToByteArray();
```

Copies the color data to a managed byte array in RGBA format.

**Returns:** Byte array containing RGBA color data.

<a id="api-be3e8cebb6bb413c"></a>

### [`readonly int Framebuffer.Width`](#api-be3e8cebb6bb413c)


```csharp
public readonly int Width { get; }
```

Gets the width of the framebuffer in pixels.


<a id="api-2b70e777c3561a82"></a>

## `enum PrimitiveTopology`

Defines the primitive topology for vertex assembly.

```csharp
public enum PrimitiveTopology
{
    TriangleList = 0,
    TriangleStrip = 1,
    LineList = 2,
    LineStrip = 3,
    PointList = 4,
}
```

<a id="api-01186890625af9e0"></a>

### [`PrimitiveTopology.LineList`](#api-01186890625af9e0)


```csharp
LineList = 2
```

Individual line segments. Each group of 2 vertices forms a line.

<a id="api-aab98df92a4b5808"></a>

### [`PrimitiveTopology.LineStrip`](#api-aab98df92a4b5808)


```csharp
LineStrip = 3
```

Connected line segments where each vertex (after the first) forms a line with the preceding vertex.

<a id="api-80f5024c0bfe2827"></a>

### [`PrimitiveTopology.PointList`](#api-80f5024c0bfe2827)


```csharp
PointList = 4
```

Individual points. Each vertex is rendered as a point.

<a id="api-fd44aea093cddbbe"></a>

### [`PrimitiveTopology.TriangleList`](#api-fd44aea093cddbbe)


```csharp
TriangleList = 0
```

Vertices are assembled into triangles. Each group of 3 vertices forms a triangle.

<a id="api-03f869978630466f"></a>

### [`PrimitiveTopology.TriangleStrip`](#api-03f869978630466f)


```csharp
TriangleStrip = 1
```

Vertices form a strip of triangles where each vertex (after the first two) forms a triangle with the two preceding vertices.


<a id="api-c96d3d152e487cab"></a>

## `class RenderContext`

Orchestrates the software rendering pipeline.

RenderContext manages the rendering state and executes vertex and fragment shaders to produce pixels in a framebuffer.

```csharp
public unsafe class RenderContext
{
    public bool PremultipliedAlpha { get; set; }
    public Framebuffer Framebuffer { get; }
    public Viewport Viewport { get; set; }
    public PrimitiveTopology Topology { get; set; }
    public bool DepthTestEnabled { get; set; }
    public bool BlendEnabled { get; set; }
    public CullMode CullMode { get; set; }

    public RenderContext(Framebuffer framebuffer);
    public void ClearColor(Color4 color);
    public void ClearDepth(float depth = 1.0f);
    public void Draw<TVertex, TVarying, TBindings>(VertexSource<TVertex> vertices, IVertexShader<TVertex, TVarying, TBindings> vertexShader, IFragmentShader<TVarying, FragmentOutput, TBindings> fragmentShader, TBindings bindings)
        where TVertex : unmanaged where TVarying : unmanaged where TBindings : struct;
}
```

<a id="api-9e9f59c32a1a0b75"></a>

### [`RenderContext.RenderContext(Framebuffer framebuffer)`](#api-9e9f59c32a1a0b75)


```csharp
public RenderContext(Framebuffer framebuffer);
```

Creates a new render context with the specified framebuffer.

- **`framebuffer`** — The framebuffer to render into.

<a id="api-ec52dda0c0a92e21"></a>

### [`bool RenderContext.BlendEnabled`](#api-ec52dda0c0a92e21)


```csharp
public bool BlendEnabled { get; set; }
```

Gets or sets whether blending is enabled.

<a id="api-d9127513c485773b"></a>

### [`void RenderContext.ClearColor(Color4 color)`](#api-d9127513c485773b)


```csharp
public void ClearColor(Color4 color);
```

Clears the framebuffer color to the specified value.

- **`color`** — Color to clear to.

<a id="api-1cd6850d9850e951"></a>

### [`void RenderContext.ClearDepth(float depth = 1)`](#api-1cd6850d9850e951)


```csharp
public void ClearDepth(float depth = 1.0f);
```

Clears the framebuffer depth to the specified value.

- **`depth`** — Depth value to clear to (default 1.0).

<a id="api-3c589ef8be7c700b"></a>

### [`CullMode RenderContext.CullMode`](#api-3c589ef8be7c700b)


```csharp
public CullMode CullMode { get; set; }
```

Gets or sets the triangle cull mode (default is Back).

<a id="api-9b012d253fe2d4f6"></a>

### [`bool RenderContext.DepthTestEnabled`](#api-9b012d253fe2d4f6)


```csharp
public bool DepthTestEnabled { get; set; }
```

Gets or sets whether depth testing is enabled.

<a id="api-468b1568a374c932"></a>

### [`void RenderContext.Draw<TVertex, TVarying, TBindings>(VertexSource<TVertex> vertices, IVertexShader<TVertex, TVarying, TBindings> vertexShader, IFragmentShader<TVarying, FragmentOutput, TBindings> fragmentShader, TBindings bindings)`](#api-468b1568a374c932)


```csharp
public void Draw<TVertex, TVarying, TBindings>(VertexSource<TVertex> vertices, IVertexShader<TVertex, TVarying, TBindings> vertexShader, IFragmentShader<TVarying, FragmentOutput, TBindings> fragmentShader, TBindings bindings)
    where TVertex : unmanaged where TVarying : unmanaged where TBindings : struct;
```

Renders vertices through the specified vertex and fragment shaders.

- **`TVertex`** — The vertex input type.

- **`TVarying`** — The varying data type (vertex output / fragment input).

- **`TBindings`** — The shader bindings type.

- **`vertices`** — Source of vertex data.

- **`vertexShader`** — Vertex shader implementation.

- **`fragmentShader`** — Fragment shader implementation.

- **`bindings`** — Shader bindings (uniforms, textures, etc.).

<a id="api-305a327e4e1dd7b1"></a>

### [`Framebuffer RenderContext.Framebuffer`](#api-305a327e4e1dd7b1)


```csharp
public Framebuffer Framebuffer { get; }
```

Gets the framebuffer associated with this render context.

<a id="api-491e325f3f0ae645"></a>

### [`bool RenderContext.PremultipliedAlpha`](#api-491e325f3f0ae645)


```csharp
public bool PremultipliedAlpha { get; set; }
```

Uses premultiplied source-over when blending is enabled.

<a id="api-05994626e575e0bd"></a>

### [`PrimitiveTopology RenderContext.Topology`](#api-05994626e575e0bd)


```csharp
public PrimitiveTopology Topology { get; set; }
```

Gets or sets the primitive topology.

<a id="api-b714639468004625"></a>

### [`Viewport RenderContext.Viewport`](#api-b714639468004625)


```csharp
public Viewport Viewport { get; set; }
```

Gets or sets the viewport for coordinate transformation.


<a id="api-ad9612394f01a20e"></a>

## `class SampledTexture`

Deterministic RGBA8 sampling with bilinear filtering and trilinear mip selection.

```csharp
public sealed class SampledTexture : ISampledTexture<Color4>
{
    public SampledTexture(int width, int height, IReadOnlyList<byte[]> mipLevels);
    public Color4 Sample(Sampler sampler, Float2 uv, F32 level);
}
```

<a id="api-ca14129d34bb5f85"></a>

### [`SampledTexture.SampledTexture(int width, int height, IReadOnlyList<byte[]> mipLevels)`](#api-ca14129d34bb5f85)


```csharp
public SampledTexture(int width, int height, IReadOnlyList<byte[]> mipLevels);
```

Copies validated premultiplied RGBA levels, largest first.

<a id="api-014c59a25510fb16"></a>

### [`Color4 SampledTexture.Sample(Sampler sampler, Float2 uv, F32 level)`](#api-014c59a25510fb16)


```csharp
public Color4 Sample(Sampler sampler, Float2 uv, F32 level);
```

Samples normalized coordinates at an explicit mip level.


<a id="api-853a50cf0b1aa91a"></a>

## `struct VertexSource<T>`

Represents a source of vertex data for rendering.

- **`T`** — The vertex structure type.

VertexSource provides a view over a contiguous array of vertex data. The vertex type T must be a value type with sequential layout.

```csharp
public unsafe struct VertexSource<T>
    where T : unmanaged
{
    public readonly int Count { get; }
    public readonly T* Data { get; }

    [Obsolete("Use constructor within a fixed block instead. This method creates dangling pointers.", error: true)]
    public static VertexSource<T> FromArray(T[] vertices);
    public VertexSource(T* data, int count);
    public readonly T this[int index] { get; }

    public readonly ReadOnlySpan<T> AsSpan();
}
```

<a id="api-d8458ececac8af13"></a>

### [`VertexSource<T>.VertexSource(T* data, int count)`](#api-d8458ececac8af13)


```csharp
public VertexSource(T* data, int count);
```

Creates a vertex source from a memory pointer.

- **`data`** — Pointer to vertex data.

- **`count`** — Number of vertices.

<a id="api-175d825760d26825"></a>

### [`readonly ReadOnlySpan<T> VertexSource<T>.AsSpan()`](#api-175d825760d26825)


```csharp
public readonly ReadOnlySpan<T> AsSpan();
```

Gets a read-only span over the vertex data.

**Returns:** A read-only span of vertices.

<a id="api-6a4743fbe3232f74"></a>

### [`readonly int VertexSource<T>.Count`](#api-6a4743fbe3232f74)


```csharp
public readonly int Count { get; }
```

Gets the number of vertices in this source.

<a id="api-36603a7527633a97"></a>

### [`readonly T* VertexSource<T>.Data`](#api-36603a7527633a97)


```csharp
public readonly T* Data { get; }
```

Gets a pointer to the vertex data.

<a id="api-c9eef7762bec7414"></a>

### [`VertexSource<T> VertexSource<T>.FromArray(T[] vertices)`](#api-c9eef7762bec7414)


```csharp
[Obsolete("Use constructor within a fixed block instead. This method creates dangling pointers.", error: true)]
public static VertexSource<T> FromArray(T[] vertices);
```

Creates a vertex source from a managed array.

- **`vertices`** — Array of vertex data.

**Returns:** A pinned vertex source.

IMPORTANT: This method is unsafe and should not be used in production code. The returned VertexSource contains a pointer to memory that will become invalid once the fixed block exits. The array can be moved by the garbage collector. Instead, use the constructor directly within a fixed block: 

```csharp
fixed (TVertex* ptr = vertices)
{
    var source = new VertexSource<TVertex>(ptr, vertices.Length);
    // Use source here
}
```

 This method is deprecated and will be removed in a future version.

<a id="api-1ea87b7204fa3cb8"></a>

### [`readonly T VertexSource<T>.this[int index]`](#api-1ea87b7204fa3cb8)


```csharp
public readonly T this[int index] { get; }
```

Gets the vertex at the specified index.

- **`index`** — Zero-based vertex index.

**Returns:** The vertex at the specified index.

**Throws** `
Thrown when index is out of bounds.
`: Thrown when index is out of bounds.


<a id="api-6d7c46961af5d96f"></a>

## `readonly struct Viewport`

Defines the viewport transformation from normalized device coordinates to screen space.

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].

```csharp
public readonly struct Viewport
{
    public readonly float X;
    public readonly float Y;
    public readonly float Width;
    public readonly float Height;
    public readonly float MinDepth;
    public readonly float MaxDepth;
    public readonly bool YUp;
    public Viewport(float x, float y, float width, float height, float minDepth = 0.0f, float maxDepth = 1.0f, bool yUp = false);
    public static Viewport FromFramebuffer(Framebuffer framebuffer);
    public readonly void Transform(float ndcX, float ndcY, float ndcZ, out float screenX, out float screenY, out float depth);
}
```

<a id="api-dbf11920ff3351ef"></a>

### [`Viewport.Viewport(float x, float y, float width, float height, float minDepth = 0, float maxDepth = 1, bool yUp = false)`](#api-dbf11920ff3351ef)


```csharp
public Viewport(float x, float y, float width, float height, float minDepth = 0.0f, float maxDepth = 1.0f, bool yUp = false);
```

Creates a new viewport.

- **`x`** — X coordinate of upper-left corner.

- **`y`** — Y coordinate of upper-left corner.

- **`width`** — Width in pixels. Must be greater than 0.

- **`height`** — Height in pixels. Must be greater than 0.

- **`minDepth`** — Minimum depth value (default 0.0).

- **`maxDepth`** — Maximum depth value (default 1.0).

- **`yUp`** — Use native GPU NDC orientation (+1 at the top).

**Throws** `
Thrown when width or height is less than or equal to 0.
`: Thrown when width or height is less than or equal to 0.

<a id="api-fa2365fe1905631a"></a>

### [`Viewport Viewport.FromFramebuffer(Framebuffer framebuffer)`](#api-fa2365fe1905631a)


```csharp
public static Viewport FromFramebuffer(Framebuffer framebuffer);
```

Creates a viewport that covers the entire framebuffer.

- **`framebuffer`** — The framebuffer to create a viewport for.

**Returns:** A viewport covering the entire framebuffer.

<a id="api-3096419b56ea5248"></a>

### [`float Viewport.Height`](#api-3096419b56ea5248)


```csharp
public readonly float Height;
```

Gets the height of the viewport in pixels.

<a id="api-562467fb171ba1ed"></a>

### [`float Viewport.MaxDepth`](#api-562467fb171ba1ed)


```csharp
public readonly float MaxDepth;
```

Gets the maximum depth value (default 1.0).

<a id="api-dec7a5b97dd63926"></a>

### [`float Viewport.MinDepth`](#api-dec7a5b97dd63926)


```csharp
public readonly float MinDepth;
```

Gets the minimum depth value (default 0.0).

<a id="api-062b9d07554d9b86"></a>

### [`void Viewport.Transform(float ndcX, float ndcY, float ndcZ, out float screenX, out float screenY, out float depth)`](#api-062b9d07554d9b86)


```csharp
public readonly void Transform(float ndcX, float ndcY, float ndcZ, out float screenX, out float screenY, out float depth);
```

Transforms a position from normalized device coordinates to screen space.

- **`ndcX`** — X coordinate in NDC space [-1, 1].

- **`ndcY`** — Y coordinate in NDC space [-1, 1].

- **`ndcZ`** — Z coordinate in NDC space [0, 1].

- **`screenX`** — Output X coordinate in screen space.

- **`screenY`** — Output Y coordinate in screen space.

- **`depth`** — Output depth value.

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)

<a id="api-f647f15e66879689"></a>

### [`float Viewport.Width`](#api-f647f15e66879689)


```csharp
public readonly float Width;
```

Gets the width of the viewport in pixels.

<a id="api-91b2c6a48dd279e0"></a>

### [`float Viewport.X`](#api-91b2c6a48dd279e0)


```csharp
public readonly float X;
```

Gets the X coordinate of the viewport&#39;s upper-left corner in pixels.

<a id="api-0e2a09935c78dc62"></a>

### [`float Viewport.Y`](#api-0e2a09935c78dc62)


```csharp
public readonly float Y;
```

Gets the Y coordinate of the viewport&#39;s upper-left corner in pixels.

<a id="api-c8ce84eae07e0cc3"></a>

### [`bool Viewport.YUp`](#api-c8ce84eae07e0cc3)


```csharp
public readonly bool YUp;
```

Maps positive NDC Y upward, matching Metal and Direct3D.

