1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
mod atlas_version;
mod gpu_atlas;
mod sampler_handle;
mod texture_handle;
pub use self::{
atlas_version::AtlasVersion, gpu_atlas::GpuAtlas,
sampler_handle::SamplerHandle, texture_handle::TextureHandle,
};
use crate::graphics::Graphics;
use anyhow::Result;
use ash::{version::DeviceV1_0, vk};
use super::vulkan::texture::TextureImage;
pub const MAX_SUPPORTED_TEXTURES: usize = 64;
pub trait TextureAtlas {
fn version(&self) -> AtlasVersion;
fn build_descriptor_image_info(&self) -> Vec<vk::DescriptorImageInfo>;
fn add_sampler(&mut self, sampler: vk::Sampler) -> Result<SamplerHandle>;
fn add_texture(&mut self, texture: TextureImage) -> Result<TextureHandle>;
unsafe fn take_texture(
&mut self,
texture_handle: TextureHandle,
) -> Result<TextureImage>;
fn bind_sampler_to_texture(
&mut self,
sampler_handle: SamplerHandle,
texture_handle: TextureHandle,
) -> Result<()>;
}
impl TextureAtlas for Graphics {
fn version(&self) -> AtlasVersion {
self.texture_atlas.version()
}
fn build_descriptor_image_info(&self) -> Vec<vk::DescriptorImageInfo> {
self.texture_atlas.build_descriptor_image_info()
}
fn add_sampler(&mut self, sampler: vk::Sampler) -> Result<SamplerHandle> {
self.texture_atlas.add_sampler(sampler)
}
fn bind_sampler_to_texture(
&mut self,
sampler_handle: SamplerHandle,
texture_handle: TextureHandle,
) -> Result<()> {
self.texture_atlas
.bind_sampler_to_texture(sampler_handle, texture_handle)
}
fn add_texture(&mut self, texture: TextureImage) -> Result<TextureHandle> {
self.texture_atlas.add_texture(texture)
}
unsafe fn take_texture(
&mut self,
texture_handle: TextureHandle,
) -> Result<TextureImage> {
self.device.logical_device.device_wait_idle()?;
self.texture_atlas.take_texture(texture_handle)
}
}