All rendering in Mirador is orchestrated by the WgpuRenderer
struct, which encapsulates the GPU device, surface, and all rendering pipelines. The rendering system is modular, with specialized sub-renderers for different aspects of the game, such as the main 3D maze, animated backgrounds, and loading or transition effects. As you can see below, the different renderers are nested within one another. Each subsequent renderer handles a more specific component of rendering the scenes in which they are needed.
Each frame, the rendering process follows this sequence:
game_renderer
or animation_renderer
is used.This architecture allows for clear separation between gameplay rendering and animated sequences, while sharing GPU resources efficiently.
The WgpuRenderer
struct is the central hub for all GPU-based rendering in Mirador. It manages the WGPU device and queue, the window surface, and contains the main rendering pipelines for both the game and animation sequences. It contains two sub-renderers: GameRenderer
which handles the 3D maze rendering, and AnimationRenderer
which handles the 2D maze rendering. They each contain their own set of sub-renderers for additional effects.
pub struct WgpuRenderer {
pub surface: wgpu::Surface<'static>,
pub surface_config: wgpu::SurfaceConfiguration,
pub device: wgpu::Device,
pub queue: wgpu::Queue,
pub game_renderer: GameRenderer,
pub animation_renderer: AnimationRenderer,
}
The GameRenderer
struct is responsible for rendering the core 3D maze, floor, and background effects during gameplay. It manages the main render pipeline, vertex and uniform buffers, and several sub-renderers for additional effects. The two sub renderers contained within, StarRenderer
and DebugRenderer
, handle the rendering of the stars in the background, and the rendering of the bounding boxes for debugging purposes respectively.
pub struct GameRenderer {
pub pipeline: wgpu::RenderPipeline,
pub vertex_buffer: wgpu::Buffer,
pub vertex_count: u32,
pub uniform_buffer: wgpu::Buffer,
pub uniform_bind_group: wgpu::BindGroup,
pub depth_texture: Option<wgpu::Texture>,
pub star_renderer: StarRenderer,
pub debug_renderer: DebugRenderer,
}
The AnimationRenderer
struct is dedicated to rendering animated sequences, such as the title screen maze, loading bars, and special exit effects. It combines maze generation logic with specialized sub-renderers for each visual element.
pub struct AnimationRenderer {
pub generator: MazeGenerator,
pub maze: Arc<Mutex<Maze>>,
pub maze_renderer: MazeRenderer,
pub loading_bar_renderer: LoadingBarRenderer,
pub exit_shader_renderer: ExitShaderRenderer,
pub texture: wgpu::Texture,
pub last_update: Instant,
}