refactor renderer responsable + docs + schema

This commit is contained in:
Jérôme Bousquié
2026-07-06 17:37:13 +02:00
parent 47851b8f61
commit 8e57dc783b
11 changed files with 256 additions and 136 deletions
+26 -40
View File
@@ -1,50 +1,40 @@
use std::sync::Arc;
use winit::event_loop::EventLoop;
use winit::window::WindowBuilder;
use wsg_lib::conf;
use wsg_lib::context::Context;
use wsg_lib::frame::Frame; // Import nécessaire
use wsg_lib::material::Material;
use wsg_lib::mesh::Mesh;
use wsg_lib::pipeline_cache::PipelineCache;
use wsg_lib::renderer::Renderer;
use wsg_lib::vertex::Vertex;
fn main() {
let event_loop = EventLoop::new().unwrap();
let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap());
// Initialisation contexte matériel (device, queue, surface) Utilisation de pollster pour le bloc async
let context = pollster::block_on(Context::new(window.clone()));
// 1. Initialisation
let context = pollster::block_on(Context::new(window.clone())).expect("Échec init GPU");
// Initialisation des briques de rendu
// Configuration de la surface et récupération du format
let format = context
.configure(&context.adapter, 800, 600)
.expect("Échec configuration");
// 2. Initialisation du Renderer (Il récupère tout ce dont il a besoin)
let mut cache = PipelineCache::new();
cache
.register_shader("basic", "assets/shaders/basic.wgsl")
.unwrap();
let renderer = Renderer::new(&context, &cache);
cache.register_shader("basic", conf::BASIC_SHADER).unwrap();
// Creation d'un material (charge le basic shader via le cache)
let material = Material::new(&context.device, context.config.format, "basic", &mut cache);
// Creation d'un mesh
// 1. Définition des sommets (avec position et couleur pour l'interpolation)
let vertices = [
Vertex {
position: [-0.5, 0.5, 0.0],
color: [1.0, 0.0, 0.0],
}, // Haut-Gauche (Rouge)
Vertex {
position: [0.5, 0.5, 0.0],
color: [0.0, 1.0, 0.0],
}, // Haut-Droite (Vert)
Vertex {
position: [0.5, -0.5, 0.0],
color: [0.0, 0.0, 1.0],
}, // Bas-Droite (Bleu)
Vertex {
position: [-0.5, -0.5, 0.0],
color: [1.0, 1.0, 1.0],
}, // Bas-Gauche (Blanc)
];
let renderer = Renderer::new(&context, format);
// 3. Material : On utilise renderer.device() et renderer.format()
let material = Material::new(renderer.device(), renderer.format(), "basic", &mut cache);
// Mesh : On utilise le device du renderer
let vertices = [ /* ... tes sommets ... */ ];
let indices: [u16; 6] = [0, 1, 2, 0, 2, 3];
let mesh = Mesh::new(&context.device, &vertices, Some(&indices));
let mesh = Mesh::new(renderer.device(), &vertices, Some(&indices));
// Render loop
event_loop
@@ -57,17 +47,13 @@ fn main() {
event: winit::event::WindowEvent::RedrawRequested,
..
} => {
// Acquisition de la cible de rendu
let frame = context.surface.get_current_texture().unwrap();
let view = frame
.texture
.create_view(&wgpu::TextureViewDescriptor::default());
if let Some(frame) = Frame::try_new(&context.surface) {
// 1. Rendu (plus d'arguments device/queue inutiles)
renderer.render(frame.view(), &mesh, &material);
// Orchestration du rendu
renderer.render(&context.device, &context.queue, &view, &mesh, &material);
// Presentation de l'image
frame.present();
// 2. Présentation
renderer.present(frame);
}
}
_ => (),
}