Examples
// Minimal example of a WGPU/Winit application using Wume
// This example creates a window and renders a solid color to it.
use std::sync::Arc;
use wume::{wgpu, winit};
use winit::application::ApplicationHandler;
use winit::window::Window;
struct App {
context: wume::WgpuContext,
}
impl From<Arc<Window>> for App {
fn from(window: Arc<Window>) -> Self {
let context = wume::WgpuContext::new(window).unwrap();
Self { context }
}
}
impl ApplicationHandler for App {
fn resumed(&mut self, _event_loop: &winit::event_loop::ActiveEventLoop) {}
fn window_event(
&mut self,
event_loop: &winit::event_loop::ActiveEventLoop,
_window_id: winit::window::WindowId,
event: winit::event::WindowEvent,
) {
use winit::event::WindowEvent;
match event {
WindowEvent::CloseRequested => {
event_loop.exit();
}
WindowEvent::Resized(size) => {
self.context.resize(size.width, size.height);
}
WindowEvent::RedrawRequested => {
let frame = self.context.surface.get_current_texture().unwrap();
let view = frame
.texture
.create_view(&wgpu::TextureViewDescriptor::default());
let mut encoder =
self.context
.device
.create_command_encoder(&wgpu::CommandEncoderDescriptor {
label: Some("Render Encoder"),
});
{
let clear_color = wgpu::Color {
r: 0.5,
g: 0.2,
b: 0.2,
a: 1.0,
};
let _render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Clear Color Pass"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(clear_color),
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: None,
occlusion_query_set: None,
timestamp_writes: None,
});
}
self.context.queue.submit(Some(encoder.finish()));
frame.present();
}
_ => {}
}
}
}
fn main() {
let window_attributes = winit::window::WindowAttributes::default();
wume::lazy_run::<App>(Some(window_attributes)).unwrap()
}