renderer2d

    Comprehensive 2D rendering toolkit: batched-quad RenderFrame, atlas quad geometry, color helpers, debug overlay/profiler, color-matrix transforms.

    Download zip
    Author
    Version
    0.6.0
    License
    Apache-2.0
    Last updated
    15 days ago
    Downloads
    99

    mizchi/renderer2d does not have a README file

    AtlasQuad2D

    pub(all) struct AtlasQuad2D {
    source :
    AtlasDrawSource

    left : Double
    top : Double
    right : Double
    bottom : Double
    uniform_dwords : Array[Int]
    }

    AtlasQuad2D::new

    fn AtlasQuad2D::new(source~ :
    AtlasDrawSource
    , left~ : Double, top~ : Double, right~ : Double, bottom~ : Double, uniform_dwords? : Array[Int]) -> AtlasQuad2D

    ColorM

    pub struct ColorM {
    elements : FixedArray[Double]
    } derive(
    Debug
    )

    impl Show for ColorM

    ColorM::apply

    fn ColorM::apply(self : ColorM, r : Double, g : Double, b : Double, a : Double) -> (Double, Double, Double, Double)

    Apply color matrix to an RGBA color (all values 0.0-1.0).

    ColorM::apply_clamped

    fn ColorM::apply_clamped(self : ColorM, r : Double, g : Double, b : Double, a : Double) -> (Double, Double, Double, Double)

    Apply color matrix and clamp result to [0, 1].

    ColorM::apply_color

    fn ColorM::apply_color(self : ColorM, color :
    Color
    ) ->
    Color

    Apply color matrix to a gfx.Color.

    ColorM::change_hsv

    fn ColorM::change_hsv(self : ColorM, scale_hue : Double, scale_saturation : Double, scale_value : Double) -> ColorM

    Change HSV: scale_hue rotates hue (radians), scale_saturation and scale_value scale saturation and value.

    ColorM::concat

    fn ColorM::concat(self : ColorM, other : ColorM) -> ColorM

    Concatenate two color matrices (self * other).

    ColorM::identity

    fn ColorM::identity() -> ColorM

    ColorM::invert

    fn ColorM::invert(self : ColorM) -> ColorM

    Invert colors.

    ColorM::is_identity

    fn ColorM::is_identity(self : ColorM) -> Bool

    ColorM::monochrome

    fn ColorM::monochrome(self : ColorM) -> ColorM

    Convert to monochrome (grayscale) using NTSC luminance coefficients.

    ColorM::output

    fn ColorM::output(self : ColorM, logger : &Logger) -> Unit

    ColorM::rotate_hue

    fn ColorM::rotate_hue(self : ColorM, theta : Double) -> ColorM

    Rotate hue by angle in radians.

    ColorM::scale

    fn ColorM::scale(self : ColorM, r : Double, g : Double, b : Double, a : Double) -> ColorM

    Scale RGBA channels.

    ColorM::to_repr

    ColorM::to_string

    fn ColorM::to_string(self : ColorM) -> String

    ColorM::translate

    fn ColorM::translate(self : ColorM, r : Double, g : Double, b : Double, a : Double) -> ColorM

    Translate (offset) RGBA channels.

    DotText2D

    pub(all) struct DotText2D {
    chars : Array[Int]
    cx : Double
    cy : Double
    color :
    Color

    scale : Double
    }

    DotText2D::new

    fn DotText2D::new(chars~ : Array[Int], cx~ : Double, cy~ : Double, color~ :
    Color
    , scale? : Double) -> DotText2D

    FrameProfile

    pub(all) struct FrameProfile {
    fps : Double
    frame_time_ms : Double
    update_ms : Double
    draw_ms : Double
    gpu_frame_ms : Double
    draw_calls : Int
    vertex_count : Int
    asset_inflight : Int
    } derive(
    Debug
    )

    Frame profiler data. Collect timing in update/draw and pass to build_profiler_hud.

    FrameProfile::output

    fn FrameProfile::output(self : FrameProfile, logger : &Logger) -> Unit

    FrameProfile::to_string

    fn FrameProfile::to_string(self : FrameProfile) -> String

    Line2D

    pub(all) struct Line2D {
    x0 : Double
    y0 : Double
    x1 : Double
    y1 : Double
    width : Double
    color :
    Color

    }

    Line2D::new

    fn Line2D::new(x0~ : Double, y0~ : Double, x1~ : Double, y1~ : Double, width? : Double, color~ :
    Color
    ) -> Line2D

    Number2D

    pub(all) struct Number2D {
    number : Int
    cx : Double
    cy : Double
    color :
    Color

    scale : Double
    }

    Number2D::new

    fn Number2D::new(number~ : Int, cx~ : Double, cy~ : Double, color~ :
    Color
    , scale? : Double) -> Number2D

    RectFill2D

    pub(all) struct RectFill2D {
    x : Double
    y : Double
    w : Double
    h : Double
    color :
    Color

    }

    RectFill2D::new

    fn RectFill2D::new(x~ : Double, y~ : Double, w~ : Double, h~ : Double, color~ :
    Color
    ) -> RectFill2D

    RectOutline2D

    pub(all) struct RectOutline2D {
    x : Double
    y : Double
    w : Double
    h : Double
    line_width : Double
    color :
    Color

    }

    RectOutline2D::new

    fn RectOutline2D::new(x~ : Double, y~ : Double, w~ : Double, h~ : Double, line_width? : Double, color~ :
    Color
    ) -> RectOutline2D

    RenderFrame2D

    pub(all) struct RenderFrame2D {
    dst :
    ImageHandle

    shader :
    ShaderHandle

    screen_w : Int
    screen_h : Int
    pipeline_id : Int
    uniform_hash : Int
    blend :
    BlendMode

    }

    RenderFrame2D::dst_region

    RenderFrame2D::new

    fn RenderFrame2D::new(dst~ :
    ImageHandle
    , shader~ :
    ShaderHandle
    , screen_w~ : Int, screen_h~ : Int, pipeline_id? : Int, uniform_hash? : Int, blend? :
    BlendMode
    ) -> RenderFrame2D

    SVGRenderResult

    pub struct SVGRenderResult {
    width : Int
    height : Int
    pixels : Array[Int]
    } derive(
    Debug
    )

    Create an ImageSpec-compatible RGBA8 pixel array from an SVG. Useful for uploading SVG renders as textures.

    SVGRenderResult::output

    fn SVGRenderResult::output(self : SVGRenderResult, logger : &Logger) -> Unit

    SVGRenderResult::to_string

    fn SVGRenderResult::to_string(self : SVGRenderResult) -> String

    TrianglePayload

    pub struct TrianglePayload {
    has_payload : Bool
    ax : Double
    ay : Double
    bx : Double
    by : Double
    cx : Double
    cy : Double
    au : Double
    av : Double
    bu : Double
    bv : Double
    cu : Double
    cv : Double
    uniform_r : Double
    uniform_g : Double
    uniform_b : Double
    uniform_a : Double
    texture_seed : Int
    } derive(
    Debug
    )

    TrianglePayload::output

    fn TrianglePayload::output(self : TrianglePayload, logger : &Logger) -> Unit

    TrianglePayload::to_string

    fn TrianglePayload::to_string(self : TrianglePayload) -> String

    append_atlas_quad

    fn append_atlas_quad(commands : Array[
    DrawTrianglesCommand
    ], frame : RenderFrame2D, quad : AtlasQuad2D) -> Unit

    append_dot_text

    fn append_dot_text(commands : Array[
    DrawTrianglesCommand
    ], frame : RenderFrame2D, text : DotText2D) -> Unit

    append_line

    fn append_line(commands : Array[
    DrawTrianglesCommand
    ], frame : RenderFrame2D, line : Line2D) -> Unit

    append_number

    fn append_number(commands : Array[
    DrawTrianglesCommand
    ], frame : RenderFrame2D, number : Number2D) -> Unit

    append_primitive_batch

    fn append_primitive_batch(commands : Array[
    DrawTrianglesCommand
    ], frame : RenderFrame2D, vertex_data : Array[Double], indices : Array[Int], color :
    Color
    ) -> Unit

    append_rect_fill

    fn append_rect_fill(commands : Array[
    DrawTrianglesCommand
    ], frame : RenderFrame2D, rect : RectFill2D) -> Unit

    append_rect_fill_geometry

    fn append_rect_fill_geometry(vertices : Array[Double], indices : Array[Int], frame : RenderFrame2D, rect : RectFill2D) -> Unit

    append_rect_outline

    fn append_rect_outline(commands : Array[
    DrawTrianglesCommand
    ], frame : RenderFrame2D, rect : RectOutline2D) -> Unit

    atlas_quad_indices

    fn atlas_quad_indices() -> Array[Int]

    atlas_quad_vertex_data

    fn atlas_quad_vertex_data(source :
    AtlasDrawSource
    , left : Double, top : Double, right : Double, bottom : Double) -> Array[Double]

    build_input_debug_overlay

    Build a debug overlay showing current input state. Returns draw commands for:
    • Cursor crosshair at the current position
    • Small indicator squares for each pressed key
    • Indicator for pressed mouse buttons

    build_profiler_hud

    fn build_profiler_hud(cmds : Array[
    DrawTrianglesCommand
    ], dst :
    ImageHandle
    , shader :
    ShaderHandle
    , profile : FrameProfile, screen_w : Double, screen_h : Double) -> Unit

    Build a profiler HUD overlay in the top-right corner. Uses dot-matrix glyphs — no font dependency.

    clamp_unit

    fn clamp_unit(value : Double) -> Double

    color_black

    fn color_black() ->
    Color

    color_blue

    fn color_blue() ->
    Color

    color_from_hex

    fn color_from_hex(hex : Int) ->
    Color

    color_from_hex_alpha

    fn color_from_hex_alpha(hex : Int, alpha : Double) ->
    Color

    color_green

    fn color_green() ->
    Color

    color_red

    fn color_red() ->
    Color

    color_to_uniform_dwords

    fn color_to_uniform_dwords(color :
    Color
    ) -> Array[Int]

    color_transparent

    fn color_transparent() ->
    Color

    color_white

    fn color_white() ->
    Color

    color_yellow

    fn color_yellow() ->
    Color

    decode_triangle_payload

    fn decode_triangle_payload(vertex_data : Array[Double], indices : Array[Int], uniform_dwords : Array[Int], src_image_ids : Array[Int]) -> TrianglePayload

    default_frame_profile

    fn default_frame_profile() -> FrameProfile

    default_triangle_payload

    fn default_triangle_payload() -> TrianglePayload

    dot_text_size

    fn dot_text_size(char_count : Int, scale? : Double) -> (Double, Double)

    Rendered size of a dot-text run of char_count glyphs: (width, height).

    Exposed because the UI integrity gate compares a label's measured extent against its node rect to catch text that will spill or be clipped; that comparison is only sound if it uses the same arithmetic append_dot_text lays the glyphs out with, so both read it from here.

    draw_dot_text

    fn draw_dot_text(cmds : Array[
    DrawTrianglesCommand
    ], dst :
    ImageHandle
    , shader :
    ShaderHandle
    , chars : Array[Int], cx : Double, cy : Double, sw : Double, sh : Double, color :
    Color
    , scale : Double) -> Unit

    draw_number

    fn draw_number(cmds : Array[
    DrawTrianglesCommand
    ], dst :
    ImageHandle
    , shader :
    ShaderHandle
    , number : Int, ox : Double, oy : Double, sw : Double, sh : Double, color :
    Color
    , scale : Double) -> Unit

    glyph_pattern

    fn glyph_pattern(ch : Int) -> Array[Int]

    line_vertices

    fn line_vertices(x0 : Double, y0 : Double, x1 : Double, y1 : Double, width : Double) -> (Array[Double], Array[Int])

    Build vertex data for a line segment as a thin quad. Returns (vertex_data, indices) for a DrawTrianglesCommand.

    ndc_rect_fill_vertices

    fn ndc_rect_fill_vertices(px : Double, py : Double, pw : Double, ph : Double, screen_w : Double, screen_h : Double) -> (Array[Double], Array[Int])

    Build vertex data for a filled rectangle in NDC (pixel coords → clip space).

    new_atlas_quad_batch_draw_command

    fn new_atlas_quad_batch_draw_command(dst :
    ImageHandle
    , shader :
    ShaderHandle
    , dst_region :
    DstRegion
    , pipeline_id : Int, uniform_hash : Int, blend :
    BlendMode
    , source :
    AtlasDrawSource
    , rects : Array[Double], uniform_dwords : Array[Int]) ->
    DrawTrianglesCommand

    Build a single DrawTrianglesCommand covering N quads that share one atlas source, shader, dst region, pipeline, blend, and uniform state. rects is laid out as [l0, t0, r0, b0, l1, t1, r1, b1, ...] so the caller never allocates per-quad arrays. Quad count = rects.length() / 4; trailing partial elements are ignored. dst_region.index_count is overridden to 6*N so the GPU draws all quads in one call.

    new_atlas_quad_draw_command

    fn new_atlas_quad_draw_command(dst :
    ImageHandle
    , shader :
    ShaderHandle
    , dst_region :
    DstRegion
    , index_offset : Int, pipeline_id : Int, uniform_hash : Int, blend :
    BlendMode
    , source :
    AtlasDrawSource
    , left : Double, top : Double, right : Double, bottom : Double, uniform_dwords : Array[Int]) ->
    DrawTrianglesCommand

    new_line_command

    fn new_line_command(dst :
    ImageHandle
    , shader :
    ShaderHandle
    , x0 : Double, y0 : Double, x1 : Double, y1 : Double, width : Double, color :
    Color
    , pipeline_id : Int) ->
    DrawTrianglesCommand

    Build a draw command for a line segment.

    new_ndc_rect_fill_command

    fn new_ndc_rect_fill_command(dst :
    ImageHandle
    , shader :
    ShaderHandle
    , px : Double, py : Double, pw : Double, ph : Double, screen_w : Double, screen_h : Double, color :
    Color
    , pipeline_id : Int) ->
    DrawTrianglesCommand

    Build a draw command for a filled rectangle in NDC coordinates.

    new_rect_fill_command

    fn new_rect_fill_command(dst :
    ImageHandle
    , shader :
    ShaderHandle
    , x : Double, y : Double, w : Double, h : Double, color :
    Color
    , pipeline_id : Int) ->
    DrawTrianglesCommand

    Build a draw command for a filled rectangle using a solid color shader.

    new_simple_draw_command

    Build a simple draw command with common defaults.

    rect_fill_vertices

    fn rect_fill_vertices(x : Double, y : Double, w : Double, h : Double) -> (Array[Double], Array[Int])

    Build vertex data for a filled axis-aligned rectangle.

    rect_outline_vertices

    fn rect_outline_vertices(x : Double, y : Double, w : Double, h : Double, line_width : Double) -> (Array[Double], Array[Int])

    Build vertex data for an axis-aligned rectangle outline as four line quads.

    render_atlas_quads

    render_commands

    fn[T :
    GraphicsDriver
    ] render_commands(graphics : T, cmds : Array[
    DrawTrianglesCommand
    ], clear_color? :
    Color
    , clear_enabled? : Bool) -> Unit raise

    render_svg

    fn render_svg(svg_source : String, width : Int, height : Int) -> SVGRenderResult?

    render_svg_to_rgba

    fn render_svg_to_rgba(svg_source : String, width : Int, height : Int) -> (Int, Int, Array[Int])?

    Render an SVG string to RGBA pixel data. Returns (width, height, pixels) where pixels is a flat RGBA8 array.

    svg_path_to_fill_vertices

    fn svg_path_to_fill_vertices(path_data : String, tolerance : Double) -> (Array[Double], Array[Int])

    Parse an SVG path string and flatten to vertices for fill rendering.

    svg_path_to_stroke_vertices

    fn svg_path_to_stroke_vertices(path_data : String, width : Double, tolerance : Double) -> (Array[Double], Array[Int])

    Parse an SVG path string and flatten to vertices for stroke rendering.

    svg_path_to_vector_path

    fn svg_path_to_vector_path(path_data : String) ->
    Path

    Parse an SVG path data string (e.g. "M 0 0 L 10 10") into a vector Path.