@@ -32,15 +32,14 @@ struct BladeAtlasState {
impl BladeAtlasState {
fn destroy(&mut self) {
- for texture in self.monochrome_textures.drain(..) {
- self.gpu.destroy_texture(texture.raw);
+ for mut texture in self.monochrome_textures.drain(..) {
+ texture.destroy(&self.gpu);
}
- for texture in self.polychrome_textures.drain(..) {
- self.gpu.destroy_texture(texture.raw);
+ for mut texture in self.polychrome_textures.drain(..) {
+ texture.destroy(&self.gpu);
}
- for texture in self.path_textures.drain(..) {
- self.gpu.destroy_texture(texture.raw);
- self.gpu.destroy_texture_view(texture.raw_view.unwrap());
+ for mut texture in self.path_textures.drain(..) {
+ texture.destroy(&self.gpu);
}
self.upload_belt.destroy(&self.gpu);
}
@@ -48,7 +47,7 @@ impl BladeAtlasState {
pub struct BladeTextureInfo {
pub size: gpu::Extent,
- pub raw_view: Option<gpu::TextureView>,
+ pub raw_view: gpu::TextureView,
}
impl BladeAtlas {
@@ -198,17 +197,13 @@ impl BladeAtlasState {
dimension: gpu::TextureDimension::D2,
usage,
});
- let raw_view = if usage.contains(gpu::TextureUsage::TARGET) {
- Some(self.gpu.create_texture_view(gpu::TextureViewDesc {
- name: "",
- texture: raw,
- format,
- dimension: gpu::ViewDimension::D2,
- subresources: &Default::default(),
- }))
- } else {
- None
- };
+ let raw_view = self.gpu.create_texture_view(gpu::TextureViewDesc {
+ name: "",
+ texture: raw,
+ format,
+ dimension: gpu::ViewDimension::D2,
+ subresources: &Default::default(),
+ });
let textures = match kind {
AtlasTextureKind::Monochrome => &mut self.monochrome_textures,
@@ -270,7 +265,7 @@ struct BladeAtlasTexture {
id: AtlasTextureId,
allocator: BucketedAtlasAllocator,
raw: gpu::Texture,
- raw_view: Option<gpu::TextureView>,
+ raw_view: gpu::TextureView,
format: gpu::TextureFormat,
}
@@ -293,6 +288,11 @@ impl BladeAtlasTexture {
Some(tile)
}
+ fn destroy(&mut self, gpu: &gpu::Context) {
+ gpu.destroy_texture(self.raw);
+ gpu.destroy_texture_view(self.raw_view);
+ }
+
fn bytes_per_pixel(&self) -> u8 {
self.format.block_info().size
}
@@ -336,7 +336,7 @@ impl BladeRenderer {
let vertex_buf = self.instance_belt.alloc_data(&vertices, &self.gpu);
let mut pass = self.command_encoder.render(gpu::RenderTargetSet {
colors: &[gpu::RenderTarget {
- view: tex_info.raw_view.unwrap(),
+ view: tex_info.raw_view,
init_op: gpu::InitOp::Clear(gpu::TextureColor::OpaqueBlack),
finish_op: gpu::FinishOp::Store,
}],
@@ -426,7 +426,7 @@ impl BladeRenderer {
0,
&ShaderPathsData {
globals,
- t_sprite: tex_info.raw_view.unwrap(),
+ t_sprite: tex_info.raw_view,
s_sprite: self.atlas_sampler,
b_path_sprites: instance_buf,
},
@@ -457,7 +457,7 @@ impl BladeRenderer {
0,
&ShaderMonoSpritesData {
globals,
- t_sprite: tex_info.raw_view.unwrap(),
+ t_sprite: tex_info.raw_view,
s_sprite: self.atlas_sampler,
b_mono_sprites: instance_buf,
},
@@ -475,7 +475,7 @@ impl BladeRenderer {
0,
&ShaderPolySpritesData {
globals,
- t_sprite: tex_info.raw_view.unwrap(),
+ t_sprite: tex_info.raw_view,
s_sprite: self.atlas_sampler,
b_poly_sprites: instance_buf,
},