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::core::{device_owned, Device, DeviceId},
relevant::Relevant,
rendy_core::hal::{device::Device as _, image::SamplerDesc, Backend},
};
pub use crate::sampler::cache::SamplerCache;
#[derive(Debug)]
pub struct Sampler<B: Backend> {
device: DeviceId,
raw: B::Sampler,
info: SamplerDesc,
relevant: Relevant,
}
device_owned!(Sampler<B>);
impl<B> Sampler<B>
where
B: Backend,
{
pub fn create(
device: &Device<B>,
info: SamplerDesc,
) -> Result<Self, rendy_core::hal::device::AllocationError> {
let raw = unsafe { device.create_sampler(&info) }?;
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
}
}