|
ZenitUI
Retained-mode C++20 UI framework
|
Abstract 2D rendering backend. More...
#include <UIContext.hpp>
Public Member Functions | |
Low-Level Indexed Geometry | |
| virtual void | drawGeometry (std::span< const Vertex2D > vertices, std::span< const uint32_t > indices, TextureHandle tex={})=0 |
| Draw an indexed triangle list in logical screen coordinates. | |
Shape Primitives | |
| virtual void | fillRect (Rect r, Color c) |
| Fill an axis-aligned rectangle r with solid color c. | |
| virtual void | fillRoundedRect (Rect r, float radiusPx, Color c) |
| Fill a rectangle r with corner radius radiusPx (clamped to half the shorter side). | |
| virtual void | fillCircle (Vec2 center, float radius, Color c) |
| Fill a circle centered at center with the given logical radius. | |
| virtual void | strokeRect (Rect r, float thickness, Color c) |
| Stroke a rectangular border strictly inside r (CSS border-box). | |
| virtual void | strokeRoundedRect (Rect r, float radiusPx, float thickness, Color c) |
| Stroke a rounded border strictly inside r (CSS border-box). | |
| virtual void | fillBorder (Rect r, EdgeInsets sides, Color c) |
| Draw a rectangular ring with per-edge widths in a single indexed draw call. | |
Textures & Nine-Slice | |
| virtual void | drawTexture (TextureHandle t, Rect src, Rect dst, Color tint) |
| Draw sub-rectangle src (texture pixels) of texture t into logical rect dst, multiplied by tint. | |
| virtual void | drawNineSlice (TextureHandle t, NineSlice s, Rect dst, Color tint) |
| Draw texture t stretched into dst using the 9-slice insets s (fixed corners, stretched edges/center). | |
| virtual TextureHandle | createTexture (int, int, const uint8_t *=nullptr) |
Allocate a dynamic RGBA8 2D texture of w x h pixels. | |
| virtual void | updateTexture (TextureHandle, Rect, const uint8_t *) |
Upload tightly-packed RGBA8 pixels into sub-rectangle region of texture t. | |
| virtual void | destroyTexture (TextureHandle) |
| Release a dynamic texture previously created by createTexture. | |
State Stacks | |
| virtual void | pushTransform (const Transform2D &t)=0 |
| Push a 2D pivot-based transform onto the transform stack. | |
| virtual void | popTransform ()=0 |
| Pop the most recently pushed transform from the stack. | |
| virtual void | pushEffect (EffectHandle e)=0 |
| Bind shader effect e and push it onto the effect stack (used when Feature::Effects is supported). | |
| virtual void | popEffect ()=0 |
| Pop the active shader effect and restore the previous one (if any). | |
| virtual void | setBlendMode (BlendMode) |
| Switch the active color-blending mode. | |
| virtual void | pushClip (Rect r)=0 |
| Push a local-space clip rectangle r, intersecting it with the current clip. | |
| virtual void | popClip ()=0 |
| Pop the current clip rectangle and restore the previous scissor region. | |
| virtual Rect | getClipRect () const =0 |
| Return the active screen-space clip rectangle in logical pixels (used for culling). | |
Off-Screen Render Targets | |
| virtual TargetHandle | createTarget (int w, int h)=0 |
| Allocate an off-screen RGBA render target of w x h pixels (used when Feature::NestedTargets is supported). | |
| virtual void | destroyTarget (TargetHandle t)=0 |
| Release a render target previously allocated by createTarget. | |
| virtual void | pushTarget (TargetHandle t)=0 |
| Redirect subsequent draw calls to target t and clear it to transparent black. | |
| virtual void | popTarget ()=0 |
| Finish drawing into the active target and restore the previous target (or main framebuffer) and stacks. | |
| virtual void | drawTarget (TargetHandle t, Rect dst, Color tint)=0 |
| Composite the entire render target t into logical destination rect dst, multiplied by tint. | |
| virtual void | drawTarget (TargetHandle t, Rect, Rect dst, Color tint) |
| Composite sub-rectangle src (target pixels) of t into logical rect dst. | |
| virtual void | clearTarget (TargetHandle t, Color c)=0 |
| Clear render target t to solid color c. | |
| virtual bool | inTarget () const =0 |
| Return true while a pushTarget is active without a matching popTarget. | |
Shader Effects | |
| virtual EffectHandle | createEffect (std::string_view, std::string_view={}) |
| Compile and allocate a shader effect from GLSL/backend source strings. | |
| virtual void | destroyEffect (EffectHandle) |
| Release a shader effect previously created by createEffect. | |
Shader Uniforms | |
| virtual void | setEffectFloat (EffectHandle e, const char *name, float value)=0 |
| Set a float uniform named name on effect e. | |
| virtual void | setEffectVec2 (EffectHandle e, const char *name, Vec2 value)=0 |
| Set a vec2 uniform named name on effect e. | |
| virtual void | setEffectVec3 (EffectHandle e, const char *name, Vec3 value)=0 |
| Set a vec3 uniform named name on effect e. | |
| virtual void | setEffectVec4f (EffectHandle e, const char *name, Vec4 value)=0 |
| Set a vec4 uniform named name on effect e. | |
| virtual void | setEffectVec4 (EffectHandle e, const char *name, Color value)=0 |
| Set a normalized RGBA vec4 uniform (0..1 per channel) named name on effect e. | |
Capabilities & Frame Lifecycle | |
| virtual bool | supports (Feature f) const =0 |
| Query whether this backend implements an optional Feature. | |
| virtual ShaderLanguage | shaderLanguage () const |
| Return the shading language expected by IAssetProvider::loadEffect on this renderer. | |
| virtual void | beginFrame ()=0 |
| Called at the start of Layout::renderFrame before any draw calls (e.g. | |
| virtual void | endFrame ()=0 |
| Called at the end of Layout::renderFrame after all draw calls and portals have rendered. | |
| virtual void | setDpiScale (float scale)=0 |
| Notify the renderer of the active logical-to-physical DPI scale factor for the current frame. | |
Abstract 2D rendering backend.
All coordinates, rectangles, radii, and font sizes are expressed in logical pixels (post-DPI). Backends apply dpiScale internally when configuring the GPU transform or physical scissor rect.
See Writing a Custom Backend for the full porting guide and Backends, TextEngine, UTF-8 & Debugging for reference implementations (RaylibRenderer, MockRenderer).
|
pure virtual |
Called at the start of Layout::renderFrame before any draw calls (e.g.
to push a DPI scale matrix).
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
pure virtual |
Clear render target t to solid color c.
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
inlinevirtual |
Compile and allocate a shader effect from GLSL/backend source strings.
When vsSource is empty, backends supply their default 2D vertex shader.
Reimplemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
pure virtual |
Allocate an off-screen RGBA render target of w x h pixels (used when Feature::NestedTargets is supported).
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
inlinevirtual |
Allocate a dynamic RGBA8 2D texture of w x h pixels.
When rgbaPixels is nullptr, the texture is initialized to transparent black. Used by TextEngine to manage dynamic glyph atlas pages.
Reimplemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
inlinevirtual |
Release a shader effect previously created by createEffect.
Reimplemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
pure virtual |
Release a render target previously allocated by createTarget.
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
inlinevirtual |
Release a dynamic texture previously created by createTexture.
Reimplemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
pure virtual |
Draw an indexed triangle list in logical screen coordinates.
This is the single mandatory geometry primitive for backends. When tex.valid() is false, backends should sample a 1x1 opaque white texture so solid-colored vertices render unmodified.
Triangles are emitted counter-clockwise in NDC (Y-down screen space) by all Geometry2D builders.
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
inlinevirtual |
Draw texture t stretched into dst using the 9-slice insets s (fixed corners, stretched edges/center).
Reimplemented in ZenitUI::RaylibRenderer, and ZenitUI::Test::MockRenderer.
|
pure virtual |
Composite the entire render target t into logical destination rect dst, multiplied by tint.
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
inlinevirtual |
Composite sub-rectangle src (target pixels) of t into logical rect dst.
Used by TargetPool when supports(Feature::TargetSubRect) is true. Default falls back to full-target drawTarget(t, dst, tint).
Reimplemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
inlinevirtual |
Draw sub-rectangle src (texture pixels) of texture t into logical rect dst, multiplied by tint.
Reimplemented in ZenitUI::RaylibRenderer, and ZenitUI::Test::MockRenderer.
|
pure virtual |
Called at the end of Layout::renderFrame after all draw calls and portals have rendered.
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
Fill a circle centered at center with the given logical radius.
Reimplemented in ZenitUI::RaylibRenderer, and ZenitUI::Test::MockRenderer.
Fill an axis-aligned rectangle r with solid color c.
Reimplemented in ZenitUI::RaylibRenderer, and ZenitUI::Test::MockRenderer.
Fill a rectangle r with corner radius radiusPx (clamped to half the shorter side).
Reimplemented in ZenitUI::RaylibRenderer, and ZenitUI::Test::MockRenderer.
|
pure virtual |
Return the active screen-space clip rectangle in logical pixels (used for culling).
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
pure virtual |
Return true while a pushTarget is active without a matching popTarget.
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
pure virtual |
Pop the current clip rectangle and restore the previous scissor region.
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
pure virtual |
Pop the active shader effect and restore the previous one (if any).
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
pure virtual |
Finish drawing into the active target and restore the previous target (or main framebuffer) and stacks.
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
pure virtual |
Pop the most recently pushed transform from the stack.
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
pure virtual |
Push a local-space clip rectangle r, intersecting it with the current clip.
Implementations must transform r through the active transform stack before intersecting so scissoring matches rotated/scaled subtrees.
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
pure virtual |
Bind shader effect e and push it onto the effect stack (used when Feature::Effects is supported).
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
pure virtual |
Redirect subsequent draw calls to target t and clear it to transparent black.
Must save and reset the current clip and transform stacks so rendering inside t starts cleanly, then restore them on popTarget.
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
pure virtual |
Push a 2D pivot-based transform onto the transform stack.
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
inlinevirtual |
Switch the active color-blending mode.
Implementations must flush any pending geometry batch before changing GPU blend state. Backends that do not support Feature::Effects may keep the default no-op.
Reimplemented in ZenitUI::RaylibRenderer, and ZenitUI::SDL3Renderer.
|
pure virtual |
Notify the renderer of the active logical-to-physical DPI scale factor for the current frame.
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
pure virtual |
Set a float uniform named name on effect e.
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
pure virtual |
Set a vec2 uniform named name on effect e.
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
pure virtual |
Set a vec3 uniform named name on effect e.
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
pure virtual |
Set a normalized RGBA vec4 uniform (0..1 per channel) named name on effect e.
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
pure virtual |
Set a vec4 uniform named name on effect e.
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
inlinevirtual |
Return the shading language expected by IAssetProvider::loadEffect on this renderer.
Reimplemented in ZenitUI::RaylibRenderer, and ZenitUI::SDL3Renderer.
Stroke a rectangular border strictly inside r (CSS border-box).
Drawing inward keeps the border flush against fillRect(r, ...) without anti-aliasing seams or layout overflow.
Reimplemented in ZenitUI::RaylibRenderer, and ZenitUI::Test::MockRenderer.
|
inlinevirtual |
Stroke a rounded border strictly inside r (CSS border-box).
Outer radius is radiusPx; inner radius shrinks by thickness (clamped at 0) so the border stays flush against fillRoundedRect(r, ...).
Reimplemented in ZenitUI::Test::MockRenderer.
|
pure virtual |
Query whether this backend implements an optional Feature.
Implemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.
|
inlinevirtual |
Upload tightly-packed RGBA8 pixels into sub-rectangle region of texture t.
Implementations must flush any pending draw batch referencing t before mutating texels.
Reimplemented in ZenitUI::RaylibRenderer, ZenitUI::SDL3Renderer, and ZenitUI::Test::MockRenderer.