objc2-metal 0.3.2

Bindings to the Metal framework
Documentation
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlclearcolor?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MTLClearColor {
    pub red: c_double,
    pub green: c_double,
    pub blue: c_double,
    pub alpha: c_double,
}

unsafe impl Encode for MTLClearColor {
    const ENCODING: Encoding = Encoding::Struct(
        "?",
        &[
            <c_double>::ENCODING,
            <c_double>::ENCODING,
            <c_double>::ENCODING,
            <c_double>::ENCODING,
        ],
    );
}

unsafe impl RefEncode for MTLClearColor {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

impl MTLClearColor {
    // TODO: pub fn MTLClearColorMake(red: c_double,green: c_double,blue: c_double,alpha: c_double,) -> MTLClearColor;
}

/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlloadaction?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTLLoadAction(pub NSUInteger);
impl MTLLoadAction {
    #[doc(alias = "MTLLoadActionDontCare")]
    pub const DontCare: Self = Self(0);
    #[doc(alias = "MTLLoadActionLoad")]
    pub const Load: Self = Self(1);
    #[doc(alias = "MTLLoadActionClear")]
    pub const Clear: Self = Self(2);
}

unsafe impl Encode for MTLLoadAction {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for MTLLoadAction {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlstoreaction?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTLStoreAction(pub NSUInteger);
impl MTLStoreAction {
    #[doc(alias = "MTLStoreActionDontCare")]
    pub const DontCare: Self = Self(0);
    #[doc(alias = "MTLStoreActionStore")]
    pub const Store: Self = Self(1);
    #[doc(alias = "MTLStoreActionMultisampleResolve")]
    pub const MultisampleResolve: Self = Self(2);
    #[doc(alias = "MTLStoreActionStoreAndMultisampleResolve")]
    pub const StoreAndMultisampleResolve: Self = Self(3);
    #[doc(alias = "MTLStoreActionUnknown")]
    pub const Unknown: Self = Self(4);
    #[doc(alias = "MTLStoreActionCustomSampleDepthStore")]
    pub const CustomSampleDepthStore: Self = Self(5);
}

unsafe impl Encode for MTLStoreAction {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for MTLStoreAction {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlstoreactionoptions?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTLStoreActionOptions(pub NSUInteger);
bitflags::bitflags! {
    impl MTLStoreActionOptions: NSUInteger {
        #[doc(alias = "MTLStoreActionOptionNone")]
        const None = 0;
        #[doc(alias = "MTLStoreActionOptionCustomSamplePositions")]
        const CustomSamplePositions = 1<<0;
    }
}

unsafe impl Encode for MTLStoreActionOptions {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for MTLStoreActionOptions {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// This enumeration controls if Metal accumulates visibility results between render encoders or resets them.
///
/// You can specify this property for ``MTLRenderCommandEncoders`` and for ``MTL4RenderCommandEncoders`` through
/// their descriptors' ``MTLRenderCommandEncoder/visibilityResultType`` and ``MTL4RenderCommandEncoder/visibilityResultType``
/// methods.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlvisibilityresulttype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTLVisibilityResultType(pub NSInteger);
impl MTLVisibilityResultType {
    /// Reset visibility result data when you create a render command encoder.
    #[doc(alias = "MTLVisibilityResultTypeReset")]
    pub const Reset: Self = Self(0);
    /// Accumulate visibility results data across multiple render passes.
    #[doc(alias = "MTLVisibilityResultTypeAccumulate")]
    pub const Accumulate: Self = Self(1);
}

unsafe impl Encode for MTLVisibilityResultType {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for MTLVisibilityResultType {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlrenderpassattachmentdescriptor?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct MTLRenderPassAttachmentDescriptor;
);

extern_conformance!(
    unsafe impl NSCopying for MTLRenderPassAttachmentDescriptor {}
);

unsafe impl CopyingHelper for MTLRenderPassAttachmentDescriptor {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for MTLRenderPassAttachmentDescriptor {}
);

impl MTLRenderPassAttachmentDescriptor {
    extern_methods!(
        #[cfg(all(
            feature = "MTLAllocation",
            feature = "MTLResource",
            feature = "MTLTexture"
        ))]
        /// The MTLTexture object for this attachment.
        #[unsafe(method(texture))]
        #[unsafe(method_family = none)]
        pub fn texture(&self) -> Option<Retained<ProtocolObject<dyn MTLTexture>>>;

