Table of Contents

Struct Framebuffer

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

Represents a framebuffer with RGBA32 color data and optional depth buffer.

public struct Framebuffer : IDisposable
Implements
Inherited Members

Remarks

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

Constructors

Framebuffer(int, int, bool)

Creates a new framebuffer with the specified dimensions.

public Framebuffer(int width, int height, bool withDepthBuffer = true)

Parameters

width int

Width in pixels. Must be greater than 0.

height int

Height in pixels. Must be greater than 0.

withDepthBuffer bool

Whether to allocate a depth buffer.

Exceptions

ArgumentOutOfRangeException

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

Framebuffer(int, int, uint*, float*)

Creates a framebuffer wrapping existing memory buffers.

public Framebuffer(int width, int height, uint* colorData, float* depthData = null)

Parameters

width int

Width in pixels.

height int

Height in pixels.

colorData uint*

Pointer to RGBA32 color data.

depthData float*

Optional pointer to depth buffer data.

Remarks

This constructor does not take ownership of the memory buffers. The caller is responsible for managing the lifetime of the buffers.

Properties

ColorData

Gets a pointer to the RGBA32 color data.

public readonly uint* ColorData { get; }

Property Value

uint*

Remarks

Color data is stored as packed RGBA with 8 bits per channel. Format: 0xRRGGBBAA

DepthData

Gets a pointer to the depth buffer data, or null if no depth buffer.

public readonly float* DepthData { get; }

Property Value

float*

Remarks

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.

HasDepthBuffer

Gets whether this framebuffer has a depth buffer.

public readonly bool HasDepthBuffer { get; }

Property Value

bool

Height

Gets the height of the framebuffer in pixels.

public readonly int Height { get; }

Property Value

int

Width

Gets the width of the framebuffer in pixels.

public readonly int Width { get; }

Property Value

int

Methods

ClearColor(uint)

Clears the color buffer to the specified color.

public readonly void ClearColor(uint color)

Parameters

color uint

RGBA32 color value (0xRRGGBBAA).

ClearDepth(float)

Clears the depth buffer to the specified depth value.

public readonly void ClearDepth(float depth = 1)

Parameters

depth float

Depth value in range [0.0, 1.0]. Default is 1.0 (far plane).

Exceptions

InvalidOperationException

Thrown when the framebuffer has no depth buffer.

Dispose()

Releases the framebuffer memory if owned by this instance.

public void Dispose()

GetColor(int, int)

Gets the color at the specified pixel coordinate.

public readonly uint GetColor(int x, int y)

Parameters

x int

X coordinate in pixels.

y int

Y coordinate in pixels.

Returns

uint

RGBA32 color value, or 0 if coordinates are out of bounds.

GetDepth(int, int)

Gets the depth at the specified pixel coordinate.

public readonly float GetDepth(int x, int y)

Parameters

x int

X coordinate in pixels.

y int

Y coordinate in pixels.

Returns

float

Depth value in range [0.0, 1.0], or 1.0 if coordinates are out of bounds or no depth buffer.

SetColor(int, int, uint)

Sets the color at the specified pixel coordinate.

public readonly void SetColor(int x, int y, uint color)

Parameters

x int

X coordinate in pixels.

y int

Y coordinate in pixels.

color uint

RGBA32 color value.

SetDepth(int, int, float)

Sets the depth at the specified pixel coordinate.

public readonly void SetDepth(int x, int y, float depth)

Parameters

x int

X coordinate in pixels.

y int

Y coordinate in pixels.

depth float

Depth value in range [0.0, 1.0].

ToByteArray()

Copies the color data to a managed byte array in RGBA format.

public readonly byte[] ToByteArray()

Returns

byte[]

Byte array containing RGBA color data.