render2d#
the core of the 2D renderer for CAD: a retained scene of lines, polylines, arcs and circles, curves, fills and hatches with layers and styles, dash patterns, blocks inserted many times, transparency, text from an atlas of multi-channel distance fields, strokes with analytic coverage, f64 coordinates relative to the camera, visibility on the GPU -- crate root lib/render2d/lib.rs
render2d -- the core of the 2D renderer for CAD on lib/gpu (G6a, G6b; docs/RENDER2D.md): a retained scene of
entities with stable ids (lines, polylines, arcs and circles; Bézier curves, ellipses and splines flattened per zoom
band on the CPU, curve.rs; fills of rings, triangulated on the CPU, fill.rs; blocks inserted many times, their records
once on the GPU and each insert an instance with its transform, G6b2), layers and styles (transparency per layer and
entity, by block); strokes as quads whose
coverage the fragment shader computes from the geometry (no MSAA), with exact butt, square and round caps and miter,
bevel and round joins, dash patterns in pixels or drawing units; fills with their edge's exact coverage, every pixel
blended once, and hatches from the camera's place in f64; f64 coordinates, a pair of f32 per axis on the GPU with the
camera subtracted first; visibility in compute shaders that keep the painter's order and write the indirect draws. Hosted
like render3d as the content of a ui.gpu_view (the app glues it with a GpuContent; lib/ui knows nothing of it). The
same WGSL on every path: compiled ahead (shaders_spv.rs) on Vulkan, handed to the browser as text on WebGPU.
Renderer::new(&device, &RendererDesc) -> Result<Renderer> the pipelines of one colour format
Scene::new(&renderer) -> Result<Scene>
scene.add_style(&Style) -> StyleId, set_style; add_layer(&Layer) -> LayerId, set_layer, remove_layer
scene.insert(layer, style, &Shape) -> EntityId, update(id, &Shape), set_entity_style(id, style), remove(id)
scene.add_block(&Block) -> BlockId, insert_in(block, style, &Shape); Shape::Insert(Insert) places a block on a
layer or in another block (moved by update, arrays as DXF's MINSERT)
scene.set_camera(&Camera) centre (f64), scale (units per pixel), rotation
dxf::load(&mut scene, &bytes, &dxf::Options) -> Loaded (G6e2) a DXF drawing into the scene (dxf.rs, dxftext.rs;
the reader is the crate jflib-dxf)
a frame:
scene.prepare(&mut renderer, (w, h))?; waits for this slot's last frame, uploads what changed
renderer.record(&mut encoder, &scene, color)?;
let id = queue.submit([encoder.finish()?])?; (or swapchain.present)
scene.submitted(id);
Draw order: layers by Layer::order (then by when they were added), within a layer the order of insertion (an update
keeps an entity's place); colours are sRGB codes with straight alpha, blended in code space as lib/gfx blends
(the target holds codes: a Unorm format such as ui's Bgra8Unorm, no sRGB format). The camera's y axis points up
on the screen. Errors are gpu's: Invalid for ids and values this crate can judge, the rest from the backend.