        #[cfg(all(
            feature = "MTLAllocation",
            feature = "MTLResource",
            feature = "MTLTexture"
        ))]
        /// Setter for [`texture`][Self::texture].
        #[unsafe(method(setTexture:))]
        #[unsafe(method_family = none)]
        pub fn setTexture(&self, texture: Option<&ProtocolObject<dyn MTLTexture>>);

        /// The mipmap level of the texture to be used for rendering.  Default is zero.
        #[unsafe(method(level))]
        #[unsafe(method_family = none)]
        pub fn level(&self) -> NSUInteger;

        /// Setter for [`level`][Self::level].
        #[unsafe(method(setLevel:))]
        #[unsafe(method_family = none)]
        pub fn setLevel(&self, level: NSUInteger);

        /// The slice of the texture to be used for rendering.  Default is zero.
        #[unsafe(method(slice))]
        #[unsafe(method_family = none)]
        pub fn slice(&self) -> NSUInteger;

        /// Setter for [`slice`][Self::slice].
        #[unsafe(method(setSlice:))]
        #[unsafe(method_family = none)]
        pub fn setSlice(&self, slice: NSUInteger);

        /// The depth plane of the texture to be used for rendering.  Default is zero.
        #[unsafe(method(depthPlane))]
        #[unsafe(method_family = none)]
        pub fn depthPlane(&self) -> NSUInteger;

        /// Setter for [`depthPlane`][Self::depthPlane].
        #[unsafe(method(setDepthPlane:))]
        #[unsafe(method_family = none)]
        pub fn setDepthPlane(&self, depth_plane: NSUInteger);

        #[cfg(all(
            feature = "MTLAllocation",
            feature = "MTLResource",
            feature = "MTLTexture"
        ))]
        /// The texture used for multisample resolve operations.  Only used (and required)
        /// if the store action is set to MTLStoreActionMultisampleResolve.
        #[unsafe(method(resolveTexture))]
        #[unsafe(method_family = none)]
        pub fn resolveTexture(&self) -> Option<Retained<ProtocolObject<dyn MTLTexture>>>;

        #[cfg(all(
            feature = "MTLAllocation",
            feature = "MTLResource",
            feature = "MTLTexture"
        ))]
        /// Setter for [`resolveTexture`][Self::resolveTexture].
        #[unsafe(method(setResolveTexture:))]
        #[unsafe(method_family = none)]
        pub fn setResolveTexture(&self, resolve_texture: Option<&ProtocolObject<dyn MTLTexture>>);

        /// The mipmap level of the resolve texture to be used for multisample resolve.  Defaults to zero.
        #[unsafe(method(resolveLevel))]
        #[unsafe(method_family = none)]
        pub fn resolveLevel(&self) -> NSUInteger;

        /// Setter for [`resolveLevel`][Self::resolveLevel].
        #[unsafe(method(setResolveLevel:))]
        #[unsafe(method_family = none)]
        pub fn setResolveLevel(&self, resolve_level: NSUInteger);

        /// The texture slice of the resolve texture to be used for multisample resolve.  Defaults to zero.
        #[unsafe(method(resolveSlice))]
        #[unsafe(method_family = none)]
        pub fn resolveSlice(&self) -> NSUInteger;

        /// Setter for [`resolveSlice`][Self::resolveSlice].
        #[unsafe(method(setResolveSlice:))]
        #[unsafe(method_family = none)]
        pub fn setResolveSlice(&self, resolve_slice: NSUInteger);

        /// The texture depth plane of the resolve texture to be used for multisample resolve.  Defaults to zero.
        #[unsafe(method(resolveDepthPlane))]
        #[unsafe(method_family = none)]
        pub fn resolveDepthPlane(&self) -> NSUInteger;

        /// Setter for [`resolveDepthPlane`][Self::resolveDepthPlane].
        #[unsafe(method(setResolveDepthPlane:))]
        #[unsafe(method_family = none)]
        pub fn setResolveDepthPlane(&self, resolve_depth_plane: NSUInteger);

        /// The action to be performed with this attachment at the beginning of a render pass.  Default is
        /// MTLLoadActionDontCare unless specified by a creation or init method.
        #[unsafe(method(loadAction))]
        #[unsafe(method_family = none)]
        pub fn loadAction(&self) -> MTLLoadAction;

        /// Setter for [`loadAction`][Self::loadAction].
        #[unsafe(method(setLoadAction:))]
        #[unsafe(method_family = none)]
        pub fn setLoadAction(&self, load_action: MTLLoadAction);

        /// The action to be performed with this attachment at the end of a render pass.  Default is
        /// MTLStoreActionDontCare unless specified by a creation or init method.
        #[unsafe(method(storeAction))]
        #[unsafe(method_family = none)]
        pub fn storeAction(&self) -> MTLStoreAction;

        /// Setter for [`storeAction`][Self::storeAction].
        #[unsafe(method(setStoreAction:))]
        #[unsafe(method_family = none)]
        pub fn setStoreAction(&self, store_action: MTLStoreAction);

        /// Optional configuration for the store action performed with this attachment at the end of a render pass.  Default is
        /// MTLStoreActionOptionNone.
        #[unsafe(method(storeActionOptions))]
        #[unsafe(method_family = none)]
        pub fn storeActionOptions(&self) -> MTLStoreActionOptions;

        /// Setter for [`storeActionOptions`][Self::storeActionOptions].
        #[unsafe(method(setStoreActionOptions:))]
        #[unsafe(method_family = none)]
        pub fn setStoreActionOptions(&self, store_action_options: MTLStoreActionOptions);
    );
}

