Q1: Create a render texture and register it for sampling via drawTexture. Returns (bind_group_index, texture_vec_index).
(&mut self, width: u32, height: u32)
| 6262 | /// Q1: Create a render texture and register it for sampling via drawTexture. |
| 6263 | /// Returns (bind_group_index, texture_vec_index). |
| 6264 | pub fn create_render_texture(&mut self, width: u32, height: u32) -> (u32, usize) { |
| 6265 | let texture = self.device.create_texture(&wgpu::TextureDescriptor { |
| 6266 | label: Some("render_texture"), |
| 6267 | size: wgpu::Extent3d { width, height, depth_or_array_layers: 1 }, |
| 6268 | mip_level_count: 1, sample_count: 1, |
| 6269 | dimension: wgpu::TextureDimension::D2, |
| 6270 | format: self.surface_config.format, |
| 6271 | usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING, |
| 6272 | view_formats: &[], |
| 6273 | }); |
| 6274 | let tex_view = texture.create_view(&wgpu::TextureViewDescriptor::default()); |
| 6275 | let bind_group = self.device.create_bind_group(&wgpu::BindGroupDescriptor { |
| 6276 | label: Some("rt_bg"), layout: &self.texture_bind_group_layout, |
| 6277 | entries: &[ |
| 6278 | wgpu::BindGroupEntry { binding: 0, resource: wgpu::BindingResource::TextureView(&tex_view) }, |
| 6279 | wgpu::BindGroupEntry { binding: 1, resource: wgpu::BindingResource::Sampler(&self.sampler) }, |
| 6280 | ], |
| 6281 | }); |
| 6282 | let idx = self.texture_bind_groups.len() as u32; |
| 6283 | let tex_idx = self.textures.len(); |
| 6284 | self.texture_bind_groups.push(bind_group); |
| 6285 | self.textures.push(texture); |
| 6286 | self.texture_sizes.push((width, height)); |
| 6287 | (idx, tex_idx) |
| 6288 | } |
| 6289 | |
| 6290 | /// Q1: Get a reference to an internal texture by index. |
| 6291 | pub fn get_texture_ref(&self, index: usize) -> Option<&wgpu::Texture> { |
no test coverage detected