//! Workflow déclaratif minimal, sans manipulation WGPU explicite dans ce fichier. //! `AppBuilder` crée l'event loop puis `App::run` ouvre la fenêtre, construit le `Context`/`Renderer` //! et fait tourner la boucle update → render → present. Depuis la migration winit 0.30, le GPU n'existe //! qu'après `resumed` : c'est pourquoi l'enregistrement shader + la création mesh/matériau/entité vivent //! dans le hook `AppHandler::setup`, appelé une fois le contexte prêt. La scène se rend automatiquement : //! la méthode `render()` par défaut appelle `app.render_scene(frame.view())`. use std::sync::Arc; use wsg_lib::AppHandler; use wsg_lib::app::AppBuilder; use wsg_lib::resources::{Material, Mesh, Vertex}; use wsg_lib::utils::WsgError; struct MonQuad; impl AppHandler for MonQuad { fn setup(&mut self, app: &mut wsg_lib::App) { let format = app.renderer().format(); // Enregistrement du shader, création du matériau et du mesh du quad (sans importer wgpu). app.cache() .register_shader("basic", wsg_lib::utils::BASIC_SHADER_PATH) .unwrap(); let vertices = [ Vertex { position: [-0.5, 0.5, 0.0], normal: [0.0, 0.0, 1.0], uv: [0.0, 0.0], color: [1.0, 0.0, 0.0, 1.0], }, // Haut-Gauche (Rouge) Vertex { position: [0.5, 0.5, 0.0], normal: [0.0, 0.0, 1.0], uv: [1.0, 0.0], color: [0.0, 1.0, 0.0, 1.0], }, // Haut-Droite (Vert) Vertex { position: [0.5, -0.5, 0.0], normal: [0.0, 0.0, 1.0], uv: [1.0, 1.0], color: [0.0, 0.0, 1.0, 1.0], }, // Bas-Droite (Bleu) Vertex { position: [-0.5, -0.5, 0.0], normal: [0.0, 0.0, 1.0], uv: [0.0, 1.0], color: [1.0, 1.0, 0.0, 1.0], }, // Bas-Gauche (Jaune) ]; let indices: [u16; 6] = [0, 1, 2, 0, 2, 3]; let mesh = Arc::new(Mesh::new( app.renderer().device(), &vertices, Some(&indices), )); let material = Arc::new(Material::new(format, "basic", app.cache())); app.scene.add_mesh("quad_mesh", mesh).unwrap(); app.scene.add_material("basic_material", material).unwrap(); app.scene .add_entity("quad", "quad_mesh", "basic_material") .unwrap(); } } #[pollster::main] async fn main() -> Result<(), WsgError> { let app = AppBuilder::new().title("WSG Simple").build().await?; app.run(MonQuad) }