/// Methods declared on superclass `NSObject`.
impl MTLRenderPassAttachmentDescriptor {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for MTLRenderPassAttachmentDescriptor {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlrenderpasscolorattachmentdescriptor?language=objc)
    #[unsafe(super(MTLRenderPassAttachmentDescriptor, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct MTLRenderPassColorAttachmentDescriptor;
);

extern_conformance!(
    unsafe impl NSCopying for MTLRenderPassColorAttachmentDescriptor {}
);

unsafe impl CopyingHelper for MTLRenderPassColorAttachmentDescriptor {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for MTLRenderPassColorAttachmentDescriptor {}
);

impl MTLRenderPassColorAttachmentDescriptor {
    extern_methods!(
        /// The clear color to be used if the loadAction property is MTLLoadActionClear
        #[unsafe(method(clearColor))]
        #[unsafe(method_family = none)]
        pub fn clearColor(&self) -> MTLClearColor;

        /// Setter for [`clearColor`][Self::clearColor].
        #[unsafe(method(setClearColor:))]
        #[unsafe(method_family = none)]
        pub fn setClearColor(&self, clear_color: MTLClearColor);
    );
}

/// Methods declared on superclass `NSObject`.
impl MTLRenderPassColorAttachmentDescriptor {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for MTLRenderPassColorAttachmentDescriptor {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

/// Controls the MSAA depth resolve operation. Supported on iOS GPU Family 3 and later.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlmultisampledepthresolvefilter?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTLMultisampleDepthResolveFilter(pub NSUInteger);
impl MTLMultisampleDepthResolveFilter {
    #[doc(alias = "MTLMultisampleDepthResolveFilterSample0")]
    pub const Sample0: Self = Self(0);
    #[doc(alias = "MTLMultisampleDepthResolveFilterMin")]
    pub const Min: Self = Self(1);
    #[doc(alias = "MTLMultisampleDepthResolveFilterMax")]
    pub const Max: Self = Self(2);
}

unsafe impl Encode for MTLMultisampleDepthResolveFilter {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for MTLMultisampleDepthResolveFilter {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlrenderpassdepthattachmentdescriptor?language=objc)
    #[unsafe(super(MTLRenderPassAttachmentDescriptor, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct MTLRenderPassDepthAttachmentDescriptor;
);

extern_conformance!(
    unsafe impl NSCopying for MTLRenderPassDepthAttachmentDescriptor {}
);

unsafe impl CopyingHelper for MTLRenderPassDepthAttachmentDescriptor {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for MTLRenderPassDepthAttachmentDescriptor {}
);

impl MTLRenderPassDepthAttachmentDescriptor {
    extern_methods!(
        /// The clear depth value to be used if the loadAction property is MTLLoadActionClear
        #[unsafe(method(clearDepth))]
        #[unsafe(method_family = none)]
        pub fn clearDepth(&self) -> c_double;

        /// Setter for [`clearDepth`][Self::clearDepth].
        #[unsafe(method(setClearDepth:))]
        #[unsafe(method_family = none)]
        pub fn setClearDepth(&self, clear_depth: c_double);

        /// The filter to be used for depth multisample resolve.  Defaults to MTLMultisampleDepthResolveFilterSample0.
        #[unsafe(method(depthResolveFilter))]
        #[unsafe(method_family = none)]
        pub fn depthResolveFilter(&self) -> MTLMultisampleDepthResolveFilter;

        /// Setter for [`depthResolveFilter`][Self::depthResolveFilter].
        #[unsafe(method(setDepthResolveFilter:))]
        #[unsafe(method_family = none)]
        pub fn setDepthResolveFilter(&self, depth_resolve_filter: MTLMultisampleDepthResolveFilter);
    );
}

/// Methods declared on superclass `NSObject`.
impl MTLRenderPassDepthAttachmentDescriptor {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for MTLRenderPassDepthAttachmentDescriptor {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

/// Controls the MSAA stencil resolve operation.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlmultisamplestencilresolvefilter?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTLMultisampleStencilResolveFilter(pub NSUInteger);
impl MTLMultisampleStencilResolveFilter {
    /// The stencil sample corresponding to sample 0. This is the default behavior.
    #[doc(alias = "MTLMultisampleStencilResolveFilterSample0")]
    pub const Sample0: Self = Self(0);
    /// The stencil sample corresponding to whichever depth sample is selected by the depth resolve filter. If depth resolve is not enabled, the stencil sample is chosen based on what a depth resolve filter would have selected.
    #[doc(alias = "MTLMultisampleStencilResolveFilterDepthResolvedSample")]
    pub const DepthResolvedSample: Self = Self(1);
}

unsafe impl Encode for MTLMultisampleStencilResolveFilter {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for MTLMultisampleStencilResolveFilter {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlrenderpassstencilattachmentdescriptor?language=objc)
    #[unsafe(super(MTLRenderPassAttachmentDescriptor, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct MTLRenderPassStencilAttachmentDescriptor;
);

extern_conformance!(
    unsafe impl NSCopying for MTLRenderPassStencilAttachmentDescriptor {}
);

unsafe impl CopyingHelper for MTLRenderPassStencilAttachmentDescriptor {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for MTLRenderPassStencilAttachmentDescriptor {}
);

impl MTLRenderPassStencilAttachmentDescriptor {
    extern_methods!(
        /// The clear stencil value to be used if the loadAction property is MTLLoadActionClear
        #[unsafe(method(clearStencil))]
        #[unsafe(method_family = none)]
        pub fn clearStencil(&self) -> u32;

        /// Setter for [`clearStencil`][Self::clearStencil].
        #[unsafe(method(setClearStencil:))]
        #[unsafe(method_family = none)]
        pub fn setClearStencil(&self, clear_stencil: u32);

        /// The filter to be used for stencil multisample resolve. Defaults to MTLMultisampleStencilResolveFilterSample0.
        #[unsafe(method(stencilResolveFilter))]
        #[unsafe(method_family = none)]
        pub fn stencilResolveFilter(&self) -> MTLMultisampleStencilResolveFilter;

        /// Setter for [`stencilResolveFilter`][Self::stencilResolveFilter].
        #[unsafe(method(setStencilResolveFilter:))]
        #[unsafe(method_family = none)]
        pub fn setStencilResolveFilter(
            &self,
            stencil_resolve_filter: MTLMultisampleStencilResolveFilter,
        );
    );
}

/// Methods declared on superclass `NSObject`.
impl MTLRenderPassStencilAttachmentDescriptor {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for MTLRenderPassStencilAttachmentDescriptor {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlrenderpasscolorattachmentdescriptorarray?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct MTLRenderPassColorAttachmentDescriptorArray;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for MTLRenderPassColorAttachmentDescriptorArray {}
);

impl MTLRenderPassColorAttachmentDescriptorArray {
    extern_methods!(
        /// # Safety
        ///
        /// `attachmentIndex` might not be bounds-checked.
        #[unsafe(method(objectAtIndexedSubscript:))]
        #[unsafe(method_family = none)]
        pub unsafe fn objectAtIndexedSubscript(
            &self,
            attachment_index: NSUInteger,
        ) -> Retained<MTLRenderPassColorAttachmentDescriptor>;

        /// # Safety
        ///
        /// `attachmentIndex` might not be bounds-checked.
        #[unsafe(method(setObject:atIndexedSubscript:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setObject_atIndexedSubscript(
            &self,
            attachment: Option<&MTLRenderPassColorAttachmentDescriptor>,
            attachment_index: NSUInteger,
        );
    );
}

/// Methods declared on superclass `NSObject`.
impl MTLRenderPassColorAttachmentDescriptorArray {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for MTLRenderPassColorAttachmentDescriptorArray {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlrenderpasssamplebufferattachmentdescriptor?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct MTLRenderPassSampleBufferAttachmentDescriptor;
);

extern_conformance!(
    unsafe impl NSCopying for MTLRenderPassSampleBufferAttachmentDescriptor {}
);

unsafe impl CopyingHelper for MTLRenderPassSampleBufferAttachmentDescriptor {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for MTLRenderPassSampleBufferAttachmentDescriptor {}
);

impl MTLRenderPassSampleBufferAttachmentDescriptor {
    extern_methods!(
        #[cfg(feature = "MTLCounters")]
        /// The sample buffer to store samples for the render-pass defined samples.
        /// If sampleBuffer is non-nil, the sample indices will be used to store samples into
        /// the sample buffer.  If no sample buffer is provided, no samples will be taken.
        /// If any of the sample indices are specified as MTLCounterDontSample, no sample
        /// will be taken for that action.
        #[unsafe(method(sampleBuffer))]
        #[unsafe(method_family = none)]
        pub fn sampleBuffer(&self) -> Option<Retained<ProtocolObject<dyn MTLCounterSampleBuffer>>>;

        #[cfg(feature = "MTLCounters")]
        /// Setter for [`sampleBuffer`][Self::sampleBuffer].
        #[unsafe(method(setSampleBuffer:))]
        #[unsafe(method_family = none)]
        pub fn setSampleBuffer(
            &self,
            sample_buffer: Option<&ProtocolObject<dyn MTLCounterSampleBuffer>>,
        );

        /// The sample index to use to store the sample taken at the start of
        /// vertex processing.  Setting the value to MTLCounterDontSample will cause
        /// this sample to be omitted.
        ///
        /// On devices where MTLCounterSamplingPointAtStageBoundary is unsupported,
        /// this sample index is invalid and must be set to MTLCounterDontSample or creation of a render pass will fail.
        #[unsafe(method(startOfVertexSampleIndex))]
        #[unsafe(method_family = none)]
        pub fn startOfVertexSampleIndex(&self) -> NSUInteger;

        /// Setter for [`startOfVertexSampleIndex`][Self::startOfVertexSampleIndex].
        ///
        /// # Safety
        ///
        /// This might not be bounds-checked.
        #[unsafe(method(setStartOfVertexSampleIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setStartOfVertexSampleIndex(&self, start_of_vertex_sample_index: NSUInteger);

        /// The sample index to use to store the sample taken at the end of
        /// vertex processing.  Setting the value to MTLCounterDontSample will cause
        /// this sample to be omitted.
        ///
        /// On devices where MTLCounterSamplingPointAtStageBoundary is unsupported,
        /// this sample index is invalid and must be set to MTLCounterDontSample or creation of a render pass will fail.
        #[unsafe(method(endOfVertexSampleIndex))]
        #[unsafe(method_family = none)]
        pub fn endOfVertexSampleIndex(&self) -> NSUInteger;

        /// Setter for [`endOfVertexSampleIndex`][Self::endOfVertexSampleIndex].
        ///
        /// # Safety
        ///
        /// This might not be bounds-checked.
        #[unsafe(method(setEndOfVertexSampleIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setEndOfVertexSampleIndex(&self, end_of_vertex_sample_index: NSUInteger);

        /// The sample index to use to store the sample taken at the start of
        /// fragment processing.  Setting the value to MTLCounterDontSample will cause
        /// this sample to be omitted.
        ///
        /// On devices where MTLCounterSamplingPointAtStageBoundary is unsupported,
        /// this sample index is invalid and must be set to MTLCounterDontSample or creation of a render pass will fail.
        #[unsafe(method(startOfFragmentSampleIndex))]
        #[unsafe(method_family = none)]
        pub fn startOfFragmentSampleIndex(&self) -> NSUInteger;

        /// Setter for [`startOfFragmentSampleIndex`][Self::startOfFragmentSampleIndex].
        ///
        /// # Safety
        ///
        /// This might not be bounds-checked.
        #[unsafe(method(setStartOfFragmentSampleIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setStartOfFragmentSampleIndex(
            &self,
            start_of_fragment_sample_index: NSUInteger,
        );

