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
mod cache;
use {
crate::util::{device_owned, Device, DeviceId},
gfx_hal::{image::SamplerInfo, Backend, Device as _},
relevant::Relevant,
};
pub use crate::sampler::cache::SamplerCache;
#[derive(Debug)]
pub struct Sampler<B: Backend> {
device: DeviceId,
raw: B::Sampler,
info: SamplerInfo,
relevant: Relevant,
}
device_owned!(Sampler<B>);
impl<B> Sampler<B>
where
B: Backend,
{
pub fn create(
device: &Device<B>,
info: SamplerInfo,
) -> Result<Self, gfx_hal::device::AllocationError> {
let raw = unsafe { device.create_sampler(info.clone()) }?;
Ok(Sampler {
device: device.id(),
raw,
info,
relevant: Relevant,
})
}
pub unsafe fn dispose(self, device: &Device<B>) {
self.assert_device_owner(device);
device.destroy_sampler(self.raw);
self.relevant.dispose();
}
pub fn raw(&self) -> &B::Sampler {
&self.raw
}
pub unsafe fn raw_mut(&mut self) -> &mut B::Sampler {
&mut self.raw
}
}