début renderer

This commit is contained in:
Jérôme Bousquié
2026-07-04 20:59:25 +02:00
parent 2a3c6493fc
commit d1b499570a
4 changed files with 36 additions and 11 deletions
+14 -2
View File
@@ -5,6 +5,9 @@
use crate::conf::BASIC_SHADER;
// On demande à Cargo de surveiller ce fichier (si le wsgl est modifié, mais pas la lib)
const _: &[u8] = include_bytes!("../assets/shaders/basic_shader.wgsl");
/// Renders geometry using a fixed RenderPipeline. This struct owns heavy objects
/// (RenderPipeline) compiled once at creation time, avoiding per-frame allocation.
pub struct Renderer {
@@ -19,10 +22,15 @@ impl Renderer {
/// by the orchestrator (main.rs). The pipeline is compiled only here; subsequent calls are cheap.
pub fn new(device: &wgpu::Device, format: wgpu::TextureFormat) -> Self {
// In wgpu 30, ShaderModuleDescriptor fields changed: label is Option<&str> (not Some(label)),
// and source uses Cow<'_, str> instead of [u8]. include_str! + .into() converts &str → Cow<str>.
// and source uses Cow<'_, str> instead of [u8].
// BASIC_SHADER serves as both the debug label and the file path loaded at runtime
// (include_str!() requires a string literal, not a variable).
// See assets/shaders/basic_shader.wgsl for the WGSL source — defines vs_main + fs_main stages.
let shader_source =
std::fs::read_to_string(BASIC_SHADER).expect("Failed to read shader file");
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some(BASIC_SHADER),
source: wgpu::ShaderSource::Wgsl(include_str!("../assets/shaders/basic_shader.wgsl").into()),
source: wgpu::ShaderSource::Wgsl(shader_source.into()),
});
// push_constant_ranges → removed in wgpu 30; replaced by immediate_size for var<immediate> support.
@@ -98,4 +106,8 @@ impl Renderer {
drop(render_pass);
queue.submit(std::iter::once(encoder.finish()));
}
// méthode utilitaire pour cacher le "bruit"
pub fn submit_commands(&self, queue: &wgpu::Queue, encoder: wgpu::CommandEncoder) {
queue.submit(std::iter::once(encoder.finish()));
}
}