        /// The sample index to use to store the sample taken at the end of
        /// fragment processing.  Setting the value to MTLCounterDontSample will cause
        /// this sample to be omitted.
        ///
        /// On devices where MTLCounterSamplingPointAtStageBoundary is unsupported,
        /// this sample index is invalid and must be set to MTLCounterDontSample or creation of a render pass will fail.
        #[unsafe(method(endOfFragmentSampleIndex))]
        #[unsafe(method_family = none)]
        pub fn endOfFragmentSampleIndex(&self) -> NSUInteger;

        /// Setter for [`endOfFragmentSampleIndex`][Self::endOfFragmentSampleIndex].
        ///
        /// # Safety
        ///
        /// This might not be bounds-checked.
        #[unsafe(method(setEndOfFragmentSampleIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setEndOfFragmentSampleIndex(&self, end_of_fragment_sample_index: NSUInteger);
    );
}

/// Methods declared on superclass `NSObject`.
impl MTLRenderPassSampleBufferAttachmentDescriptor {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for MTLRenderPassSampleBufferAttachmentDescriptor {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlrenderpasssamplebufferattachmentdescriptorarray?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct MTLRenderPassSampleBufferAttachmentDescriptorArray;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for MTLRenderPassSampleBufferAttachmentDescriptorArray {}
);

impl MTLRenderPassSampleBufferAttachmentDescriptorArray {
    extern_methods!(
        /// # Safety
        ///
        /// `attachmentIndex` might not be bounds-checked.
        #[unsafe(method(objectAtIndexedSubscript:))]
        #[unsafe(method_family = none)]
        pub unsafe fn objectAtIndexedSubscript(
            &self,
            attachment_index: NSUInteger,
        ) -> Retained<MTLRenderPassSampleBufferAttachmentDescriptor>;

        /// # Safety
        ///
        /// `attachmentIndex` might not be bounds-checked.
        #[unsafe(method(setObject:atIndexedSubscript:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setObject_atIndexedSubscript(
            &self,
            attachment: Option<&MTLRenderPassSampleBufferAttachmentDescriptor>,
            attachment_index: NSUInteger,
        );
    );
}

/// Methods declared on superclass `NSObject`.
impl MTLRenderPassSampleBufferAttachmentDescriptorArray {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for MTLRenderPassSampleBufferAttachmentDescriptorArray {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern_class!(
    /// MTLRenderPassDescriptor represents a collection of attachments to be used to create a concrete render command encoder
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlrenderpassdescriptor?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct MTLRenderPassDescriptor;
);

extern_conformance!(
    unsafe impl NSCopying for MTLRenderPassDescriptor {}
);

unsafe impl CopyingHelper for MTLRenderPassDescriptor {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for MTLRenderPassDescriptor {}
);

impl MTLRenderPassDescriptor {
    extern_methods!(
        /// Create an autoreleased default frame buffer descriptor
        #[unsafe(method(renderPassDescriptor))]
        #[unsafe(method_family = none)]
        pub fn renderPassDescriptor() -> Retained<MTLRenderPassDescriptor>;

        #[unsafe(method(colorAttachments))]
        #[unsafe(method_family = none)]
        pub fn colorAttachments(&self) -> Retained<MTLRenderPassColorAttachmentDescriptorArray>;

        #[unsafe(method(depthAttachment))]
        #[unsafe(method_family = none)]
        pub fn depthAttachment(&self) -> Retained<MTLRenderPassDepthAttachmentDescriptor>;

        /// Setter for [`depthAttachment`][Self::depthAttachment].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setDepthAttachment:))]
        #[unsafe(method_family = none)]
        pub fn setDepthAttachment(
            &self,
            depth_attachment: Option<&MTLRenderPassDepthAttachmentDescriptor>,
        );

        #[unsafe(method(stencilAttachment))]
        #[unsafe(method_family = none)]
        pub fn stencilAttachment(&self) -> Retained<MTLRenderPassStencilAttachmentDescriptor>;

        /// Setter for [`stencilAttachment`][Self::stencilAttachment].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setStencilAttachment:))]
        #[unsafe(method_family = none)]
        pub fn setStencilAttachment(
            &self,
            stencil_attachment: Option<&MTLRenderPassStencilAttachmentDescriptor>,
        );

        #[cfg(all(
            feature = "MTLAllocation",
            feature = "MTLBuffer",
            feature = "MTLResource"
        ))]
        /// Buffer into which samples passing the depth and stencil tests are counted.
        #[unsafe(method(visibilityResultBuffer))]
        #[unsafe(method_family = none)]
        pub fn visibilityResultBuffer(&self) -> Option<Retained<ProtocolObject<dyn MTLBuffer>>>;

