From a3f813240181028c6f8579a99c3c89e47c65b14d Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Wed, 11 Dec 2024 20:17:57 +0100 Subject: [PATCH] implement texture resizing on wgpu (untested) --- hui-wgpu/src/lib.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/hui-wgpu/src/lib.rs b/hui-wgpu/src/lib.rs index 91dcdf2..3c2fbed 100644 --- a/hui-wgpu/src/lib.rs +++ b/hui-wgpu/src/lib.rs @@ -242,10 +242,25 @@ impl WgpuUiRenderer { queue.write_buffer(&self.index_buffer, 0, data_idx_view); } - fn update_texture(&self, meta: TextureAtlasMeta, queue: &wgpu::Queue) { + fn update_texture(&mut self, meta: TextureAtlasMeta, queue: &wgpu::Queue, device: &wgpu::Device) { //TODO URGENCY:HIGH resize texture if needed if meta.data.len() as u32 > (self.texture.size().width * self.texture.size().height * 4) { - unimplemented!("texture resize not implemented"); + self.texture.destroy(); + // unimplemented!("texture resize not implemented"); + self.texture = device.create_texture(&wgpu::TextureDescriptor { + label: Some("ui_texture"), + size: wgpu::Extent3d { + width: DEFAULT_TEXTURE_SIZE, + height: DEFAULT_TEXTURE_SIZE, + depth_or_array_layers: 1, + }, + mip_level_count: 1, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: wgpu::TextureFormat::Rgba8UnormSrgb, + usage: wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::TEXTURE_BINDING, + view_formats: &[], + }); } queue.write_texture( wgpu::ImageCopyTexture { @@ -282,7 +297,7 @@ impl WgpuUiRenderer { let meta = instance.atlas(); if self.modified || meta.modified { - self.update_texture(meta, queue); + self.update_texture(meta, queue, device); } self.modified = false;