MTLSampler.hpp
1 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 2 // 3 // Metal/MTLSampler.hpp 4 // 5 // Copyright 2020-2024 Apple Inc. 6 // 7 // Licensed under the Apache License, Version 2.0 (the "License"); 8 // you may not use this file except in compliance with the License. 9 // You may obtain a copy of the License at 10 // 11 // http://www.apache.org/licenses/LICENSE-2.0 12 // 13 // Unless required by applicable law or agreed to in writing, software 14 // distributed under the License is distributed on an "AS IS" BASIS, 15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 // See the License for the specific language governing permissions and 17 // limitations under the License. 18 // 19 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 20 21 #pragma once 22 23 #include "MTLDefines.hpp" 24 #include "MTLHeaderBridge.hpp" 25 #include "MTLPrivate.hpp" 26 27 #include <Foundation/Foundation.hpp> 28 29 #include "MTLDepthStencil.hpp" 30 #include "MTLSampler.hpp" 31 #include "MTLTypes.hpp" 32 33 namespace MTL 34 { 35 _MTL_ENUM(NS::UInteger, SamplerMinMagFilter) { 36 SamplerMinMagFilterNearest = 0, 37 SamplerMinMagFilterLinear = 1, 38 }; 39 40 _MTL_ENUM(NS::UInteger, SamplerMipFilter) { 41 SamplerMipFilterNotMipmapped = 0, 42 SamplerMipFilterNearest = 1, 43 SamplerMipFilterLinear = 2, 44 }; 45 46 _MTL_ENUM(NS::UInteger, SamplerAddressMode) { 47 SamplerAddressModeClampToEdge = 0, 48 SamplerAddressModeMirrorClampToEdge = 1, 49 SamplerAddressModeRepeat = 2, 50 SamplerAddressModeMirrorRepeat = 3, 51 SamplerAddressModeClampToZero = 4, 52 SamplerAddressModeClampToBorderColor = 5, 53 }; 54 55 _MTL_ENUM(NS::UInteger, SamplerBorderColor) { 56 SamplerBorderColorTransparentBlack = 0, 57 SamplerBorderColorOpaqueBlack = 1, 58 SamplerBorderColorOpaqueWhite = 2, 59 }; 60 61 class SamplerDescriptor : public NS::Copying<SamplerDescriptor> 62 { 63 public: 64 static class SamplerDescriptor* alloc(); 65 66 class SamplerDescriptor* init(); 67 68 MTL::SamplerMinMagFilter minFilter() const; 69 void setMinFilter(MTL::SamplerMinMagFilter minFilter); 70 71 MTL::SamplerMinMagFilter magFilter() const; 72 void setMagFilter(MTL::SamplerMinMagFilter magFilter); 73 74 MTL::SamplerMipFilter mipFilter() const; 75 void setMipFilter(MTL::SamplerMipFilter mipFilter); 76 77 NS::UInteger maxAnisotropy() const; 78 void setMaxAnisotropy(NS::UInteger maxAnisotropy); 79 80 MTL::SamplerAddressMode sAddressMode() const; 81 void setSAddressMode(MTL::SamplerAddressMode sAddressMode); 82 83 MTL::SamplerAddressMode tAddressMode() const; 84 void setTAddressMode(MTL::SamplerAddressMode tAddressMode); 85 86 MTL::SamplerAddressMode rAddressMode() const; 87 void setRAddressMode(MTL::SamplerAddressMode rAddressMode); 88 89 MTL::SamplerBorderColor borderColor() const; 90 void setBorderColor(MTL::SamplerBorderColor borderColor); 91 92 bool normalizedCoordinates() const; 93 void setNormalizedCoordinates(bool normalizedCoordinates); 94 95 float lodMinClamp() const; 96 void setLodMinClamp(float lodMinClamp); 97 98 float lodMaxClamp() const; 99 void setLodMaxClamp(float lodMaxClamp); 100 101 bool lodAverage() const; 102 void setLodAverage(bool lodAverage); 103 104 MTL::CompareFunction compareFunction() const; 105 void setCompareFunction(MTL::CompareFunction compareFunction); 106 107 bool supportArgumentBuffers() const; 108 void setSupportArgumentBuffers(bool supportArgumentBuffers); 109 110 NS::String* label() const; 111 void setLabel(const NS::String* label); 112 }; 113 114 class SamplerState : public NS::Referencing<SamplerState> 115 { 116 public: 117 NS::String* label() const; 118 119 class Device* device() const; 120 121 MTL::ResourceID gpuResourceID() const; 122 }; 123 124 } 125 126 // static method: alloc 127 _MTL_INLINE MTL::SamplerDescriptor* MTL::SamplerDescriptor::alloc() 128 { 129 return NS::Object::alloc<MTL::SamplerDescriptor>(_MTL_PRIVATE_CLS(MTLSamplerDescriptor)); 130 } 131 132 // method: init 133 _MTL_INLINE MTL::SamplerDescriptor* MTL::SamplerDescriptor::init() 134 { 135 return NS::Object::init<MTL::SamplerDescriptor>(); 136 } 137 138 // property: minFilter 139 _MTL_INLINE MTL::SamplerMinMagFilter MTL::SamplerDescriptor::minFilter() const 140 { 141 return Object::sendMessage<MTL::SamplerMinMagFilter>(this, _MTL_PRIVATE_SEL(minFilter)); 142 } 143 144 _MTL_INLINE void MTL::SamplerDescriptor::setMinFilter(MTL::SamplerMinMagFilter minFilter) 145 { 146 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMinFilter_), minFilter); 147 } 148 149 // property: magFilter 150 _MTL_INLINE MTL::SamplerMinMagFilter MTL::SamplerDescriptor::magFilter() const 151 { 152 return Object::sendMessage<MTL::SamplerMinMagFilter>(this, _MTL_PRIVATE_SEL(magFilter)); 153 } 154 155 _MTL_INLINE void MTL::SamplerDescriptor::setMagFilter(MTL::SamplerMinMagFilter magFilter) 156 { 157 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMagFilter_), magFilter); 158 } 159 160 // property: mipFilter 161 _MTL_INLINE MTL::SamplerMipFilter MTL::SamplerDescriptor::mipFilter() const 162 { 163 return Object::sendMessage<MTL::SamplerMipFilter>(this, _MTL_PRIVATE_SEL(mipFilter)); 164 } 165 166 _MTL_INLINE void MTL::SamplerDescriptor::setMipFilter(MTL::SamplerMipFilter mipFilter) 167 { 168 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMipFilter_), mipFilter); 169 } 170 171 // property: maxAnisotropy 172 _MTL_INLINE NS::UInteger MTL::SamplerDescriptor::maxAnisotropy() const 173 { 174 return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(maxAnisotropy)); 175 } 176 177 _MTL_INLINE void MTL::SamplerDescriptor::setMaxAnisotropy(NS::UInteger maxAnisotropy) 178 { 179 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMaxAnisotropy_), maxAnisotropy); 180 } 181 182 // property: sAddressMode 183 _MTL_INLINE MTL::SamplerAddressMode MTL::SamplerDescriptor::sAddressMode() const 184 { 185 return Object::sendMessage<MTL::SamplerAddressMode>(this, _MTL_PRIVATE_SEL(sAddressMode)); 186 } 187 188 _MTL_INLINE void MTL::SamplerDescriptor::setSAddressMode(MTL::SamplerAddressMode sAddressMode) 189 { 190 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSAddressMode_), sAddressMode); 191 } 192 193 // property: tAddressMode 194 _MTL_INLINE MTL::SamplerAddressMode MTL::SamplerDescriptor::tAddressMode() const 195 { 196 return Object::sendMessage<MTL::SamplerAddressMode>(this, _MTL_PRIVATE_SEL(tAddressMode)); 197 } 198 199 _MTL_INLINE void MTL::SamplerDescriptor::setTAddressMode(MTL::SamplerAddressMode tAddressMode) 200 { 201 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setTAddressMode_), tAddressMode); 202 } 203 204 // property: rAddressMode 205 _MTL_INLINE MTL::SamplerAddressMode MTL::SamplerDescriptor::rAddressMode() const 206 { 207 return Object::sendMessage<MTL::SamplerAddressMode>(this, _MTL_PRIVATE_SEL(rAddressMode)); 208 } 209 210 _MTL_INLINE void MTL::SamplerDescriptor::setRAddressMode(MTL::SamplerAddressMode rAddressMode) 211 { 212 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setRAddressMode_), rAddressMode); 213 } 214 215 // property: borderColor 216 _MTL_INLINE MTL::SamplerBorderColor MTL::SamplerDescriptor::borderColor() const 217 { 218 return Object::sendMessage<MTL::SamplerBorderColor>(this, _MTL_PRIVATE_SEL(borderColor)); 219 } 220 221 _MTL_INLINE void MTL::SamplerDescriptor::setBorderColor(MTL::SamplerBorderColor borderColor) 222 { 223 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setBorderColor_), borderColor); 224 } 225 226 // property: normalizedCoordinates 227 _MTL_INLINE bool MTL::SamplerDescriptor::normalizedCoordinates() const 228 { 229 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(normalizedCoordinates)); 230 } 231 232 _MTL_INLINE void MTL::SamplerDescriptor::setNormalizedCoordinates(bool normalizedCoordinates) 233 { 234 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setNormalizedCoordinates_), normalizedCoordinates); 235 } 236 237 // property: lodMinClamp 238 _MTL_INLINE float MTL::SamplerDescriptor::lodMinClamp() const 239 { 240 return Object::sendMessage<float>(this, _MTL_PRIVATE_SEL(lodMinClamp)); 241 } 242 243 _MTL_INLINE void MTL::SamplerDescriptor::setLodMinClamp(float lodMinClamp) 244 { 245 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLodMinClamp_), lodMinClamp); 246 } 247 248 // property: lodMaxClamp 249 _MTL_INLINE float MTL::SamplerDescriptor::lodMaxClamp() const 250 { 251 return Object::sendMessage<float>(this, _MTL_PRIVATE_SEL(lodMaxClamp)); 252 } 253 254 _MTL_INLINE void MTL::SamplerDescriptor::setLodMaxClamp(float lodMaxClamp) 255 { 256 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLodMaxClamp_), lodMaxClamp); 257 } 258 259 // property: lodAverage 260 _MTL_INLINE bool MTL::SamplerDescriptor::lodAverage() const 261 { 262 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(lodAverage)); 263 } 264 265 _MTL_INLINE void MTL::SamplerDescriptor::setLodAverage(bool lodAverage) 266 { 267 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLodAverage_), lodAverage); 268 } 269 270 // property: compareFunction 271 _MTL_INLINE MTL::CompareFunction MTL::SamplerDescriptor::compareFunction() const 272 { 273 return Object::sendMessage<MTL::CompareFunction>(this, _MTL_PRIVATE_SEL(compareFunction)); 274 } 275 276 _MTL_INLINE void MTL::SamplerDescriptor::setCompareFunction(MTL::CompareFunction compareFunction) 277 { 278 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setCompareFunction_), compareFunction); 279 } 280 281 // property: supportArgumentBuffers 282 _MTL_INLINE bool MTL::SamplerDescriptor::supportArgumentBuffers() const 283 { 284 return Object::sendMessageSafe<bool>(this, _MTL_PRIVATE_SEL(supportArgumentBuffers)); 285 } 286 287 _MTL_INLINE void MTL::SamplerDescriptor::setSupportArgumentBuffers(bool supportArgumentBuffers) 288 { 289 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSupportArgumentBuffers_), supportArgumentBuffers); 290 } 291 292 // property: label 293 _MTL_INLINE NS::String* MTL::SamplerDescriptor::label() const 294 { 295 return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label)); 296 } 297 298 _MTL_INLINE void MTL::SamplerDescriptor::setLabel(const NS::String* label) 299 { 300 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLabel_), label); 301 } 302 303 // property: label 304 _MTL_INLINE NS::String* MTL::SamplerState::label() const 305 { 306 return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label)); 307 } 308 309 // property: device 310 _MTL_INLINE MTL::Device* MTL::SamplerState::device() const 311 { 312 return Object::sendMessage<MTL::Device*>(this, _MTL_PRIVATE_SEL(device)); 313 } 314 315 // property: gpuResourceID 316 _MTL_INLINE MTL::ResourceID MTL::SamplerState::gpuResourceID() const 317 { 318 return Object::sendMessage<MTL::ResourceID>(this, _MTL_PRIVATE_SEL(gpuResourceID)); 319 }