RMGui 0.15.0
C11 retained-mode UI library: layout kernel, style schema, widget painters, fonts, software framebuffer
Loading...
Searching...
No Matches
gpu_mesh.h File Reference

gpu_mesh.h — retained cel meshes in a host-owned sokol render pass. More...

#include "gpu_sokol.h"
#include "mesh_paint.h"
#include "mesh_large_paint.h"

Data Structures

struct  rmgui_gpu_mesh_raster_desc_t
 Capacity: largest output max_width x max_height pixels, max_supersample (1, 2 or 4), max_outline_width (0 to 4; 0 allocates no outline surfaces and refuses outlined styles) and an optional memory_limit in bytes (0 means none). More...
struct  rmgui_gpu_mesh_raster_caps_t
 Result of rmgui_gpu_mesh_raster_query. More...
struct  rmgui_gpu_mesh_raster_tile_t
 The last successfully prepared output: an RGBA8 image and texture view, its widthxheight, and v_up, always 0. More...

Typedefs

typedef struct rmgui_gpu_mesh rmgui_gpu_mesh_t
 One immutable model's GPU geometry, atlas and target-specific pipelines.
typedef struct rmgui_gpu_mesh_raster rmgui_gpu_mesh_raster_t
 Retained rasteriser that renders one large pose of a mesh into an RGBA8 texture matching rmgui_mesh_large_paint onto transparent black: encoded-space premultiplied color, y-down rows (v_up is 0, memory row 0 is the picture top), samples at (x+.5)/S, orthographic float projection, top-left coverage, the same depth rule, cel shading, supersample resolve and outline.

Enumerations

enum  {
  RMGUI_GPU_MESH_RASTER_NEEDS_BACKEND = 1 , RMGUI_GPU_MESH_RASTER_NEEDS_FLOAT_TARGET = 2 , RMGUI_GPU_MESH_RASTER_NEEDS_FLOAT_BLEND = 4 , RMGUI_GPU_MESH_RASTER_NEEDS_DEPTH_TARGET = 8 ,
  RMGUI_GPU_MESH_RASTER_NEEDS_SIZE = 16 , RMGUI_GPU_MESH_RASTER_NEEDS_MEMORY = 32
}

Functions

rmgui_gpu_result_t rmgui_gpu_mesh_create (rmgui_gpu_mesh_t **out, const rmgui_gpu_desc_t *desc, const rmgui_mesh_model_t *model)
 Upload vertices, indices and atlas once, outside a pass.
rmgui_gpu_result_t rmgui_gpu_mesh_large_create (rmgui_gpu_mesh_t **out, const rmgui_gpu_desc_t *desc, const rmgui_mesh_large_model_t *model)
 Upload a large model with uint32 indices and its declared base-level atlas filter/wrap modes.
void rmgui_gpu_mesh_destroy (rmgui_gpu_mesh_t *g)
 Release outside all passes, before sg_shutdown; NULL is safe.
void rmgui_gpu_mesh_begin (rmgui_gpu_mesh_t *g, const rmgui_gpu_frame_t *frame)
 Begin inside a host render pass with depth cleared to 1.
rmgui_gpu_result_t rmgui_gpu_mesh_draw (rmgui_gpu_mesh_t *g, const rmgui_mesh_instance_t *instance, rmgui_rect_t dst, rmgui_rect_t clip, const rmgui_mesh_camera_t *camera, const rmgui_mesh_style_t *style)
 Draw a pose of the borrowed model with CPU camera, cel, rim and radial-orb semantics.
rmgui_gpu_result_t rmgui_gpu_mesh_large_draw (rmgui_gpu_mesh_t *g, const rmgui_mesh_large_instance_t *instance, rmgui_rect_t dst, rmgui_rect_t clip, const rmgui_mesh_camera_t *camera, const rmgui_mesh_style_t *style)
 Draw a large pose using per-primitive UV offsets.
rmgui_gpu_result_t rmgui_gpu_mesh_raster_query (const rmgui_gpu_mesh_t *mesh, const rmgui_gpu_mesh_raster_desc_t *desc, rmgui_gpu_mesh_raster_caps_t *out)
 Report capability and cost of a descriptor for a mesh without creating anything.
rmgui_gpu_result_t rmgui_gpu_mesh_raster_create (rmgui_gpu_mesh_raster_t **out, rmgui_gpu_mesh_t *mesh, const rmgui_gpu_mesh_raster_desc_t *desc)
 Create the rasteriser outside a pass.
void rmgui_gpu_mesh_raster_destroy (rmgui_gpu_mesh_raster_t *r)
 Release every resource outside all passes and before sg_shutdown; NULL is safe.
rmgui_gpu_result_t rmgui_gpu_mesh_raster_prepare (rmgui_gpu_mesh_raster_t *r, const rmgui_mesh_large_instance_t *instance, int width, int height, rmgui_rect_t clip, const rmgui_mesh_camera_t *camera, const rmgui_mesh_style_t *style, int *rendered)
 Render a pose into the tile outside any pass.
