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
use std;
use std::ops::{Deref, DerefMut};
use core::error::{Result as OclResult};
use core::{self, Sampler as SamplerCore, AddressingMode, FilterMode, SamplerInfo, SamplerInfoResult};
use standard::Context;
#[repr(C)]
pub struct Sampler(SamplerCore);
impl Sampler {
pub fn new(context: &Context, normalize_coords: bool, addressing_mode: AddressingMode,
filter_mode: FilterMode) -> OclResult<Sampler>
{
let sampler_core = try!(core::create_sampler(context, normalize_coords,
addressing_mode, filter_mode));
Ok(Sampler(sampler_core))
}
pub fn with_defaults(context: &Context) -> OclResult<Sampler>
{
let sampler_core = try!(core::create_sampler(context, false,
AddressingMode::None, FilterMode::Nearest));
Ok(Sampler(sampler_core))
}
pub fn info(&self, info_kind: SamplerInfo) -> SamplerInfoResult {
core::get_sampler_info(&self.0, info_kind)
}
fn fmt_info(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_struct("Sampler")
.field("ReferenceCount", &self.info(SamplerInfo::ReferenceCount))
.field("Context", &self.info(SamplerInfo::Context))
.field("NormalizedCoords", &self.info(SamplerInfo::NormalizedCoords))
.field("AddressingMode", &self.info(SamplerInfo::AddressingMode))
.field("FilterMode", &self.info(SamplerInfo::FilterMode))
.finish()
}
}
impl std::fmt::Display for Sampler {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.fmt_info(f)
}
}
impl Deref for Sampler {
type Target = SamplerCore;
fn deref(&self) -> &SamplerCore {
&self.0
}
}
impl DerefMut for Sampler {
fn deref_mut(&mut self) -> &mut SamplerCore {
&mut self.0
}
}