MTLVertexDescriptor.hpp
1 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 2 // 3 // Metal/MTLVertexDescriptor.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 "MTLVertexDescriptor.hpp" 30 31 namespace MTL 32 { 33 34 static const NS::UInteger BufferLayoutStrideDynamic = NS::UIntegerMax; 35 36 _MTL_ENUM(NS::UInteger, VertexFormat) { 37 VertexFormatInvalid = 0, 38 VertexFormatUChar2 = 1, 39 VertexFormatUChar3 = 2, 40 VertexFormatUChar4 = 3, 41 VertexFormatChar2 = 4, 42 VertexFormatChar3 = 5, 43 VertexFormatChar4 = 6, 44 VertexFormatUChar2Normalized = 7, 45 VertexFormatUChar3Normalized = 8, 46 VertexFormatUChar4Normalized = 9, 47 VertexFormatChar2Normalized = 10, 48 VertexFormatChar3Normalized = 11, 49 VertexFormatChar4Normalized = 12, 50 VertexFormatUShort2 = 13, 51 VertexFormatUShort3 = 14, 52 VertexFormatUShort4 = 15, 53 VertexFormatShort2 = 16, 54 VertexFormatShort3 = 17, 55 VertexFormatShort4 = 18, 56 VertexFormatUShort2Normalized = 19, 57 VertexFormatUShort3Normalized = 20, 58 VertexFormatUShort4Normalized = 21, 59 VertexFormatShort2Normalized = 22, 60 VertexFormatShort3Normalized = 23, 61 VertexFormatShort4Normalized = 24, 62 VertexFormatHalf2 = 25, 63 VertexFormatHalf3 = 26, 64 VertexFormatHalf4 = 27, 65 VertexFormatFloat = 28, 66 VertexFormatFloat2 = 29, 67 VertexFormatFloat3 = 30, 68 VertexFormatFloat4 = 31, 69 VertexFormatInt = 32, 70 VertexFormatInt2 = 33, 71 VertexFormatInt3 = 34, 72 VertexFormatInt4 = 35, 73 VertexFormatUInt = 36, 74 VertexFormatUInt2 = 37, 75 VertexFormatUInt3 = 38, 76 VertexFormatUInt4 = 39, 77 VertexFormatInt1010102Normalized = 40, 78 VertexFormatUInt1010102Normalized = 41, 79 VertexFormatUChar4Normalized_BGRA = 42, 80 VertexFormatUChar = 45, 81 VertexFormatChar = 46, 82 VertexFormatUCharNormalized = 47, 83 VertexFormatCharNormalized = 48, 84 VertexFormatUShort = 49, 85 VertexFormatShort = 50, 86 VertexFormatUShortNormalized = 51, 87 VertexFormatShortNormalized = 52, 88 VertexFormatHalf = 53, 89 VertexFormatFloatRG11B10 = 54, 90 VertexFormatFloatRGB9E5 = 55, 91 }; 92 93 _MTL_ENUM(NS::UInteger, VertexStepFunction) { 94 VertexStepFunctionConstant = 0, 95 VertexStepFunctionPerVertex = 1, 96 VertexStepFunctionPerInstance = 2, 97 VertexStepFunctionPerPatch = 3, 98 VertexStepFunctionPerPatchControlPoint = 4, 99 }; 100 101 class VertexBufferLayoutDescriptor : public NS::Copying<VertexBufferLayoutDescriptor> 102 { 103 public: 104 static class VertexBufferLayoutDescriptor* alloc(); 105 106 class VertexBufferLayoutDescriptor* init(); 107 108 NS::UInteger stride() const; 109 void setStride(NS::UInteger stride); 110 111 MTL::VertexStepFunction stepFunction() const; 112 void setStepFunction(MTL::VertexStepFunction stepFunction); 113 114 NS::UInteger stepRate() const; 115 void setStepRate(NS::UInteger stepRate); 116 }; 117 118 class VertexBufferLayoutDescriptorArray : public NS::Referencing<VertexBufferLayoutDescriptorArray> 119 { 120 public: 121 static class VertexBufferLayoutDescriptorArray* alloc(); 122 123 class VertexBufferLayoutDescriptorArray* init(); 124 125 class VertexBufferLayoutDescriptor* object(NS::UInteger index); 126 127 void setObject(const class VertexBufferLayoutDescriptor* bufferDesc, NS::UInteger index); 128 }; 129 130 class VertexAttributeDescriptor : public NS::Copying<VertexAttributeDescriptor> 131 { 132 public: 133 static class VertexAttributeDescriptor* alloc(); 134 135 class VertexAttributeDescriptor* init(); 136 137 MTL::VertexFormat format() const; 138 void setFormat(MTL::VertexFormat format); 139 140 NS::UInteger offset() const; 141 void setOffset(NS::UInteger offset); 142 143 NS::UInteger bufferIndex() const; 144 void setBufferIndex(NS::UInteger bufferIndex); 145 }; 146 147 class VertexAttributeDescriptorArray : public NS::Referencing<VertexAttributeDescriptorArray> 148 { 149 public: 150 static class VertexAttributeDescriptorArray* alloc(); 151 152 class VertexAttributeDescriptorArray* init(); 153 154 class VertexAttributeDescriptor* object(NS::UInteger index); 155 156 void setObject(const class VertexAttributeDescriptor* attributeDesc, NS::UInteger index); 157 }; 158 159 class VertexDescriptor : public NS::Copying<VertexDescriptor> 160 { 161 public: 162 static class VertexDescriptor* alloc(); 163 164 class VertexDescriptor* init(); 165 166 static class VertexDescriptor* vertexDescriptor(); 167 168 class VertexBufferLayoutDescriptorArray* layouts() const; 169 170 class VertexAttributeDescriptorArray* attributes() const; 171 172 void reset(); 173 }; 174 175 } 176 177 // static method: alloc 178 _MTL_INLINE MTL::VertexBufferLayoutDescriptor* MTL::VertexBufferLayoutDescriptor::alloc() 179 { 180 return NS::Object::alloc<MTL::VertexBufferLayoutDescriptor>(_MTL_PRIVATE_CLS(MTLVertexBufferLayoutDescriptor)); 181 } 182 183 // method: init 184 _MTL_INLINE MTL::VertexBufferLayoutDescriptor* MTL::VertexBufferLayoutDescriptor::init() 185 { 186 return NS::Object::init<MTL::VertexBufferLayoutDescriptor>(); 187 } 188 189 // property: stride 190 _MTL_INLINE NS::UInteger MTL::VertexBufferLayoutDescriptor::stride() const 191 { 192 return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(stride)); 193 } 194 195 _MTL_INLINE void MTL::VertexBufferLayoutDescriptor::setStride(NS::UInteger stride) 196 { 197 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setStride_), stride); 198 } 199 200 // property: stepFunction 201 _MTL_INLINE MTL::VertexStepFunction MTL::VertexBufferLayoutDescriptor::stepFunction() const 202 { 203 return Object::sendMessage<MTL::VertexStepFunction>(this, _MTL_PRIVATE_SEL(stepFunction)); 204 } 205 206 _MTL_INLINE void MTL::VertexBufferLayoutDescriptor::setStepFunction(MTL::VertexStepFunction stepFunction) 207 { 208 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setStepFunction_), stepFunction); 209 } 210 211 // property: stepRate 212 _MTL_INLINE NS::UInteger MTL::VertexBufferLayoutDescriptor::stepRate() const 213 { 214 return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(stepRate)); 215 } 216 217 _MTL_INLINE void MTL::VertexBufferLayoutDescriptor::setStepRate(NS::UInteger stepRate) 218 { 219 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setStepRate_), stepRate); 220 } 221 222 // static method: alloc 223 _MTL_INLINE MTL::VertexBufferLayoutDescriptorArray* MTL::VertexBufferLayoutDescriptorArray::alloc() 224 { 225 return NS::Object::alloc<MTL::VertexBufferLayoutDescriptorArray>(_MTL_PRIVATE_CLS(MTLVertexBufferLayoutDescriptorArray)); 226 } 227 228 // method: init 229 _MTL_INLINE MTL::VertexBufferLayoutDescriptorArray* MTL::VertexBufferLayoutDescriptorArray::init() 230 { 231 return NS::Object::init<MTL::VertexBufferLayoutDescriptorArray>(); 232 } 233 234 // method: objectAtIndexedSubscript: 235 _MTL_INLINE MTL::VertexBufferLayoutDescriptor* MTL::VertexBufferLayoutDescriptorArray::object(NS::UInteger index) 236 { 237 return Object::sendMessage<MTL::VertexBufferLayoutDescriptor*>(this, _MTL_PRIVATE_SEL(objectAtIndexedSubscript_), index); 238 } 239 240 // method: setObject:atIndexedSubscript: 241 _MTL_INLINE void MTL::VertexBufferLayoutDescriptorArray::setObject(const MTL::VertexBufferLayoutDescriptor* bufferDesc, NS::UInteger index) 242 { 243 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setObject_atIndexedSubscript_), bufferDesc, index); 244 } 245 246 // static method: alloc 247 _MTL_INLINE MTL::VertexAttributeDescriptor* MTL::VertexAttributeDescriptor::alloc() 248 { 249 return NS::Object::alloc<MTL::VertexAttributeDescriptor>(_MTL_PRIVATE_CLS(MTLVertexAttributeDescriptor)); 250 } 251 252 // method: init 253 _MTL_INLINE MTL::VertexAttributeDescriptor* MTL::VertexAttributeDescriptor::init() 254 { 255 return NS::Object::init<MTL::VertexAttributeDescriptor>(); 256 } 257 258 // property: format 259 _MTL_INLINE MTL::VertexFormat MTL::VertexAttributeDescriptor::format() const 260 { 261 return Object::sendMessage<MTL::VertexFormat>(this, _MTL_PRIVATE_SEL(format)); 262 } 263 264 _MTL_INLINE void MTL::VertexAttributeDescriptor::setFormat(MTL::VertexFormat format) 265 { 266 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setFormat_), format); 267 } 268 269 // property: offset 270 _MTL_INLINE NS::UInteger MTL::VertexAttributeDescriptor::offset() const 271 { 272 return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(offset)); 273 } 274 275 _MTL_INLINE void MTL::VertexAttributeDescriptor::setOffset(NS::UInteger offset) 276 { 277 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setOffset_), offset); 278 } 279 280 // property: bufferIndex 281 _MTL_INLINE NS::UInteger MTL::VertexAttributeDescriptor::bufferIndex() const 282 { 283 return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(bufferIndex)); 284 } 285 286 _MTL_INLINE void MTL::VertexAttributeDescriptor::setBufferIndex(NS::UInteger bufferIndex) 287 { 288 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setBufferIndex_), bufferIndex); 289 } 290 291 // static method: alloc 292 _MTL_INLINE MTL::VertexAttributeDescriptorArray* MTL::VertexAttributeDescriptorArray::alloc() 293 { 294 return NS::Object::alloc<MTL::VertexAttributeDescriptorArray>(_MTL_PRIVATE_CLS(MTLVertexAttributeDescriptorArray)); 295 } 296 297 // method: init 298 _MTL_INLINE MTL::VertexAttributeDescriptorArray* MTL::VertexAttributeDescriptorArray::init() 299 { 300 return NS::Object::init<MTL::VertexAttributeDescriptorArray>(); 301 } 302 303 // method: objectAtIndexedSubscript: 304 _MTL_INLINE MTL::VertexAttributeDescriptor* MTL::VertexAttributeDescriptorArray::object(NS::UInteger index) 305 { 306 return Object::sendMessage<MTL::VertexAttributeDescriptor*>(this, _MTL_PRIVATE_SEL(objectAtIndexedSubscript_), index); 307 } 308 309 // method: setObject:atIndexedSubscript: 310 _MTL_INLINE void MTL::VertexAttributeDescriptorArray::setObject(const MTL::VertexAttributeDescriptor* attributeDesc, NS::UInteger index) 311 { 312 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setObject_atIndexedSubscript_), attributeDesc, index); 313 } 314 315 // static method: alloc 316 _MTL_INLINE MTL::VertexDescriptor* MTL::VertexDescriptor::alloc() 317 { 318 return NS::Object::alloc<MTL::VertexDescriptor>(_MTL_PRIVATE_CLS(MTLVertexDescriptor)); 319 } 320 321 // method: init 322 _MTL_INLINE MTL::VertexDescriptor* MTL::VertexDescriptor::init() 323 { 324 return NS::Object::init<MTL::VertexDescriptor>(); 325 } 326 327 // static method: vertexDescriptor 328 _MTL_INLINE MTL::VertexDescriptor* MTL::VertexDescriptor::vertexDescriptor() 329 { 330 return Object::sendMessage<MTL::VertexDescriptor*>(_MTL_PRIVATE_CLS(MTLVertexDescriptor), _MTL_PRIVATE_SEL(vertexDescriptor)); 331 } 332 333 // property: layouts 334 _MTL_INLINE MTL::VertexBufferLayoutDescriptorArray* MTL::VertexDescriptor::layouts() const 335 { 336 return Object::sendMessage<MTL::VertexBufferLayoutDescriptorArray*>(this, _MTL_PRIVATE_SEL(layouts)); 337 } 338 339 // property: attributes 340 _MTL_INLINE MTL::VertexAttributeDescriptorArray* MTL::VertexDescriptor::attributes() const 341 { 342 return Object::sendMessage<MTL::VertexAttributeDescriptorArray*>(this, _MTL_PRIVATE_SEL(attributes)); 343 } 344 345 // method: reset 346 _MTL_INLINE void MTL::VertexDescriptor::reset() 347 { 348 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(reset)); 349 }