summaryrefslogtreecommitdiffstats
path: root/third_party/rust/metal/src/sampler.rs
blob: 3dd871a3b48bb6c8a4fb834a661bd06f7213566e (plain)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Copyright 2016 GFX developers
//
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use super::{depthstencil::MTLCompareFunction, DeviceRef, NSUInteger};

#[repr(u64)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum MTLSamplerMinMagFilter {
    Nearest = 0,
    Linear = 1,
}

#[repr(u64)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum MTLSamplerMipFilter {
    NotMipmapped = 0,
    Nearest = 1,
    Linear = 2,
}

#[repr(u64)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum MTLSamplerAddressMode {
    ClampToEdge = 0,
    MirrorClampToEdge = 1,
    Repeat = 2,
    MirrorRepeat = 3,
    ClampToZero = 4,
    ClampToBorderColor = 5,
}

#[repr(u64)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum MTLSamplerBorderColor {
    TransparentBlack = 0,
    OpaqueBlack = 1,
    OpaqueWhite = 2,
}

pub enum MTLSamplerDescriptor {}

foreign_obj_type! {
    type CType = MTLSamplerDescriptor;
    pub struct SamplerDescriptor;
    pub struct SamplerDescriptorRef;
}

impl SamplerDescriptor {
    pub fn new() -> Self {
        unsafe {
            let class = class!(MTLSamplerDescriptor);
            msg_send![class, new]
        }
    }
}

impl SamplerDescriptorRef {
    pub fn set_min_filter(&self, filter: MTLSamplerMinMagFilter) {
        unsafe { msg_send![self, setMinFilter: filter] }
    }

    pub fn set_mag_filter(&self, filter: MTLSamplerMinMagFilter) {
        unsafe { msg_send![self, setMagFilter: filter] }
    }

    pub fn set_mip_filter(&self, filter: MTLSamplerMipFilter) {
        unsafe { msg_send![self, setMipFilter: filter] }
    }

    pub fn set_address_mode_s(&self, mode: MTLSamplerAddressMode) {
        unsafe { msg_send![self, setSAddressMode: mode] }
    }

    pub fn set_address_mode_t(&self, mode: MTLSamplerAddressMode) {
        unsafe { msg_send![self, setTAddressMode: mode] }
    }

    pub fn set_address_mode_r(&self, mode: MTLSamplerAddressMode) {
        unsafe { msg_send![self, setRAddressMode: mode] }
    }

    pub fn set_max_anisotropy(&self, anisotropy: NSUInteger) {
        unsafe { msg_send![self, setMaxAnisotropy: anisotropy] }
    }

    pub fn set_compare_function(&self, func: MTLCompareFunction) {
        unsafe { msg_send![self, setCompareFunction: func] }
    }

    #[cfg(feature = "private")]
    pub unsafe fn set_lod_bias(&self, bias: f32) {
        msg_send![self, setLodBias: bias]
    }

    pub fn set_lod_min_clamp(&self, clamp: f32) {
        unsafe { msg_send![self, setLodMinClamp: clamp] }
    }

    pub fn set_lod_max_clamp(&self, clamp: f32) {
        unsafe { msg_send![self, setLodMaxClamp: clamp] }
    }

    pub fn set_lod_average(&self, enable: bool) {
        unsafe { msg_send![self, setLodAverage: enable] }
    }

    pub fn set_normalized_coordinates(&self, enable: bool) {
        unsafe { msg_send![self, setNormalizedCoordinates: enable] }
    }

    pub fn set_support_argument_buffers(&self, enable: bool) {
        unsafe { msg_send![self, setSupportArgumentBuffers: enable] }
    }

    pub fn set_border_color(&self, color: MTLSamplerBorderColor) {
        unsafe { msg_send![self, setBorderColor: color] }
    }

    pub fn label(&self) -> &str {
        unsafe {
            let label = msg_send![self, label];
            crate::nsstring_as_str(label)
        }
    }

    pub fn set_label(&self, label: &str) {
        unsafe {
            let nslabel = crate::nsstring_from_str(label);
            let () = msg_send![self, setLabel: nslabel];
        }
    }
}

pub enum MTLSamplerState {}

foreign_obj_type! {
    type CType = MTLSamplerState;
    pub struct SamplerState;
    pub struct SamplerStateRef;
}

impl SamplerStateRef {
    pub fn device(&self) -> &DeviceRef {
        unsafe { msg_send![self, device] }
    }

    pub fn label(&self) -> &str {
        unsafe {
            let label = msg_send![self, label];
            crate::nsstring_as_str(label)
        }
    }
}