diff options
author | metamuffin <metamuffin@disroot.org> | 2025-01-26 22:22:53 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-26 22:22:53 +0100 |
commit | 724e6e4d97f608282e891742565b1036f3e970d5 (patch) | |
tree | d75c43703c55ff35a8dd7f01960812f5b147d683 /client/src/render/mod.rs | |
parent | f0b213d51ee7b44362b5618bf5bd1eacf50d2bb8 (diff) | |
download | weareserver-724e6e4d97f608282e891742565b1036f3e970d5.tar weareserver-724e6e4d97f608282e891742565b1036f3e970d5.tar.bz2 weareserver-724e6e4d97f608282e891742565b1036f3e970d5.tar.zst |
graphics config
Diffstat (limited to 'client/src/render/mod.rs')
-rw-r--r-- | client/src/render/mod.rs | 39 |
1 files changed, 31 insertions, 8 deletions
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<Mutex<(bool, GraphicsConfig)>>, } #[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 |