rmgui_gpu_result_t rmgui_gpu_mesh_raster_tile (const rmgui_gpu_mesh_raster_t *r, rmgui_gpu_mesh_raster_tile_t *out)
 Return the last prepared tile; E_STATE before the first successful prepare.
void rmgui_gpu_mesh_end (rmgui_gpu_mesh_t *g)
 End without ending the host pass, restoring state or committing.

Detailed Description

gpu_mesh.h — retained cel meshes in a host-owned sokol render pass.

Typedef Documentation

◆ rmgui_gpu_mesh_t

typedef struct rmgui_gpu_mesh rmgui_gpu_mesh_t

One immutable model's GPU geometry, atlas and target-specific pipelines.

The model is borrowed and must remain live and immutable until destruction. Variable-sized CPU tables are allocated from the actual model counts at creation, not fixed library ceilings. Geometry indices/counts passed to sg draws must fit int; texture/destination dimensions follow the device limits. All operations run on the host sg thread; no sg implementation is supplied.

◆ rmgui_gpu_mesh_raster_t

typedef struct rmgui_gpu_mesh_raster rmgui_gpu_mesh_raster_t

Retained rasteriser that renders one large pose of a mesh into an RGBA8 texture matching rmgui_mesh_large_paint onto transparent black: encoded-space premultiplied color, y-down rows (v_up is 0, memory row 0 is the picture top), samples at (x+.5)/S, orthographic float projection, top-left coverage, the same depth rule, cel shading, supersample resolve and outline.

The rasteriser owns every GPU resource it needs, sized once from its descriptor: float color and depth targets, outline surfaces when max_outline_width > 0, a lookup table, one 96-byte-per-triangle vertex record buffer built at creation, the pipelines and the output tile. Nothing is allocated, created or uploaded per pose, and no per-frame vertex, atlas or tile upload happens: a pose is uniforms and draws only. Several rasterisers may share a mesh. It uses OpenGL core, OpenGL ES 3 and WebGL2 and reports other backends through rmgui_gpu_mesh_raster_query.

The scene pass does not use rasteriser interpolation: each triangle is drawn as its pixel bounding box and the shaders repeat the CPU's float projection, edge test with top-left rule, barycentric weights, depth, per-triangle depth slopes, normal and UV interpolation, cel/rim/orb shading and atlas sampling (sRGB decode and alpha from CPU-built tables) per sample. Resolve order, alpha rounding, sRGB quantisation, outline rules (nearest-seed order, 48 px interior threshold, size fade), orientation and clipping match the CPU as well. On llvmpipe through OpenGL core and ES 3 the result is byte-identical to the CPU in every measured case (see make check-gpu-mesh). Other implementations differ only by their float behaviour (fused multiply-add, reciprocal and square-root accuracy), which can flip an isolated sample that sits at a decision boundary within a few ulp; the consumer measures that on its own device. Opaque, double-sided and alpha-blended materials are supported; the CPU tint, global opacity and destination blending are not part of the result.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
RMGUI_GPU_MESH_RASTER_NEEDS_BACKEND 
RMGUI_GPU_MESH_RASTER_NEEDS_FLOAT_TARGET 
RMGUI_GPU_MESH_RASTER_NEEDS_FLOAT_BLEND 
RMGUI_GPU_MESH_RASTER_NEEDS_DEPTH_TARGET 
RMGUI_GPU_MESH_RASTER_NEEDS_SIZE 
RMGUI_GPU_MESH_RASTER_NEEDS_MEMORY 

Function Documentation

◆ rmgui_gpu_mesh_create()

rmgui_gpu_result_t rmgui_gpu_mesh_create ( rmgui_gpu_mesh_t ** out,
const rmgui_gpu_desc_t * desc,
const rmgui_mesh_model_t * model )

Upload vertices, indices and atlas once, outside a pass.

desc must match the host attachments, including a depth attachment and positive sample count. Returns E_ARGS for invalid model/desc, E_STATE for unavailable sg or an active pass, E_LIMIT for device/budget limits, E_BACKEND for resource failure. Failure preserves *out. No ownership of model or host resources transfers.

◆ rmgui_gpu_mesh_large_create()

rmgui_gpu_result_t rmgui_gpu_mesh_large_create ( rmgui_gpu_mesh_t ** out,
const rmgui_gpu_desc_t * desc,
const rmgui_mesh_large_model_t * model )

Upload a large model with uint32 indices and its declared base-level atlas filter/wrap modes.

RGB is sRGB-decoded before bilinear filtering. Same ownership, target, state and transactional output contract as mesh_create.

◆ rmgui_gpu_mesh_destroy()

void rmgui_gpu_mesh_destroy ( rmgui_gpu_mesh_t * g)

Release outside all passes, before sg_shutdown; NULL is safe.

◆ rmgui_gpu_mesh_begin()

void rmgui_gpu_mesh_begin ( rmgui_gpu_mesh_t * g,
const rmgui_gpu_frame_t * frame )

Begin inside a host render pass with depth cleared to 1.