        #[cfg(all(
            feature = "MTLAllocation",
            feature = "MTLBuffer",
            feature = "MTLResource"
        ))]
        /// Setter for [`visibilityResultBuffer`][Self::visibilityResultBuffer].
        #[unsafe(method(setVisibilityResultBuffer:))]
        #[unsafe(method_family = none)]
        pub fn setVisibilityResultBuffer(
            &self,
            visibility_result_buffer: Option<&ProtocolObject<dyn MTLBuffer>>,
        );

        /// The number of active layers
        #[unsafe(method(renderTargetArrayLength))]
        #[unsafe(method_family = none)]
        pub fn renderTargetArrayLength(&self) -> NSUInteger;

        /// Setter for [`renderTargetArrayLength`][Self::renderTargetArrayLength].
        #[unsafe(method(setRenderTargetArrayLength:))]
        #[unsafe(method_family = none)]
        pub fn setRenderTargetArrayLength(&self, render_target_array_length: NSUInteger);

        /// The per sample size in bytes of the largest explicit imageblock layout in the renderPass.
        #[unsafe(method(imageblockSampleLength))]
        #[unsafe(method_family = none)]
        pub fn imageblockSampleLength(&self) -> NSUInteger;

        /// Setter for [`imageblockSampleLength`][Self::imageblockSampleLength].
        #[unsafe(method(setImageblockSampleLength:))]
        #[unsafe(method_family = none)]
        pub fn setImageblockSampleLength(&self, imageblock_sample_length: NSUInteger);

