| 1 |
// Copyright 2016 GFX developers |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or |
| 4 |
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or |
| 5 |
// http://opensource.org/licenses/MIT>, at your option. This file may not be |
| 6 |
// copied, modified, or distributed except according to those terms. |
| 7 |
|
| 8 |
use super::{depthstencil::MTLCompareFunction, DeviceRef, MTLResourceID, NSUInteger}; |
| 9 |
|
| 10 |
/// See <https://developer.apple.com/documentation/metal/mtlsamplerminmagfilter> |
| 11 |
#[repr(u64)] |
| 12 |
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] |
| 13 |
pub enum MTLSamplerMinMagFilter { |
| 14 |
Nearest = 0, |
| 15 |
Linear = 1, |
| 16 |
} |
| 17 |
|
| 18 |
/// See <https://developer.apple.com/documentation/metal/mtlsamplermipfilter> |
| 19 |
#[repr(u64)] |
| 20 |
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] |
| 21 |
pub enum MTLSamplerMipFilter { |
| 22 |
NotMipmapped = 0, |
| 23 |
Nearest = 1, |
| 24 |
Linear = 2, |
| 25 |
} |
| 26 |
|
| 27 |
/// See <https://developer.apple.com/documentation/metal/mtlsampleraddressmode> |
| 28 |
#[repr(u64)] |
| 29 |
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] |
| 30 |
pub enum MTLSamplerAddressMode { |
| 31 |
ClampToEdge = 0, |
| 32 |
MirrorClampToEdge = 1, |
| 33 |
Repeat = 2, |
| 34 |
MirrorRepeat = 3, |
| 35 |
ClampToZero = 4, |
| 36 |
ClampToBorderColor = 5, |
| 37 |
} |
| 38 |
|
| 39 |
/// See <https://developer.apple.com/documentation/metal/mtlsamplerbordercolor> |
| 40 |
#[repr(u64)] |
| 41 |
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] |
| 42 |
pub enum MTLSamplerBorderColor { |
| 43 |
TransparentBlack = 0, |
| 44 |
OpaqueBlack = 1, |
| 45 |
OpaqueWhite = 2, |
| 46 |
} |
| 47 |
|
| 48 |
/// See <https://developer.apple.com/documentation/metal/mtlsamplerdescriptor> |
| 49 |
pub enum MTLSamplerDescriptor {} |
| 50 |
|
| 51 |
foreign_obj_type! { |
| 52 |
type CType = MTLSamplerDescriptor; |
| 53 |
pub struct SamplerDescriptor; |
| 54 |
} |
| 55 |
|
| 56 |
impl SamplerDescriptor { |
| 57 |
pub fn new() -> Self { |
| 58 |
unsafe { |
| 59 |
let class = class!(MTLSamplerDescriptor); |
| 60 |
msg_send![class, new] |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
impl SamplerDescriptorRef { |
| 66 |
pub fn set_min_filter(&self, filter: MTLSamplerMinMagFilter) { |
| 67 |
unsafe { msg_send![self, setMinFilter: filter] } |
| 68 |
} |
| 69 |
|
| 70 |
pub fn set_mag_filter(&self, filter: MTLSamplerMinMagFilter) { |
| 71 |
unsafe { msg_send![self, setMagFilter: filter] } |
| 72 |
} |
| 73 |
|
| 74 |
pub fn set_mip_filter(&self, filter: MTLSamplerMipFilter) { |
| 75 |
unsafe { msg_send![self, setMipFilter: filter] } |
| 76 |
} |
| 77 |
|
| 78 |
pub fn set_address_mode_s(&self, mode: MTLSamplerAddressMode) { |
| 79 |
unsafe { msg_send![self, setSAddressMode: mode] } |
| 80 |
} |
| 81 |
|
| 82 |
pub fn set_address_mode_t(&self, mode: MTLSamplerAddressMode) { |
| 83 |
unsafe { msg_send![self, setTAddressMode: mode] } |
| 84 |
} |
| 85 |
|
| 86 |
pub fn set_address_mode_r(&self, mode: MTLSamplerAddressMode) { |
| 87 |
unsafe { msg_send![self, setRAddressMode: mode] } |
| 88 |
} |
| 89 |
|
| 90 |
pub fn set_max_anisotropy(&self, anisotropy: NSUInteger) { |
| 91 |
unsafe { msg_send![self, setMaxAnisotropy: anisotropy] } |
| 92 |
} |
| 93 |
|
| 94 |
pub fn set_compare_function(&self, func: MTLCompareFunction) { |
| 95 |
unsafe { msg_send![self, setCompareFunction: func] } |
| 96 |
} |
| 97 |
|
| 98 |
#[cfg(feature = "private")] |
| 99 |
pub unsafe fn set_lod_bias(&self, bias: f32) { |
| 100 |
msg_send![self, setLodBias: bias] |
| 101 |
} |
| 102 |
|
| 103 |
pub fn set_lod_min_clamp(&self, clamp: f32) { |
| 104 |
unsafe { msg_send![self, setLodMinClamp: clamp] } |
| 105 |
} |
| 106 |
|
| 107 |
pub fn set_lod_max_clamp(&self, clamp: f32) { |
| 108 |
unsafe { msg_send![self, setLodMaxClamp: clamp] } |
| 109 |
} |
| 110 |
|
| 111 |
pub fn set_lod_average(&self, enable: bool) { |
| 112 |
unsafe { msg_send![self, setLodAverage: enable] } |
| 113 |
} |
| 114 |
|
| 115 |
pub fn set_normalized_coordinates(&self, enable: bool) { |
| 116 |
unsafe { msg_send![self, setNormalizedCoordinates: enable] } |
| 117 |
} |
| 118 |
|
| 119 |
pub fn set_support_argument_buffers(&self, enable: bool) { |
| 120 |
unsafe { msg_send![self, setSupportArgumentBuffers: enable] } |
| 121 |
} |
| 122 |
|
| 123 |
pub fn set_border_color(&self, color: MTLSamplerBorderColor) { |
| 124 |
unsafe { msg_send![self, setBorderColor: color] } |
| 125 |
} |
| 126 |
|
| 127 |
pub fn label(&self) -> &str { |
| 128 |
unsafe { |
| 129 |
let label = msg_send![self, label]; |
| 130 |
crate::nsstring_as_str(label) |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
pub fn set_label(&self, label: &str) { |
| 135 |
unsafe { |
| 136 |
let nslabel = crate::nsstring_from_str(label); |
| 137 |
let () = msg_send![self, setLabel: nslabel]; |
| 138 |
} |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
/// See <https://developer.apple.com/documentation/metal/mtlsamplerstate> |
| 143 |
pub enum MTLSamplerState {} |
| 144 |
|
| 145 |
foreign_obj_type! { |
| 146 |
type CType = MTLSamplerState; |
| 147 |
pub struct SamplerState; |
| 148 |
} |
| 149 |
|
| 150 |
impl SamplerStateRef { |
| 151 |
pub fn device(&self) -> &DeviceRef { |
| 152 |
unsafe { msg_send![self, device] } |
| 153 |
} |
| 154 |
|
| 155 |
pub fn label(&self) -> &str { |
| 156 |
unsafe { |
| 157 |
let label = msg_send![self, label]; |
| 158 |
crate::nsstring_as_str(label) |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
pub fn gpu_resource_id(&self) -> MTLResourceID { |
| 163 |
unsafe { msg_send![self, gpuResourceID] } |
| 164 |
} |
| 165 |
} |