Skip to main content

Crate cotis_wgpu

Crate cotis_wgpu 

Source
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

Use prelude for the common entry-point types:

use cotis_wgpu::prelude::*;

§Rendering model

CotisWgpuRenderer draws three kinds of command streams:

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:

§Features

FeatureEffect
complex-colorEnables 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_id is ignored; there is no font-loading API.
  • Images: cotis_defaults::render_commands::Image commands 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::CotisRendererAsync delegates synchronously to cotis::renders::CotisRenderer; there is no async GPU work.
  • Frame errors: Present failures log a warning and skip the frame; the application continues.

§Public modules

ModuleRole
preludeApplication entry-point re-exports
rendererCotisWgpuRenderer, WindowConfig, event loop
errorWgpuBackendError
drawabledrawable::WgpuDrawable extension trait
default_drawablesBuilt-in WgpuDrawable impls for cotis-defaults commands
cotis_traitsCotis context/interactivity trait impls
colorCotis Color → wgpu conversions
inputwinit input snapshot
pipelineAdvanced: UI geometry batch and WGSL pipeline
surfaceAdvanced: swapchain and depth buffer
textAdvanced: 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::WgpuDrawable implementations for standard cotis-defaults render 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
CotisWgpuRenderer and 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.