        /// The per tile size in bytes of the persistent threadgroup memory allocation.
        #[unsafe(method(threadgroupMemoryLength))]
        #[unsafe(method_family = none)]
        pub fn threadgroupMemoryLength(&self) -> NSUInteger;

        /// Setter for [`threadgroupMemoryLength`][Self::threadgroupMemoryLength].
        #[unsafe(method(setThreadgroupMemoryLength:))]
        #[unsafe(method_family = none)]
        pub fn setThreadgroupMemoryLength(&self, threadgroup_memory_length: NSUInteger);

        /// The width in pixels of the tile.
        ///
        /// Defaults to 0. Zero means Metal chooses a width that fits within the local memory.
        #[unsafe(method(tileWidth))]
        #[unsafe(method_family = none)]
        pub fn tileWidth(&self) -> NSUInteger;

        /// Setter for [`tileWidth`][Self::tileWidth].
        #[unsafe(method(setTileWidth:))]
        #[unsafe(method_family = none)]
        pub fn setTileWidth(&self, tile_width: NSUInteger);

        /// The height in pixels of the tile.
        ///
        /// Defaults to 0. Zero means Metal chooses a height that fits within the local memory.
        #[unsafe(method(tileHeight))]
        #[unsafe(method_family = none)]
        pub fn tileHeight(&self) -> NSUInteger;

