objc2_metal/generated/
MTLSampler.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// Options for filtering texels within a mip level.
11///
12///
13/// Select the single texel nearest to the sample point.
14///
15///
16/// Select two texels in each dimension, and interpolate linearly between them.  Not all devices support linear filtering for all formats.  Integer textures can not use linear filtering on any device, and only some devices support linear filtering of Float textures.
17///
18/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlsamplerminmagfilter?language=objc)
19// NS_ENUM
20#[repr(transparent)]
21#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
22pub struct MTLSamplerMinMagFilter(pub NSUInteger);
23impl MTLSamplerMinMagFilter {
24    #[doc(alias = "MTLSamplerMinMagFilterNearest")]
25    pub const Nearest: Self = Self(0);
26    #[doc(alias = "MTLSamplerMinMagFilterLinear")]
27    pub const Linear: Self = Self(1);
28}
29
30unsafe impl Encode for MTLSamplerMinMagFilter {
31    const ENCODING: Encoding = NSUInteger::ENCODING;
32}
33
34unsafe impl RefEncode for MTLSamplerMinMagFilter {
35    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
36}
37
38/// Options for selecting and filtering between mipmap levels
39///
40/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlsamplermipfilter?language=objc)
41// NS_ENUM
42#[repr(transparent)]
43#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
44pub struct MTLSamplerMipFilter(pub NSUInteger);
45impl MTLSamplerMipFilter {
46    #[doc(alias = "MTLSamplerMipFilterNotMipmapped")]
47    pub const NotMipmapped: Self = Self(0);
48    #[doc(alias = "MTLSamplerMipFilterNearest")]
49    pub const Nearest: Self = Self(1);
50    #[doc(alias = "MTLSamplerMipFilterLinear")]
51    pub const Linear: Self = Self(2);
52}
53
54unsafe impl Encode for MTLSamplerMipFilter {
55    const ENCODING: Encoding = NSUInteger::ENCODING;
56}
57
58unsafe impl RefEncode for MTLSamplerMipFilter {
59    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
60}
61
62/// Options for what value is returned when a fetch falls outside the bounds of a texture.
63///
64///
65/// Texture coordinates will be clamped between 0 and 1.
66///
67///
68/// Mirror the texture while coordinates are within -1..1, and clamp to edge when outside.
69///
70///
71/// Wrap to the other side of the texture, effectively ignoring fractional parts of the texture coordinate.
72///
73///
74/// Between -1 and 1 the texture is mirrored across the 0 axis.  The image is repeated outside of that range.
75///
76///
77/// ClampToZero returns transparent zero (0,0,0,0) for images with an alpha channel, and returns opaque zero (0,0,0,1) for images without an alpha channel.
78///
79///
80/// Clamp to border color returns the value specified by the borderColor variable of the MTLSamplerDesc.
81///
82/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlsampleraddressmode?language=objc)
83// NS_ENUM
84#[repr(transparent)]
85#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
86pub struct MTLSamplerAddressMode(pub NSUInteger);
87impl MTLSamplerAddressMode {
88    #[doc(alias = "MTLSamplerAddressModeClampToEdge")]
89    pub const ClampToEdge: Self = Self(0);
90    #[doc(alias = "MTLSamplerAddressModeMirrorClampToEdge")]
91    pub const MirrorClampToEdge: Self = Self(1);
92    #[doc(alias = "MTLSamplerAddressModeRepeat")]
93    pub const Repeat: Self = Self(2);
94    #[doc(alias = "MTLSamplerAddressModeMirrorRepeat")]
95    pub const MirrorRepeat: Self = Self(3);
96    #[doc(alias = "MTLSamplerAddressModeClampToZero")]
97    pub const ClampToZero: Self = Self(4);
98    #[doc(alias = "MTLSamplerAddressModeClampToBorderColor")]
99    pub const ClampToBorderColor: Self = Self(5);
100}
101
102unsafe impl Encode for MTLSamplerAddressMode {
103    const ENCODING: Encoding = NSUInteger::ENCODING;
104}
105
106unsafe impl RefEncode for MTLSamplerAddressMode {
107    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
108}
109
110/// Specify the color value that will be clamped to when the sampler address mode is MTLSamplerAddressModeClampToBorderColor.
111///
112///
113/// Transparent black returns {0,0,0,0} for clamped texture values.
114///
115///
116/// OpaqueBlack returns {0,0,0,1} for clamped texture values.
117///
118///
119/// OpaqueWhite returns {1,1,1,1} for clamped texture values.
120///
121/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlsamplerbordercolor?language=objc)
122// NS_ENUM
123#[repr(transparent)]
124#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
125pub struct MTLSamplerBorderColor(pub NSUInteger);
126impl MTLSamplerBorderColor {
127    #[doc(alias = "MTLSamplerBorderColorTransparentBlack")]
128    pub const TransparentBlack: Self = Self(0);
129    #[doc(alias = "MTLSamplerBorderColorOpaqueBlack")]
130    pub const OpaqueBlack: Self = Self(1);
131    #[doc(alias = "MTLSamplerBorderColorOpaqueWhite")]
132    pub const OpaqueWhite: Self = Self(2);
133}
134
135unsafe impl Encode for MTLSamplerBorderColor {
136    const ENCODING: Encoding = NSUInteger::ENCODING;
137}
138
139unsafe impl RefEncode for MTLSamplerBorderColor {
140    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
141}
142
143/// Configures how the sampler aggregates contributing samples to a final value.
144///
145/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlsamplerreductionmode?language=objc)
146// NS_ENUM
147#[repr(transparent)]
148#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
149pub struct MTLSamplerReductionMode(pub NSUInteger);
150impl MTLSamplerReductionMode {
151    /// A reduction mode that adds together the product of each contributing sample value by its weight.
152    #[doc(alias = "MTLSamplerReductionModeWeightedAverage")]
153    pub const WeightedAverage: Self = Self(0);
154    /// A reduction mode that finds the minimum contributing sample value by separately evaluating each channel.
155    #[doc(alias = "MTLSamplerReductionModeMinimum")]
156    pub const Minimum: Self = Self(1);
157    /// A reduction mode that finds the maximum contributing sample value by separately evaluating each channel.
158    #[doc(alias = "MTLSamplerReductionModeMaximum")]
159    pub const Maximum: Self = Self(2);
160}
161
162unsafe impl Encode for MTLSamplerReductionMode {
163    const ENCODING: Encoding = NSUInteger::ENCODING;
164}
165
166unsafe impl RefEncode for MTLSamplerReductionMode {
167    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
168}
169
170extern_class!(
171    /// A mutable descriptor used to configure a sampler.  When complete, this can be used to create an immutable MTLSamplerState.
172    ///
173    /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlsamplerdescriptor?language=objc)
174    #[unsafe(super(NSObject))]
175    #[derive(Debug, PartialEq, Eq, Hash)]
176    pub struct MTLSamplerDescriptor;
177);
178
179extern_conformance!(
180    unsafe impl NSCopying for MTLSamplerDescriptor {}
181);
182
183unsafe impl CopyingHelper for MTLSamplerDescriptor {
184    type Result = Self;
185}
186
187extern_conformance!(
188    unsafe impl NSObjectProtocol for MTLSamplerDescriptor {}
189);
190
191impl MTLSamplerDescriptor {
192    extern_methods!(
193        /// Filter option for combining texels within a mipmap level the sample footprint is larger than a pixel (minification).
194        ///
195        /// The default value is MTLSamplerMinMagFilterNearest.
196        #[unsafe(method(minFilter))]
197        #[unsafe(method_family = none)]
198        pub fn minFilter(&self) -> MTLSamplerMinMagFilter;
199
200        /// Setter for [`minFilter`][Self::minFilter].
201        #[unsafe(method(setMinFilter:))]
202        #[unsafe(method_family = none)]
203        pub fn setMinFilter(&self, min_filter: MTLSamplerMinMagFilter);
204
205        /// Filter option for combining texels within a mipmap level the sample footprint is smaller than a pixel (magnification).
206        ///
207        /// The default value is MTLSamplerMinMagFilterNearest.
208        #[unsafe(method(magFilter))]
209        #[unsafe(method_family = none)]
210        pub fn magFilter(&self) -> MTLSamplerMinMagFilter;
211
212        /// Setter for [`magFilter`][Self::magFilter].
213        #[unsafe(method(setMagFilter:))]
214        #[unsafe(method_family = none)]
215        pub fn setMagFilter(&self, mag_filter: MTLSamplerMinMagFilter);
216
217        /// Filter options for filtering between two mipmap levels.
218        ///
219        /// The default value is MTLSamplerMipFilterNotMipmapped
220        #[unsafe(method(mipFilter))]
221        #[unsafe(method_family = none)]
222        pub fn mipFilter(&self) -> MTLSamplerMipFilter;
223
224        /// Setter for [`mipFilter`][Self::mipFilter].
225        #[unsafe(method(setMipFilter:))]
226        #[unsafe(method_family = none)]
227        pub fn setMipFilter(&self, mip_filter: MTLSamplerMipFilter);
228
229        /// The number of samples that can be taken to improve quality of sample footprints that are anisotropic.
230        ///
231        /// The default value is 1.
232        #[unsafe(method(maxAnisotropy))]
233        #[unsafe(method_family = none)]
234        pub fn maxAnisotropy(&self) -> NSUInteger;
235
236        /// Setter for [`maxAnisotropy`][Self::maxAnisotropy].
237        #[unsafe(method(setMaxAnisotropy:))]
238        #[unsafe(method_family = none)]
239        pub fn setMaxAnisotropy(&self, max_anisotropy: NSUInteger);
240
241        /// Set the wrap mode for the S texture coordinate.  The default value is MTLSamplerAddressModeClampToEdge.
242        #[unsafe(method(sAddressMode))]
243        #[unsafe(method_family = none)]
244        pub fn sAddressMode(&self) -> MTLSamplerAddressMode;
245
246        /// Setter for [`sAddressMode`][Self::sAddressMode].
247        #[unsafe(method(setSAddressMode:))]
248        #[unsafe(method_family = none)]
249        pub fn setSAddressMode(&self, s_address_mode: MTLSamplerAddressMode);
250
251        /// Set the wrap mode for the T texture coordinate.  The default value is MTLSamplerAddressModeClampToEdge.
252        #[unsafe(method(tAddressMode))]
253        #[unsafe(method_family = none)]
254        pub fn tAddressMode(&self) -> MTLSamplerAddressMode;
255
256        /// Setter for [`tAddressMode`][Self::tAddressMode].
257        #[unsafe(method(setTAddressMode:))]
258        #[unsafe(method_family = none)]
259        pub fn setTAddressMode(&self, t_address_mode: MTLSamplerAddressMode);
260
261        /// Set the wrap mode for the R texture coordinate.  The default value is MTLSamplerAddressModeClampToEdge.
262        #[unsafe(method(rAddressMode))]
263        #[unsafe(method_family = none)]
264        pub fn rAddressMode(&self) -> MTLSamplerAddressMode;
265
266        /// Setter for [`rAddressMode`][Self::rAddressMode].
267        #[unsafe(method(setRAddressMode:))]
268        #[unsafe(method_family = none)]
269        pub fn setRAddressMode(&self, r_address_mode: MTLSamplerAddressMode);
270
271        /// Set the color for the MTLSamplerAddressMode to one of the predefined in the MTLSamplerBorderColor enum.
272        #[unsafe(method(borderColor))]
273        #[unsafe(method_family = none)]
274        pub fn borderColor(&self) -> MTLSamplerBorderColor;
275
276        /// Setter for [`borderColor`][Self::borderColor].
277        #[unsafe(method(setBorderColor:))]
278        #[unsafe(method_family = none)]
279        pub fn setBorderColor(&self, border_color: MTLSamplerBorderColor);
280
281        /// Sets the reduction mode for filtering contributing samples.
282        ///
283        /// The property's default value is ``MTLSamplerReductionModeWeightedAverage``.
284        /// The sampler ignores this property if any of the following property values are equal to a specific value:
285        /// - The sampler's ``mipFilter`` property is equal to ``MTLSamplerMipFilterNotMipmapped``.
286        /// - The sampler's ``mipFilter`` property is equal to ``MTLSamplerMipFilterNearest``.
287        /// - The sampler's ``minFilter`` property is equal to ``MTLSamplerMinMagFilterNearest``.
288        /// - The sampler's ``magFilter`` property is equal to ``MTLSamplerMinMagFilterNearest``.
289        #[unsafe(method(reductionMode))]
290        #[unsafe(method_family = none)]
291        pub fn reductionMode(&self) -> MTLSamplerReductionMode;
292
293        /// Setter for [`reductionMode`][Self::reductionMode].
294        #[unsafe(method(setReductionMode:))]
295        #[unsafe(method_family = none)]
296        pub fn setReductionMode(&self, reduction_mode: MTLSamplerReductionMode);
297
298        /// If YES, texture coordates are from 0 to 1.  If NO, texture coordinates are 0..width, 0..height.
299        ///
300        /// normalizedCoordinates defaults to YES.  Non-normalized coordinates should only be used with 1D and 2D textures with the ClampToEdge wrap mode, otherwise the results of sampling are undefined.
301        #[unsafe(method(normalizedCoordinates))]
302        #[unsafe(method_family = none)]
303        pub fn normalizedCoordinates(&self) -> bool;
304
305        /// Setter for [`normalizedCoordinates`][Self::normalizedCoordinates].
306        #[unsafe(method(setNormalizedCoordinates:))]
307        #[unsafe(method_family = none)]
308        pub fn setNormalizedCoordinates(&self, normalized_coordinates: bool);
309
310        /// The minimum level of detail that will be used when sampling from a texture.
311        ///
312        /// The default value of lodMinClamp is 0.0.  Clamp values are ignored for texture sample variants that specify an explicit level of detail.
313        #[unsafe(method(lodMinClamp))]
314        #[unsafe(method_family = none)]
315        pub fn lodMinClamp(&self) -> c_float;
316
317        /// Setter for [`lodMinClamp`][Self::lodMinClamp].
318        #[unsafe(method(setLodMinClamp:))]
319        #[unsafe(method_family = none)]
320        pub fn setLodMinClamp(&self, lod_min_clamp: c_float);
321
322        /// The maximum level of detail that will be used when sampling from a texture.
323        ///
324        /// The default value of lodMaxClamp is FLT_MAX.  Clamp values are ignored for texture sample variants that specify an explicit level of detail.
325        #[unsafe(method(lodMaxClamp))]
326        #[unsafe(method_family = none)]
327        pub fn lodMaxClamp(&self) -> c_float;
328
329        /// Setter for [`lodMaxClamp`][Self::lodMaxClamp].
330        #[unsafe(method(setLodMaxClamp:))]
331        #[unsafe(method_family = none)]
332        pub fn setLodMaxClamp(&self, lod_max_clamp: c_float);
333
334        /// If YES, an average level of detail will be used when sampling from a texture. If NO, no averaging is performed.
335        ///
336        /// lodAverage defaults to NO. This option is a performance hint. An implementation is free to ignore this property.
337        #[unsafe(method(lodAverage))]
338        #[unsafe(method_family = none)]
339        pub fn lodAverage(&self) -> bool;
340
341        /// Setter for [`lodAverage`][Self::lodAverage].
342        #[unsafe(method(setLodAverage:))]
343        #[unsafe(method_family = none)]
344        pub fn setLodAverage(&self, lod_average: bool);
345
346        /// Sets the level-of-detail (lod) bias when sampling from a texture.
347        ///
348        /// The property's default value is `0.0f`.
349        /// The precision format is `S4.6`, and the range is `[-16.0, 15.999]`.
350        #[unsafe(method(lodBias))]
351        #[unsafe(method_family = none)]
352        pub fn lodBias(&self) -> c_float;
353
354        /// Setter for [`lodBias`][Self::lodBias].
355        #[unsafe(method(setLodBias:))]
356        #[unsafe(method_family = none)]
357        pub fn setLodBias(&self, lod_bias: c_float);
358
359        #[cfg(feature = "MTLDepthStencil")]
360        /// Set the comparison function used when sampling shadow maps. The default value is MTLCompareFunctionNever.
361        #[unsafe(method(compareFunction))]
362        #[unsafe(method_family = none)]
363        pub fn compareFunction(&self) -> MTLCompareFunction;
364
365        #[cfg(feature = "MTLDepthStencil")]
366        /// Setter for [`compareFunction`][Self::compareFunction].
367        #[unsafe(method(setCompareFunction:))]
368        #[unsafe(method_family = none)]
369        pub fn setCompareFunction(&self, compare_function: MTLCompareFunction);
370
371        /// true if the sampler can be used inside an argument buffer
372        #[unsafe(method(supportArgumentBuffers))]
373        #[unsafe(method_family = none)]
374        pub fn supportArgumentBuffers(&self) -> bool;
375
376        /// Setter for [`supportArgumentBuffers`][Self::supportArgumentBuffers].
377        #[unsafe(method(setSupportArgumentBuffers:))]
378        #[unsafe(method_family = none)]
379        pub fn setSupportArgumentBuffers(&self, support_argument_buffers: bool);
380
381        /// A string to help identify the created object.
382        #[unsafe(method(label))]
383        #[unsafe(method_family = none)]
384        pub fn label(&self) -> Option<Retained<NSString>>;
385
386        /// Setter for [`label`][Self::label].
387        ///
388        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
389        #[unsafe(method(setLabel:))]
390        #[unsafe(method_family = none)]
391        pub fn setLabel(&self, label: Option<&NSString>);
392    );
393}
394
395/// Methods declared on superclass `NSObject`.
396impl MTLSamplerDescriptor {
397    extern_methods!(
398        #[unsafe(method(init))]
399        #[unsafe(method_family = init)]
400        pub fn init(this: Allocated<Self>) -> Retained<Self>;
401
402        #[unsafe(method(new))]
403        #[unsafe(method_family = new)]
404        pub fn new() -> Retained<Self>;
405    );
406}
407
408impl DefaultRetained for MTLSamplerDescriptor {
409    #[inline]
410    fn default_retained() -> Retained<Self> {
411        Self::new()
412    }
413}
414
415extern_protocol!(
416    /// An immutable collection of sampler state compiled for a single device.
417    ///
418    /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlsamplerstate?language=objc)
419    pub unsafe trait MTLSamplerState: NSObjectProtocol + Send + Sync {
420        /// A string to help identify this object.
421        #[unsafe(method(label))]
422        #[unsafe(method_family = none)]
423        fn label(&self) -> Option<Retained<NSString>>;
424
425        #[cfg(feature = "MTLDevice")]
426        /// The device this resource was created against.  This resource can only be used with this device.
427        #[unsafe(method(device))]
428        #[unsafe(method_family = none)]
429        fn device(&self) -> Retained<ProtocolObject<dyn MTLDevice>>;
430
431        #[cfg(feature = "MTLTypes")]
432        /// Handle of the GPU resource suitable for storing in an Argument Buffer
433        #[unsafe(method(gpuResourceID))]
434        #[unsafe(method_family = none)]
435        fn gpuResourceID(&self) -> MTLResourceID;
436    }
437);