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/ui.rs | |
parent | f0b213d51ee7b44362b5618bf5bd1eacf50d2bb8 (diff) | |
download | weareserver-724e6e4d97f608282e891742565b1036f3e970d5.tar weareserver-724e6e4d97f608282e891742565b1036f3e970d5.tar.bz2 weareserver-724e6e4d97f608282e891742565b1036f3e970d5.tar.zst |
graphics config
Diffstat (limited to 'client/src/render/ui.rs')
-rw-r--r-- | client/src/render/ui.rs | 66 |
1 files changed, 46 insertions, 20 deletions
diff --git a/client/src/render/ui.rs b/client/src/render/ui.rs index e27b9cb..4de2633 100644 --- a/client/src/render/ui.rs +++ b/client/src/render/ui.rs @@ -34,8 +34,8 @@ use wgpu::{ Buffer, BufferDescriptor, BufferUsages, ColorTargetState, ColorWrites, CommandEncoder, CompareFunction, DepthStencilState, Device, Extent3d, FilterMode, FragmentState, FrontFace, ImageCopyTexture, ImageDataLayout, IndexFormat, LoadOp, MultisampleState, Operations, Origin3d, - PipelineCompilationOptions, PipelineLayoutDescriptor, PolygonMode, PrimitiveState, - PrimitiveTopology, PushConstantRange, Queue, RenderPassColorAttachment, + PipelineCompilationOptions, PipelineLayout, PipelineLayoutDescriptor, PolygonMode, + PrimitiveState, PrimitiveTopology, PushConstantRange, Queue, RenderPassColorAttachment, RenderPassDepthStencilAttachment, RenderPassDescriptor, RenderPipeline, RenderPipelineDescriptor, SamplerBindingType, SamplerDescriptor, ShaderStages, StoreOp, SurfaceConfiguration, Texture, TextureAspect, TextureDescriptor, TextureDimension, @@ -51,9 +51,11 @@ pub const UI_POSITION_OFFSET: f32 = 1000.; pub struct UiRenderer { device: Arc<Device>, queue: Arc<Queue>, - _config: GraphicsConfig, + config: GraphicsConfig, ctx: Context, pipeline: RenderPipeline, + format: TextureFormat, + pipeline_layout: PipelineLayout, bind_group_layout: BindGroupLayout, textures: RwLock<HashMap<TextureId, (BindGroup, Texture, [u32; 2])>>, surfaces: RwLock<HashMap<ViewportId, UiSurface>>, @@ -82,9 +84,6 @@ impl UiRenderer { format: TextureFormat, config: GraphicsConfig, ) -> Self { - let frag_shader = device.create_shader_module(include_wgsl!("shaders/fragment_ui.wgsl")); - let vert_shader = device.create_shader_module(include_wgsl!("shaders/vertex_ui.wgsl")); - let bind_group_layout = device.create_bind_group_layout(&BindGroupLayoutDescriptor { entries: &[ BindGroupLayoutEntry { @@ -114,8 +113,34 @@ impl UiRenderer { stages: ShaderStages::VERTEX, }], }); - let pipeline = device.create_render_pipeline(&RenderPipelineDescriptor { - label: None, + let pipeline = + Self::create_pipeline(&device, &pipeline_layout, format, config.sample_count); + + Self { + ctx: Context::default(), + pipeline, + device, + queue, + pipeline_layout, + bind_group_layout, + config, + format, + last_pointer: Vec2::ZERO, + textures: HashMap::new().into(), + surfaces: HashMap::new().into(), + } + } + + fn create_pipeline( + device: &Device, + pipeline_layout: &PipelineLayout, + format: TextureFormat, + sample_count: u32, + ) -> RenderPipeline { + let frag_shader = device.create_shader_module(include_wgsl!("shaders/fragment_ui.wgsl")); + let vert_shader = device.create_shader_module(include_wgsl!("shaders/vertex_ui.wgsl")); + device.create_render_pipeline(&RenderPipelineDescriptor { + label: Some("ui pipeline"), layout: Some(&pipeline_layout), fragment: Some(FragmentState { module: &frag_shader, @@ -152,22 +177,23 @@ impl UiRenderer { bias: Default::default(), }), multisample: MultisampleState { - count: config.sample_count, + count: sample_count, ..Default::default() }, multiview: None, cache: None, - }); - Self { - ctx: Context::default(), - pipeline, - device, - queue, - bind_group_layout, - _config: config, - last_pointer: Vec2::ZERO, - textures: HashMap::new().into(), - surfaces: HashMap::new().into(), + }) + } + + pub fn reconfigure(&mut self, config: &GraphicsConfig) { + if self.config.sample_count != config.sample_count { + self.pipeline = Self::create_pipeline( + &self.device, + &self.pipeline_layout, + self.format, + config.sample_count, + ); + self.config.sample_count = config.sample_count; } } |