        /// Setter for [`tileHeight`][Self::tileHeight].
        #[unsafe(method(setTileHeight:))]
        #[unsafe(method_family = none)]
        pub fn setTileHeight(&self, tile_height: NSUInteger);

        /// The raster sample count for the render pass when no attachments are given.
        #[unsafe(method(defaultRasterSampleCount))]
        #[unsafe(method_family = none)]
        pub fn defaultRasterSampleCount(&self) -> NSUInteger;

        /// Setter for [`defaultRasterSampleCount`][Self::defaultRasterSampleCount].
        #[unsafe(method(setDefaultRasterSampleCount:))]
        #[unsafe(method_family = none)]
        pub fn setDefaultRasterSampleCount(&self, default_raster_sample_count: NSUInteger);

        /// The width in pixels to constrain the render target to.
        ///
        /// Defaults to 0. If non-zero the value must be smaller than or equal to the minimum width of all attachments.
        #[unsafe(method(renderTargetWidth))]
        #[unsafe(method_family = none)]
        pub fn renderTargetWidth(&self) -> NSUInteger;

        /// Setter for [`renderTargetWidth`][Self::renderTargetWidth].
        #[unsafe(method(setRenderTargetWidth:))]
        #[unsafe(method_family = none)]
        pub fn setRenderTargetWidth(&self, render_target_width: NSUInteger);

        /// The height in pixels to constrain the render target to.
        ///
        /// Defaults to 0. If non-zero the value must be smaller than or equal to the minimum height of all attachments.
        #[unsafe(method(renderTargetHeight))]
        #[unsafe(method_family = none)]
        pub fn renderTargetHeight(&self) -> NSUInteger;