Invalid state or dimensions leave the region inactive. The region clobbers pipeline, bindings, uniforms, viewport and scissor; the host must reapply its own state after end. Mesh depth is fitted to each pose; separate draws must use nonoverlapping destination rectangles or independently cleared depth.

◆ rmgui_gpu_mesh_draw()

rmgui_gpu_result_t rmgui_gpu_mesh_draw ( rmgui_gpu_mesh_t * g,
const rmgui_mesh_instance_t * instance,
rmgui_rect_t dst,
rmgui_rect_t clip,
const rmgui_mesh_camera_t * camera,
const rmgui_mesh_style_t * style )

Draw a pose of the borrowed model with CPU camera, cel, rim and radial-orb semantics.

No allocation or geometry/atlas upload. Complete finite, affine, nonsingular pose/camera/style preflight precedes any GPU state changes/draws; E_ARGS refuses invalid arguments, E_STATE an inactive/out-of-pass region, E_BACKEND invalid GPU resources, E_LIMIT excessive dimensions. UV edits must be constant translations per primitive (including badge digits); other UV edits are refused. Empty clip intersections are successful no-ops. Outline is an inverted hull expanded by outline_width device pixels in the projected vertex-normal direction, not the CPU screen-space silhouette and internal-edge algorithm. CPU supersample is validated but host sample_count controls GPU antialiasing. Lighting/atlas decoding is linear. SRGB8A8 targets keep layer blending linear; other color targets receive sRGB-encoded output and therefore blend in encoded space. Transparent target RGB follows hardware blending, not CPU straight-alpha framebuffer presentation. No clouds are drawn.

◆ rmgui_gpu_mesh_large_draw()

rmgui_gpu_result_t rmgui_gpu_mesh_large_draw ( rmgui_gpu_mesh_t * g,
const rmgui_mesh_large_instance_t * instance,
rmgui_rect_t dst,
rmgui_rect_t clip,
const rmgui_mesh_camera_t * camera,
const rmgui_mesh_style_t * style )

Draw a large pose using per-primitive UV offsets.

Same preflight, pixel and host-pass contract as mesh_draw; use the shared begin/end/destroy lifecycle. No allocation or geometry/atlas upload.

◆ rmgui_gpu_mesh_raster_query()

rmgui_gpu_result_t rmgui_gpu_mesh_raster_query ( const rmgui_gpu_mesh_t * mesh,
const rmgui_gpu_mesh_raster_desc_t * desc,
rmgui_gpu_mesh_raster_caps_t * out )

Report capability and cost of a descriptor for a mesh without creating anything.

E_ARGS for a non-large mesh or invalid descriptor, E_STATE without sg.

◆ rmgui_gpu_mesh_raster_create()

rmgui_gpu_result_t rmgui_gpu_mesh_raster_create ( rmgui_gpu_mesh_raster_t ** out,
rmgui_gpu_mesh_t * mesh,
const rmgui_gpu_mesh_raster_desc_t * desc )

Create the rasteriser outside a pass.

Failure preserves *out. E_ARGS invalid, E_STATE for sg unavailable or an active pass, E_LIMIT for size or memory (caps.missing SIZE or MEMORY), E_BACKEND for any other missing capability or resource failure.

◆ rmgui_gpu_mesh_raster_destroy()

void rmgui_gpu_mesh_raster_destroy ( rmgui_gpu_mesh_raster_t * r)

Release every resource outside all passes and before sg_shutdown; NULL is safe.

◆ rmgui_gpu_mesh_raster_prepare()

rmgui_gpu_result_t rmgui_gpu_mesh_raster_prepare ( rmgui_gpu_mesh_raster_t * r,
const rmgui_mesh_large_instance_t * instance,
int width,
int height,
rmgui_rect_t clip,
const rmgui_mesh_camera_t * camera,
const rmgui_mesh_style_t * style,
int * rendered )

Render a pose into the tile outside any pass.

The rasteriser runs its own passes, so the host must reapply its pipeline, bindings, uniforms, viewport and scissor afterwards. clip is in tile pixels; an empty clip yields a fully transparent tile. Validation and pose preflight complete before any GPU work, so every refusal (E_ARGS invalid pose, camera, style, size or outline above capacity; E_STATE inside a pass or without sg; E_BACKEND invalid resources) leaves the previous tile intact. An unchanged pose, camera, style, size and clip sets *rendered to 0 and does no work; otherwise *rendered is 1 and the pass sequence is bounded by two draws per opaque primitive per surface plus two full-screen passes.

◆ rmgui_gpu_mesh_raster_tile()

rmgui_gpu_result_t rmgui_gpu_mesh_raster_tile ( const rmgui_gpu_mesh_raster_t * r,
rmgui_gpu_mesh_raster_tile_t * out )

Return the last prepared tile; E_STATE before the first successful prepare.

◆ rmgui_gpu_mesh_end()

void rmgui_gpu_mesh_end ( rmgui_gpu_mesh_t * g)

End without ending the host pass, restoring state or committing.