Xui.GPU.Software
Assembly: Xui.Runtime.Software · C# declarations · Assembly overview
Types
enum BlendModeclass ColorTargetenum CullModestruct Framebufferenum PrimitiveTopologyclass RenderContextclass SampledTexturestruct VertexSource<T>readonly struct Viewport
enum BlendMode
Defines blend modes for color blending operations.
public enum BlendMode
{
Alpha,
Add,
Multiply,
Screen,
Overlay,
Replace
}
BlendMode.Add
Add
Additive blending - colors are added together. result = src.rgb + dst.rgb
BlendMode.Alpha
Alpha
Standard alpha blending (source over destination). result = src.rgb * src.a + dst.rgb * (1 - src.a)
BlendMode.Multiply
Multiply
Multiplicative blending - colors are multiplied. result = src.rgb * dst.rgb
BlendMode.Overlay
Overlay
Overlay blending - combination of multiply and screen. Darkens dark colors, lightens light colors.
BlendMode.Replace
Replace
Replace mode - source completely replaces destination. result = src.rgb
BlendMode.Screen
Screen
Screen blending - inverted multiplicative. result = 1 - (1 - src.rgb) * (1 - dst.rgb)
class ColorTarget
Represents a color attachment target for rendering operations.
Provides conversion utilities between shader Color4 types and RGBA32 packed format.
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);
}
Color4 ColorTarget.Add(Color4 src, Color4 dst)
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]).
Color4 ColorTarget.Blend(Color4 src, Color4 dst)
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)
uint ColorTarget.BlendRgba32(uint src, uint dst)
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.
Color4 ColorTarget.BlendWith(Color4 src, Color4 dst, BlendMode mode)
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.
Color4 ColorTarget.FromRgba32(uint rgba32)
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].
Color4 ColorTarget.Multiply(Color4 src, Color4 dst)
public static Color4 Multiply(Color4 src, Color4 dst);
Multiplicative blending - multiplies source and destination colors.
src— Source color.dst— Destination color.
Returns: Multiplied color.
Color4 ColorTarget.Overlay(Color4 src, Color4 dst)
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.
Color4 ColorTarget.Screen(Color4 src, Color4 dst)
public static Color4 Screen(Color4 src, Color4 dst);
Screen blending - inverted multiplicative blending.
src— Source color.dst— Destination color.
Returns: Screen-blended color.
uint ColorTarget.ToRgba32(Color4 color)
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.
enum CullMode
Specifies which triangle faces to cull during software rasterization.
public enum CullMode
{
None = 0,
Back = 1,
Front = 2,
}
CullMode.Back
Back = 1
Back-facing triangles are culled (default).
CullMode.Front
Front = 2
Front-facing triangles are culled.
CullMode.None
None = 0
No culling — all triangles are rendered.
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).
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();
}
Framebuffer.Framebuffer(int width, int height, bool withDepthBuffer = true)
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.
Framebuffer.Framebuffer(int width, int height, uint* colorData, float* depthData = null)
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.
readonly void Framebuffer.ClearColor(uint color)
public readonly void ClearColor(uint color);
Clears the color buffer to the specified color.
color— RGBA32 color value (0xRRGGBBAA).
readonly void Framebuffer.ClearDepth(float depth = 1)
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.
readonly uint* Framebuffer.ColorData
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
readonly float* Framebuffer.DepthData
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.
void Framebuffer.Dispose()
public void Dispose();
Releases the framebuffer memory if owned by this instance.
readonly uint Framebuffer.GetColor(int x, int y)
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.
readonly float Framebuffer.GetDepth(int x, int y)
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.
readonly bool Framebuffer.HasDepthBuffer
public readonly bool HasDepthBuffer { get; }
Gets whether this framebuffer has a depth buffer.
readonly int Framebuffer.Height
public readonly int Height { get; }
Gets the height of the framebuffer in pixels.
readonly void Framebuffer.SetColor(int x, int y, uint color)
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.
readonly void Framebuffer.SetDepth(int x, int y, float depth)
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].
readonly byte[] Framebuffer.ToByteArray()
public readonly byte[] ToByteArray();
Copies the color data to a managed byte array in RGBA format.
Returns: Byte array containing RGBA color data.
readonly int Framebuffer.Width
public readonly int Width { get; }
Gets the width of the framebuffer in pixels.
enum PrimitiveTopology
Defines the primitive topology for vertex assembly.
public enum PrimitiveTopology
{
TriangleList = 0,
TriangleStrip = 1,
LineList = 2,
LineStrip = 3,
PointList = 4,
}
PrimitiveTopology.LineList
LineList = 2
Individual line segments. Each group of 2 vertices forms a line.
PrimitiveTopology.LineStrip
LineStrip = 3
Connected line segments where each vertex (after the first) forms a line with the preceding vertex.
PrimitiveTopology.PointList
PointList = 4
Individual points. Each vertex is rendered as a point.
PrimitiveTopology.TriangleList
TriangleList = 0
Vertices are assembled into triangles. Each group of 3 vertices forms a triangle.
PrimitiveTopology.TriangleStrip
TriangleStrip = 1
Vertices form a strip of triangles where each vertex (after the first two) forms a triangle with the two preceding vertices.
class RenderContext
Orchestrates the software rendering pipeline.
RenderContext manages the rendering state and executes vertex and fragment shaders to produce pixels in a framebuffer.
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;
}
RenderContext.RenderContext(Framebuffer framebuffer)
public RenderContext(Framebuffer framebuffer);
Creates a new render context with the specified framebuffer.
framebuffer— The framebuffer to render into.
bool RenderContext.BlendEnabled
public bool BlendEnabled { get; set; }
Gets or sets whether blending is enabled.
void RenderContext.ClearColor(Color4 color)
public void ClearColor(Color4 color);
Clears the framebuffer color to the specified value.
color— Color to clear to.
void RenderContext.ClearDepth(float depth = 1)
public void ClearDepth(float depth = 1.0f);
Clears the framebuffer depth to the specified value.
depth— Depth value to clear to (default 1.0).
CullMode RenderContext.CullMode
public CullMode CullMode { get; set; }
Gets or sets the triangle cull mode (default is Back).
bool RenderContext.DepthTestEnabled
public bool DepthTestEnabled { get; set; }
Gets or sets whether depth testing is enabled.
void RenderContext.Draw<TVertex, TVarying, TBindings>(VertexSource<TVertex> vertices, IVertexShader<TVertex, TVarying, TBindings> vertexShader, IFragmentShader<TVarying, FragmentOutput, TBindings> fragmentShader, TBindings bindings)
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.).
Framebuffer RenderContext.Framebuffer
public Framebuffer Framebuffer { get; }
Gets the framebuffer associated with this render context.
bool RenderContext.PremultipliedAlpha
public bool PremultipliedAlpha { get; set; }
Uses premultiplied source-over when blending is enabled.
PrimitiveTopology RenderContext.Topology
public PrimitiveTopology Topology { get; set; }
Gets or sets the primitive topology.
Viewport RenderContext.Viewport
public Viewport Viewport { get; set; }
Gets or sets the viewport for coordinate transformation.
class SampledTexture
Deterministic RGBA8 sampling with bilinear filtering and trilinear mip selection.
public sealed class SampledTexture : ISampledTexture<Color4>
{
public SampledTexture(int width, int height, IReadOnlyList<byte[]> mipLevels);
public Color4 Sample(Sampler sampler, Float2 uv, F32 level);
}
SampledTexture.SampledTexture(int width, int height, IReadOnlyList<byte[]> mipLevels)
public SampledTexture(int width, int height, IReadOnlyList<byte[]> mipLevels);
Copies validated premultiplied RGBA levels, largest first.
Color4 SampledTexture.Sample(Sampler sampler, Float2 uv, F32 level)
public Color4 Sample(Sampler sampler, Float2 uv, F32 level);
Samples normalized coordinates at an explicit mip level.
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.
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();
}
VertexSource<T>.VertexSource(T* data, int count)
public VertexSource(T* data, int count);
Creates a vertex source from a memory pointer.
data— Pointer to vertex data.count— Number of vertices.
readonly ReadOnlySpan<T> VertexSource<T>.AsSpan()
public readonly ReadOnlySpan<T> AsSpan();
Gets a read-only span over the vertex data.
Returns: A read-only span of vertices.
readonly int VertexSource<T>.Count
public readonly int Count { get; }
Gets the number of vertices in this source.
readonly T* VertexSource<T>.Data
public readonly T* Data { get; }
Gets a pointer to the vertex data.
VertexSource<T> VertexSource<T>.FromArray(T[] vertices)
[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:
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.
readonly T VertexSource<T>.this[int index]
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.
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].
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);
}
Viewport.Viewport(float x, float y, float width, float height, float minDepth = 0, float maxDepth = 1, bool yUp = false)
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.
Viewport Viewport.FromFramebuffer(Framebuffer framebuffer)
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.
float Viewport.Height
public readonly float Height;
Gets the height of the viewport in pixels.
float Viewport.MaxDepth
public readonly float MaxDepth;
Gets the maximum depth value (default 1.0).
float Viewport.MinDepth
public readonly float MinDepth;
Gets the minimum depth value (default 0.0).
void Viewport.Transform(float ndcX, float ndcY, float ndcZ, out float screenX, out float screenY, out float depth)
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)
float Viewport.Width
public readonly float Width;
Gets the width of the viewport in pixels.
float Viewport.X
public readonly float X;
Gets the X coordinate of the viewport's upper-left corner in pixels.
float Viewport.Y
public readonly float Y;
Gets the Y coordinate of the viewport's upper-left corner in pixels.
bool Viewport.YUp
public readonly bool YUp;
Maps positive NDC Y upward, matching Metal and Direct3D.