From 724e6e4d97f608282e891742565b1036f3e970d5 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 26 Jan 2025 22:22:53 +0100 Subject: graphics config --- client/src/render/mod.rs | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'client/src/render/mod.rs') diff --git a/client/src/render/mod.rs b/client/src/render/mod.rs index db961f4..19f717a 100644 --- a/client/src/render/mod.rs +++ b/client/src/render/mod.rs @@ -57,13 +57,14 @@ pub struct Renderer<'a> { color_msaa: TextureView, config: GraphicsConfig, + pub config_update: Arc>, } #[derive(Debug, Clone)] pub struct GraphicsConfig { - max_anisotropy: u16, - max_mip_count: u32, - sample_count: u32, + pub max_anisotropy: u16, + pub max_mip_count: u32, + pub sample_count: u32, } impl<'a> Renderer<'a> { @@ -87,7 +88,8 @@ impl<'a> Renderer<'a> { let (device, queue) = adapter .request_device( &DeviceDescriptor { - required_features: Features::PUSH_CONSTANTS, + required_features: Features::PUSH_CONSTANTS + | Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES, required_limits: Limits { max_push_constant_size: 128, max_vertex_buffers: 16, @@ -188,23 +190,42 @@ impl<'a> Renderer<'a> { queue, surface_configuration, ui_renderer, + color_msaa, + config_update: Arc::new(Mutex::new((false, config.clone()))), config, surface_needs_reconfigure: false, timing: Default::default(), timing_submit: Default::default(), - color_msaa, }) } + pub fn reconfigure(&mut self, config: GraphicsConfig) { + info!("graphics configuration changed"); + self.scene_prepare.reconfigure(&config); + self.ui_renderer.reconfigure(&config); + self.config = config; + self.recreate_framebuffers(); + } + pub fn check_reconfigure(&mut self) { + let m = self.config_update.clone(); + let mut lock = m.lock().unwrap(); + if lock.0 { + self.reconfigure(lock.1.clone()); + lock.0 = false; + } + } + pub fn resize(&mut self, width: u32, height: u32) { self.surface_configuration.width = width; self.surface_configuration.height = height; self.surface .configure(&self.device, &self.surface_configuration); - + self.recreate_framebuffers(); + } + pub fn recreate_framebuffers(&mut self) { let size = Extent3d { - height, - width, + width: self.surface_configuration.width, + height: self.surface_configuration.height, depth_or_array_layers: 1, }; self.depth = self @@ -242,6 +263,8 @@ impl<'a> Renderer<'a> { camera: &Camera, input_state: &mut InputState, ) -> Result<()> { + self.check_reconfigure(); + self.timing.begin("prepare"); if self.surface_needs_reconfigure { self.surface -- cgit v1.2.3-70-g09d2