Expand description
wgpu-backed desktop renderer for the Cotis UI ecosystem.
cotis-wgpu implements Cotis’s cotis::renders::CotisRenderer and
cotis::renders::CotisRendererAsync traits on top of wgpu 24,
winit 0.30, and glyphon 0.8.
It is a drop-in alternative to other Cotis render backends such as cotis-raylib.
§Quick start
For interactive applications, create a CotisWgpuRenderer and wire it into
CotisApp (from cotis::cotis_app) with a layout manager and pipe:
use cotis::cotis_app::{CotisApp, RenderApp};
use cotis_layout::preamble::CotisLayoutManager;
use cotis_pipes::cotis_layout_pipes::CotisLayoutToRenderListPipeForGenerics;
use cotis_utils::math::Dimensions;
use cotis_wgpu::prelude::*;
let renderer = CotisWgpuRenderer::auto_start();
let manager = CotisLayoutManager::new(Dimensions::new(1000.0, 800.0));
let mut app = CotisApp::new(renderer, manager, CotisLayoutToRenderListPipeForGenerics);
while !app.render().window_should_close() {
RenderApp::compute_frame(&mut app, |root| {
// build UI on root
});
}For the full wiring pattern including a StandardRenderCmds type alias, see
examples/basic_example/support.rs in this crate’s source tree.
Run the shipped example from the workspace root:
cargo run --example basic_example -p cotis-wgpu§Recommended imports
Use prelude for the common entry-point types:
use cotis_wgpu::prelude::*;§Rendering model
CotisWgpuRenderer draws three kinds of command streams:
cotis_defaults::render_commands::render_t_list::RenderTListwith a nested list type — typed heterogeneous command lists produced by layout pipes (primary path withcotis-pipes).cotis_defaults::render_commands::render_t_list::RenderTListwith()as the list tail — single-command lists.Box<dyn drawable::WgpuDrawable>— type-erased custom commands; implementdrawable::WgpuDrawablefor types not covered bycotis-defaultscommands.
Each cotis::renders::CotisRenderer::draw_frame call pumps the winit event loop before presenting.
CotisWgpuRenderer::window_should_close also pumps events, so the typical app loop calls
app.render() (which invokes draw_frame) and then checks window_should_close().
Built-in drawing for standard cotis-defaults commands lives in default_drawables.
Custom commands can use the advanced pipeline, surface, and text modules directly.
§Cotis trait implementations
CotisWgpuRenderer also implements Cotis context and interactivity traits.
See cotis_traits for the full list, including:
cotis_utils::traits::CotisWindowContext— physical window dimensions in pixels.cotis_utils::traits::CotisFrameContext— frame delta time.cotis_utils::traits::CotisRenderContext— render marker trait.cotis_utils::text::RendererTextMeasuringProvider— glyphon text measurement.cotis_utils::interactivity::mouse::MouseProviderand keyboard providers viainput.
§Features
| Feature | Effect |
|---|---|
complex-color | Enables cotis-defaults/complex_color and complex_colored_text. Accepts ColorLayer types but does not render gradients — see default_drawables. |
§Known limitations
- Fonts: All text uses glyphon
Family::SansSerif.TextConfig::font_idis ignored; there is no font-loading API. - Images:
cotis_defaults::render_commands::Imagecommands render as colored rectangles; texture loading is not implemented. - Geometry alpha: The UI shader outputs opaque fragments; cotis color alpha is ignored for rectangles and borders (text alpha is preserved via glyphon).
- Async renderer:
cotis::renders::CotisRendererAsyncdelegates synchronously tocotis::renders::CotisRenderer; there is no async GPU work. - Frame errors: Present failures log a warning and skip the frame; the application continues.
§Public modules
| Module | Role |
|---|---|
prelude | Application entry-point re-exports |
renderer | CotisWgpuRenderer, WindowConfig, event loop |
error | WgpuBackendError |
drawable | drawable::WgpuDrawable extension trait |
default_drawables | Built-in WgpuDrawable impls for cotis-defaults commands |
cotis_traits | Cotis context/interactivity trait impls |
color | Cotis Color → wgpu conversions |
input | winit input snapshot |
pipeline | Advanced: UI geometry batch and WGSL pipeline |
surface | Advanced: swapchain and depth buffer |
text | Advanced: glyphon text batching |
Re-exports§
pub use error::WgpuBackendError;pub use renderer::CotisWgpuRenderer;pub use renderer::WindowConfig;
Modules§
- color
- Color conversion between cotis and wgpu representations.
- cotis_
traits - Cotis context and interactivity trait implementations for
crate::renderer::CotisWgpuRenderer. - default_
drawables crate::drawable::WgpuDrawableimplementations for standardcotis-defaultsrender commands.- drawable
- Custom render command extension point for the wgpu backend.
- error
- Initialization and presentation errors for the wgpu backend.
- input
- Input state collected from winit and exposed through Cotis interactivity traits.
- pipeline
- Advanced extension API: UI geometry batch and WGSL render pipeline.
- prelude
- Convenient re-exports for application code.
- renderer
CotisWgpuRendererand window configuration for the wgpu backend.- surface
- Advanced extension API: swapchain surface and depth buffer.
- text
- Advanced extension API: glyphon text batching for a single frame.