|
1 | 1 | use image::RgbaImage;
|
2 | 2 |
|
3 |
| -pub struct Texture { |
| 3 | +pub struct DepthTexture { |
4 | 4 | pub texture: wgpu::Texture,
|
5 | 5 | pub view: wgpu::TextureView,
|
6 | 6 | pub sampler: wgpu::Sampler,
|
7 | 7 | }
|
8 | 8 |
|
9 |
| -impl Texture { |
| 9 | +impl DepthTexture { |
10 | 10 | pub const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float;
|
11 | 11 |
|
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 { |
75 | 13 | let size = wgpu::Extent3d {
|
76 | 14 | width: sc_desc.width,
|
77 | 15 | height: sc_desc.height,
|
|
0 commit comments