Skip to content

Commit 92a3527

Browse files
committed
Cleanup depth texture struct
1 parent dd54749 commit 92a3527

File tree

2 files changed

+7
-69
lines changed

2 files changed

+7
-69
lines changed

src/renderer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
gpu_primitives::{CameraUniform, InstanceRaw, Vertex},
44
scene::Scene,
55
sprite::{DrawSprite, Sprite},
6-
texture::Texture,
6+
texture::DepthTexture,
77
};
88
use std::{mem, num::NonZeroU32};
99
use wgpu::{util::DeviceExt, BlendFactor, BlendOperation};
@@ -14,7 +14,7 @@ pub struct Renderer {
1414
sprites: Vec<Sprite>,
1515
uniform_buffer: wgpu::Buffer,
1616
pipeline: wgpu::RenderPipeline,
17-
depth_texture: Texture,
17+
depth_texture: DepthTexture,
1818
uniform_bind_group: wgpu::BindGroup,
1919
}
2020

@@ -104,7 +104,7 @@ impl Renderer {
104104
let fs_module =
105105
device.create_shader_module(&wgpu::include_spirv!("../shaders/shader.frag.spv"));
106106

107-
let depth_texture = Texture::create_depth_texture(&device, &sc_desc);
107+
let depth_texture = DepthTexture::new(&device, &sc_desc);
108108

109109
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
110110
label: None,
@@ -137,7 +137,7 @@ impl Renderer {
137137
..Default::default()
138138
},
139139
depth_stencil: Some(wgpu::DepthStencilState {
140-
format: Texture::DEPTH_FORMAT,
140+
format: DepthTexture::DEPTH_FORMAT,
141141
depth_write_enabled: true,
142142
depth_compare: wgpu::CompareFunction::Less,
143143
stencil: wgpu::StencilState::default(),

src/texture.rs

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,15 @@
11
use image::RgbaImage;
22

3-
pub struct Texture {
3+
pub struct DepthTexture {
44
pub texture: wgpu::Texture,
55
pub view: wgpu::TextureView,
66
pub sampler: wgpu::Sampler,
77
}
88

9-
impl Texture {
9+
impl DepthTexture {
1010
pub const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float;
1111

12-
pub fn _create_sprite_texture(
13-
device: &wgpu::Device,
14-
queue: &wgpu::Queue,
15-
image: RgbaImage,
16-
) -> Self {
17-
let texels = image.to_vec();
18-
let texture_extent = wgpu::Extent3d {
19-
width: image.width(),
20-
height: image.height(),
21-
depth: 1,
22-
};
23-
let desc = &wgpu::TextureDescriptor {
24-
label: None,
25-
size: texture_extent,
26-
mip_level_count: 1,
27-
sample_count: 1,
28-
dimension: wgpu::TextureDimension::D2,
29-
format: wgpu::TextureFormat::Rgba8UnormSrgb,
30-
usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST,
31-
};
32-
33-
let texture = device.create_texture(&desc);
34-
35-
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
36-
37-
queue.write_texture(
38-
wgpu::TextureCopyView {
39-
texture: &texture,
40-
mip_level: 0,
41-
origin: wgpu::Origin3d::ZERO,
42-
},
43-
&texels,
44-
wgpu::TextureDataLayout {
45-
offset: 0,
46-
bytes_per_row: 4 * image.width(),
47-
rows_per_image: 0,
48-
},
49-
texture_extent,
50-
);
51-
52-
// Create other resources
53-
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
54-
label: None,
55-
address_mode_u: wgpu::AddressMode::ClampToEdge,
56-
address_mode_v: wgpu::AddressMode::ClampToEdge,
57-
address_mode_w: wgpu::AddressMode::ClampToEdge,
58-
mag_filter: wgpu::FilterMode::Nearest,
59-
min_filter: wgpu::FilterMode::Linear,
60-
mipmap_filter: wgpu::FilterMode::Nearest,
61-
..Default::default()
62-
});
63-
64-
Self {
65-
texture,
66-
view,
67-
sampler,
68-
}
69-
}
70-
71-
pub fn create_depth_texture(
72-
device: &wgpu::Device,
73-
sc_desc: &wgpu::SwapChainDescriptor,
74-
) -> Self {
12+
pub fn new(device: &wgpu::Device, sc_desc: &wgpu::SwapChainDescriptor) -> Self {
7513
let size = wgpu::Extent3d {
7614
width: sc_desc.width,
7715
height: sc_desc.height,

0 commit comments

Comments
 (0)