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
+17 -11
View File
@@ -14,6 +14,7 @@ use wgpu::{Adapter, Device, Instance, Queue, Surface};
use winit::window::Window;
use crate::error::WsgError;
use crate::frame::Frame;
/// Represents the GPU context. Holds all WGPU objects needed for rendering.
/// Created once at startup and shared across frames via Arc.
@@ -78,9 +79,8 @@ impl Context {
adapter: &wgpu::Adapter,
width: u32,
height: u32,
) -> Result<(), WsgError> {
) -> Result<wgpu::TextureFormat, WsgError> {
let caps = self.surface.get_capabilities(adapter);
// Prefer SRGB format for color accuracy; fall back to first available if none (technical point documented above).
let format = caps
.formats
.iter()
@@ -89,25 +89,25 @@ impl Context {
.or(caps.formats.first().copied())
.ok_or(WsgError::SurfaceIncompatible)?;
let alpha_mode = caps
.alpha_modes
.first()
.copied()
.ok_or(WsgError::SurfaceIncompatible)?;
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format,
width,
height,
present_mode: wgpu::PresentMode::Fifo, // V-Sync activated
alpha_mode, // first supported alpha mode
present_mode: wgpu::PresentMode::Fifo,
alpha_mode: caps
.alpha_modes
.first()
.copied()
.ok_or(WsgError::SurfaceIncompatible)?,
view_formats: vec![],
color_space: wgpu::SurfaceColorSpace::Srgb,
desired_maximum_frame_latency: 2,
};
self.surface.configure(&self.device, &config);
Ok(())
// On retourne le format choisi pour que le Renderer puisse le stocker
Ok(format)
}
/// Acquires the next surface texture for rendering this frame. Returns an error variant
@@ -134,4 +134,10 @@ impl Context {
// In wgpu 30, present() moved from SurfaceTexture::present() to Queue::present(frame).
self.queue.present(frame);
}
/// Returns a Frame wrapper around the current surface texture and its TextureView.
/// Called by the orchestrator at frame start; equivalent to Context::begin_frame() + Frame construction.
pub fn get_next_frame(&self) -> Frame {
Frame::new(&self.surface)
}
}