Skip to main content

Crate damascene_winit_wgpu

Crate damascene_winit_wgpu 

Source
Expand description

Optional desktop host for running Apps against a real wgpu surface in a winit window.

Most native apps should use this crate instead of calling damascene-wgpu directly:

use damascene_core::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let viewport = Rect::new(0.0, 0.0, 720.0, 480.0);
    damascene_winit_wgpu::run("My Damascene App", viewport, MyApp::default())
}

The host owns the event loop, window, device/queue, surface configuration, render pass boundaries, input mapping, IME forwarding, and animation redraw cadence. Your code owns the App: application state, App::build, App::on_event, optional hotkeys, custom shaders, and theme.

run takes an App and runs an event loop that:

  • Calls App::build on every redraw, applying current hover/press visuals automatically before paint.
  • Routes winit pointer events through the renderer’s hit-tester and dispatches events back via App::on_event.
  • Routes Tab/Shift-Tab through focus traversal and Enter/Space/Escape through keyboard events.
  • Copies the current Damascene text selection to the native clipboard on Ctrl/Cmd+C.
  • Requests a redraw whenever interaction state changes (mouse move, button down/up) so hover/press visuals are immediate.

Use run_with_config when an app has external live state. Put per-frame state refresh in App::before_build, then pick the redraw driver that matches the data (see the README’s meter-class vs event-class discussion): a fixed cadence via HostConfig::with_redraw_interval for continuously-changing meters, or push-driven wakes via HostConfig::with_external_wakeup for sparse events, so the idle app renders at 0 fps. For fully custom render-loop integration, bypass this crate and call damascene_wgpu::Runner directly.

§Environment variables

  • DAMASCENE_COLOR_DEBUG=1 — dump the color negotiation to stderr: the surface formats the WSI advertises, the compositor’s capabilities, the preferred-description targets (reference white, display peak, indicates_hdr), and the swapchain format the ladder settled on; re-dumped on every preferred_changed2 re-negotiation. The first stop for “why didn’t I get HDR?” — see docs/COLOR_MANAGEMENT.md. Apps query the same state at runtime via HostDiagnostics::hdr_active().

Modules§

host
Building blocks for writing a custom winit host.

Structs§

HostConfig
Configuration for the optional native winit + wgpu host.
Wakeup
Send + Clone handle that wakes the running host loop from any thread and schedules one redraw.
WakeupHook
External-wakeup hook stored in HostConfig. Wraps the closure so HostConfig can keep deriving Clone and Debug.

Traits§

WinitWgpuApp
Compatibility extension point for apps that use this host crate.

Functions§

run
Run a windowed app. Blocks until the user closes the window.
run_host_app
Run a windowed app with default host configuration.
run_host_app_on_event_loop
Run a host-specific WinitWgpuApp using a caller-created winit event loop.
run_host_app_with_config
Run a windowed app with host-specific configuration.
run_on_event_loop
Run a plain App using a caller-created winit event loop.
run_with_config
Run a windowed app with host-specific configuration.