// Generated API outline. Implementation bodies omitted. #nullable enable using G16 = ushort; using RGBA = uint; using System.ComponentModel; using System.Diagnostics; using nfloat = System.Runtime.InteropServices.NFloat; namespace Xui.GPU.Software { using System; using Xui.GPU.Shaders.Types; /// /// Defines blend modes for color blending operations. /// public enum BlendMode { /// /// Standard alpha blending (source over destination). /// result = src.rgb * src.a + dst.rgb * (1 - src.a) /// Alpha, /// /// Additive blending - colors are added together. /// result = src.rgb + dst.rgb /// Add, /// /// Multiplicative blending - colors are multiplied. /// result = src.rgb * dst.rgb /// Multiply, /// /// Screen blending - inverted multiplicative. /// result = 1 - (1 - src.rgb) * (1 - dst.rgb) /// Screen, /// /// Overlay blending - combination of multiply and screen. /// Darkens dark colors, lightens light colors. /// Overlay, /// /// Replace mode - source completely replaces destination. /// result = src.rgb /// Replace } /// /// Represents a color attachment target for rendering operations. /// /// /// Provides conversion utilities between shader Color4 types and RGBA32 packed format. /// public static class ColorTarget { /// /// Converts a Color4 value to packed RGBA32 format (0xRRGGBBAA). /// /// Color4 value with components in range [0.0, 1.0]. /// Packed RGBA32 color value. /// /// Color components are clamped to [0.0, 1.0] and converted to 8-bit values. /// public static uint ToRgba32(Color4 color); /// /// Converts packed RGBA32 format to a Color4 value. /// /// Packed RGBA32 color value (0xRRGGBBAA). /// Color4 value with components in range [0.0, 1.0]. public static Color4 FromRgba32(uint rgba32); /// /// Blends two colors using alpha blending (source over destination). /// /// Source color with premultiplied alpha. /// Destination color. /// Blended color. /// /// Uses standard alpha blending formula: /// result = src.rgb * src.a + dst.rgb * (1 - src.a) /// public static Color4 Blend(Color4 src, Color4 dst); /// /// Blends a source color onto a destination using packed RGBA32 format. /// /// Source RGBA32 color. /// Destination RGBA32 color. /// Blended RGBA32 color. public static uint BlendRgba32(uint src, uint dst); /// /// Blends two colors using the specified blend mode. /// /// Source color. /// Destination color. /// The blend mode to use. /// Blended color. public static Color4 BlendWith(Color4 src, Color4 dst, BlendMode mode); /// /// Additive blending - adds source and destination colors. /// /// Source color. /// Destination color. /// Added color (clamped to [0, 1]). public static Color4 Add(Color4 src, Color4 dst); /// /// Multiplicative blending - multiplies source and destination colors. /// /// Source color. /// Destination color. /// Multiplied color. public static Color4 Multiply(Color4 src, Color4 dst); /// /// Screen blending - inverted multiplicative blending. /// /// Source color. /// Destination color. /// Screen-blended color. public static Color4 Screen(Color4 src, Color4 dst); /// /// Overlay blending - combination of multiply and screen based on destination luminance. /// /// Source color. /// Destination color. /// Overlay-blended color. public static Color4 Overlay(Color4 src, Color4 dst); } } namespace Xui.GPU.Software { using System; using Xui.GPU.Shaders.Types; using Xui.GPU.Shaders; /// /// Specifies which triangle faces to cull during software rasterization. /// public enum CullMode { /// No culling — all triangles are rendered. None = 0, /// Back-facing triangles are culled (default). Back = 1, /// Front-facing triangles are culled. Front = 2, } /// /// 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 { /// Uses premultiplied source-over when blending is enabled. public bool PremultipliedAlpha { get; set; } /// /// Gets the framebuffer associated with this render context. /// public Framebuffer Framebuffer { get; } /// /// Gets or sets the viewport for coordinate transformation. /// public Viewport Viewport { get; set; } /// /// Gets or sets the primitive topology. /// public PrimitiveTopology Topology { get; set; } /// /// Gets or sets whether depth testing is enabled. /// public bool DepthTestEnabled { get; set; } /// /// Gets or sets whether blending is enabled. /// public bool BlendEnabled { get; set; } /// /// Gets or sets the triangle cull mode (default is Back). /// public CullMode CullMode { get; set; } /// /// Creates a new render context with the specified framebuffer. /// /// The framebuffer to render into. public RenderContext(Framebuffer framebuffer); /// /// Clears the framebuffer color to the specified value. /// /// Color to clear to. public void ClearColor(Color4 color); /// /// Clears the framebuffer depth to the specified value. /// /// Depth value to clear to (default 1.0). public void ClearDepth(float depth = 1.0f); /// /// Renders vertices through the specified vertex and fragment shaders. /// /// The vertex input type. /// The varying data type (vertex output / fragment input). /// The shader bindings type. /// Source of vertex data. /// Vertex shader implementation. /// Fragment shader implementation. /// Shader bindings (uniforms, textures, etc.). public void Draw(VertexSource vertices, IVertexShader vertexShader, IFragmentShader fragmentShader, TBindings bindings) where TVertex : unmanaged where TVarying : unmanaged where TBindings : struct; } } namespace Xui.GPU.Software { using System.Runtime.InteropServices; using System; /// /// 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 { /// /// Gets the width of the framebuffer in pixels. /// public readonly int Width { get; } /// /// Gets the height of the framebuffer in pixels. /// public readonly int Height { get; } /// /// Gets a pointer to the RGBA32 color data. /// /// /// Color data is stored as packed RGBA with 8 bits per channel. /// Format: 0xRRGGBBAA /// public readonly uint* ColorData { 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. /// public readonly float* DepthData { get; } /// /// Gets whether this framebuffer has a depth buffer. /// public readonly bool HasDepthBuffer { get; } /// /// Creates a new framebuffer with the specified dimensions. /// /// Width in pixels. Must be greater than 0. /// Height in pixels. Must be greater than 0. /// Whether to allocate a depth buffer. /// /// Thrown when width or height is less than or equal to 0. /// public Framebuffer(int width, int height, bool withDepthBuffer = true); /// /// Creates a framebuffer wrapping existing memory buffers. /// /// Width in pixels. /// Height in pixels. /// Pointer to RGBA32 color data. /// 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. /// public Framebuffer(int width, int height, uint* colorData, float* depthData = null); /// /// Clears the color buffer to the specified color. /// /// RGBA32 color value (0xRRGGBBAA). public readonly void ClearColor(uint color); /// /// Clears the depth buffer to the specified depth value. /// /// Depth value in range [0.0, 1.0]. Default is 1.0 (far plane). /// /// Thrown when the framebuffer has no depth buffer. /// public readonly void ClearDepth(float depth = 1.0f); /// /// Sets the color at the specified pixel coordinate. /// /// X coordinate in pixels. /// Y coordinate in pixels. /// RGBA32 color value. public readonly void SetColor(int x, int y, uint color); /// /// Gets the color at the specified pixel coordinate. /// /// X coordinate in pixels. /// Y coordinate in pixels. /// RGBA32 color value, or 0 if coordinates are out of bounds. public readonly uint GetColor(int x, int y); /// /// Sets the depth at the specified pixel coordinate. /// /// X coordinate in pixels. /// Y coordinate in pixels. /// Depth value in range [0.0, 1.0]. public readonly void SetDepth(int x, int y, float depth); /// /// Gets the depth at the specified pixel coordinate. /// /// X coordinate in pixels. /// Y coordinate in pixels. /// Depth value in range [0.0, 1.0], or 1.0 if coordinates are out of bounds or no depth buffer. public readonly float GetDepth(int x, int y); /// /// Copies the color data to a managed byte array in RGBA format. /// /// Byte array containing RGBA color data. public readonly byte[] ToByteArray(); /// /// Releases the framebuffer memory if owned by this instance. /// public void Dispose(); } /// /// Represents a source of vertex data for rendering. /// /// 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 where T : unmanaged { /// /// Gets the number of vertices in this source. /// public readonly int Count { get; } /// /// Gets a pointer to the vertex data. /// public readonly T* Data { get; } /// /// Creates a vertex source from a managed array. /// /// Array of vertex data. /// 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. /// [Obsolete("Use constructor within a fixed block instead. This method creates dangling pointers.", error: true)] public static VertexSource FromArray(T[] vertices); /// /// Creates a vertex source from a memory pointer. /// /// Pointer to vertex data. /// Number of vertices. public VertexSource(T* data, int count); /// /// Gets the vertex at the specified index. /// /// Zero-based vertex index. /// The vertex at the specified index. /// /// Thrown when index is out of bounds. /// public readonly T this[int index] { get; } /// /// Gets a read-only span over the vertex data. /// /// A read-only span of vertices. public readonly ReadOnlySpan AsSpan(); } } namespace Xui.GPU.Software { /// /// Defines the primitive topology for vertex assembly. /// public enum PrimitiveTopology { /// /// Vertices are assembled into triangles. /// Each group of 3 vertices forms a triangle. /// TriangleList = 0, /// /// Vertices form a strip of triangles where each vertex (after the first two) /// forms a triangle with the two preceding vertices. /// TriangleStrip = 1, /// /// Individual line segments. Each group of 2 vertices forms a line. /// LineList = 2, /// /// Connected line segments where each vertex (after the first) /// forms a line with the preceding vertex. /// LineStrip = 3, /// /// Individual points. Each vertex is rendered as a point. /// PointList = 4, } } namespace Xui.GPU.Software { using System.Collections.Generic; using System.Linq; using System; using Xui.GPU.Hardware; using Xui.GPU.Shaders.Types; /// Deterministic RGBA8 sampling with bilinear filtering and trilinear mip selection. public sealed class SampledTexture : ISampledTexture { /// Copies validated premultiplied RGBA levels, largest first. public SampledTexture(int width, int height, IReadOnlyList mipLevels); /// Samples normalized coordinates at an explicit mip level. public Color4 Sample(Sampler sampler, Float2 uv, F32 level); } } namespace Xui.GPU.Software { using System; /// /// 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 { /// /// Gets the X coordinate of the viewport's upper-left corner in pixels. /// public readonly float X; /// /// Gets the Y coordinate of the viewport's upper-left corner in pixels. /// public readonly float Y; /// /// Gets the width of the viewport in pixels. /// public readonly float Width; /// /// Gets the height of the viewport in pixels. /// public readonly float Height; /// /// Gets the minimum depth value (default 0.0). /// public readonly float MinDepth; /// /// Gets the maximum depth value (default 1.0). /// public readonly float MaxDepth; /// Maps positive NDC Y upward, matching Metal and Direct3D. public readonly bool YUp; /// /// Creates a new viewport. /// /// X coordinate of upper-left corner. /// Y coordinate of upper-left corner. /// Width in pixels. Must be greater than 0. /// Height in pixels. Must be greater than 0. /// Minimum depth value (default 0.0). /// Maximum depth value (default 1.0). /// Use native GPU NDC orientation (+1 at the top). /// /// Thrown when width or height is less than or equal to 0. /// public Viewport(float x, float y, float width, float height, float minDepth = 0.0f, float maxDepth = 1.0f, bool yUp = false); /// /// Creates a viewport that covers the entire framebuffer. /// /// The framebuffer to create a viewport for. /// A viewport covering the entire framebuffer. public static Viewport FromFramebuffer(Framebuffer framebuffer); /// /// Transforms a position from normalized device coordinates to screen space. /// /// X coordinate in NDC space [-1, 1]. /// Y coordinate in NDC space [-1, 1]. /// Z coordinate in NDC space [0, 1]. /// Output X coordinate in screen space. /// Output Y coordinate in screen space. /// 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) /// public readonly void Transform(float ndcX, float ndcY, float ndcZ, out float screenX, out float screenY, out float depth); } }