        /// Setter for [`renderTargetHeight`][Self::renderTargetHeight].
        #[unsafe(method(setRenderTargetHeight:))]
        #[unsafe(method_family = none)]
        pub fn setRenderTargetHeight(&self, render_target_height: NSUInteger);

        #[cfg(feature = "MTLTypes")]
        /// Configure the custom sample positions, to be used in MSAA rendering (i.e. when sample count > 1).
        ///
        /// Parameter `positions`: The source array for custom sample position data.
        ///
        /// Parameter `count`: Specifies the length of the positions array, and must be a valid sample count or 0 (to disable custom sample positions).
        ///
        /// # Safety
        ///
        /// - `positions` must be a valid pointer or null.
        /// - `count` might not be bounds-checked.
        #[unsafe(method(setSamplePositions:count:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setSamplePositions_count(
            &self,
            positions: *const MTLSamplePosition,
            count: NSUInteger,
        );

        #[cfg(feature = "MTLTypes")]
        /// Retrieve the previously configured custom sample positions. The positions input array will only be modified when count specifies a length sufficient for the number of previously configured positions.
        ///
        /// Parameter `positions`: The destination array for custom sample position data.
        ///
        /// Parameter `count`: Specifies the length of the positions array, which must be large enough to hold all configured sample positions.
        ///
        /// Returns: The number of previously configured custom sample positions.
        ///
        /// # Safety
        ///
        /// - `positions` must be a valid pointer or null.
        /// - `count` might not be bounds-checked.
        #[unsafe(method(getSamplePositions:count:))]
        #[unsafe(method_family = none)]
        pub unsafe fn getSamplePositions_count(
            &self,
            positions: *mut MTLSamplePosition,
            count: NSUInteger,
        ) -> NSUInteger;

        #[cfg(feature = "MTLRasterizationRate")]
        /// The variable rasterization rate map to use when rendering this pass, or nil to not use variable rasterization rate.
        ///
        /// The default value is nil. Enabling variable rasterization rate allows for decreasing the rasterization rate in unimportant regions of screen space.
        #[unsafe(method(rasterizationRateMap))]
        #[unsafe(method_family = none)]
        pub fn rasterizationRateMap(
            &self,
        ) -> Option<Retained<ProtocolObject<dyn MTLRasterizationRateMap>>>;

        #[cfg(feature = "MTLRasterizationRate")]
        /// Setter for [`rasterizationRateMap`][Self::rasterizationRateMap].
        #[unsafe(method(setRasterizationRateMap:))]
        #[unsafe(method_family = none)]
        pub fn setRasterizationRateMap(
            &self,
            rasterization_rate_map: Option<&ProtocolObject<dyn MTLRasterizationRateMap>>,
        );

        /// An array of sample buffers and associated sample indices.
        #[unsafe(method(sampleBufferAttachments))]
        #[unsafe(method_family = none)]
        pub fn sampleBufferAttachments(
            &self,
        ) -> Retained<MTLRenderPassSampleBufferAttachmentDescriptorArray>;

        /// Specifies if Metal accumulates visibility results between render encoders or resets them.
        #[unsafe(method(visibilityResultType))]
        #[unsafe(method_family = none)]
        pub fn visibilityResultType(&self) -> MTLVisibilityResultType;

        /// Setter for [`visibilityResultType`][Self::visibilityResultType].
        #[unsafe(method(setVisibilityResultType:))]
        #[unsafe(method_family = none)]
        pub fn setVisibilityResultType(&self, visibility_result_type: MTLVisibilityResultType);

        /// Specifies if the render pass should support color attachment mapping.
        #[unsafe(method(supportColorAttachmentMapping))]
        #[unsafe(method_family = none)]
        pub fn supportColorAttachmentMapping(&self) -> bool;

        /// Setter for [`supportColorAttachmentMapping`][Self::supportColorAttachmentMapping].
        #[unsafe(method(setSupportColorAttachmentMapping:))]
        #[unsafe(method_family = none)]
        pub fn setSupportColorAttachmentMapping(&self, support_color_attachment_mapping: bool);
    );
}

/// Methods declared on superclass `NSObject`.
impl MTLRenderPassDescriptor {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for MTLRenderPassDescriptor {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

impl MTLClearColor {
    // TODO: pub fn MTLClearColorMake(red: c_double,green: c_double,blue: c_double,alpha: c_double,) -> MTLClearColor;
}