Struct Framebuffer
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
widthintWidth in pixels. Must be greater than 0.
heightintHeight in pixels. Must be greater than 0.
withDepthBufferboolWhether 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
widthintWidth in pixels.
heightintHeight in pixels.
colorDatauint*Pointer to RGBA32 color data.
depthDatafloat*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
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
Height
Gets the height of the framebuffer in pixels.
public readonly int Height { get; }
Property Value
Width
Gets the width of the framebuffer in pixels.
public readonly int Width { get; }
Property Value
Methods
ClearColor(uint)
Clears the color buffer to the specified color.
public readonly void ClearColor(uint color)
Parameters
coloruintRGBA32 color value (0xRRGGBBAA).
ClearDepth(float)
Clears the depth buffer to the specified depth value.
public readonly void ClearDepth(float depth = 1)
Parameters
depthfloatDepth 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
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
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
SetDepth(int, int, float)
Sets the depth at the specified pixel coordinate.
public readonly void SetDepth(int x, int y, float depth)
Parameters
xintX coordinate in pixels.
yintY coordinate in pixels.
depthfloatDepth 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.