1use crate::import_objc_macros::*;
2use crate::{
3 handle, Array, DeviceCreated, MTLFunction, MTLPixelFormat, NSUInteger, Object, ObjectPointer,
4};
5use enumflags2::BitFlags;
6
7pub struct MTLVertexDescriptor(ObjectPointer);
8handle!(MTLVertexDescriptor);
9
10impl MTLVertexDescriptor {
11 pub unsafe fn new() -> MTLVertexDescriptor {
12 MTLVertexDescriptor::from_ptr(msg_send![class!(MTLVertexDescriptor), new])
13 }
14 }
16
17impl Object for MTLVertexDescriptor {
18 unsafe fn from_ptr(ptr: ObjectPointer) -> Self
19 where
20 Self: Sized,
21 {
22 MTLVertexDescriptor(ptr)
23 }
24
25 fn get_ptr(&self) -> ObjectPointer {
26 self.0
27 }
28}
29
30pub struct MTLRenderPipelineColorAttachmentDescriptorArray(ObjectPointer);
31handle!(MTLRenderPipelineColorAttachmentDescriptorArray);
32
33impl Array<MTLRenderPipelineColorAttachmentDescriptor>
34 for MTLRenderPipelineColorAttachmentDescriptorArray
35{
36}
37
38impl Object for MTLRenderPipelineColorAttachmentDescriptorArray {
39 unsafe fn from_ptr(ptr: ObjectPointer) -> Self
40 where
41 Self: Sized,
42 {
43 MTLRenderPipelineColorAttachmentDescriptorArray(ptr)
44 }
45
46 fn get_ptr(&self) -> ObjectPointer {
47 self.0
48 }
49}
50
51#[derive(BitFlags, Copy, Clone, Debug, PartialEq)]
52#[repr(u64)]
53pub enum MTLColorWriteMask {
54 Red = 0x1 << 3,
55 Green = 0x1 << 2,
56 Blue = 0x1 << 1,
57 Alpha = 0x1,
58}
59
60#[repr(u64)]
61pub enum MTLBlendOperation {
62 Add = 0,
63 Subtract = 1,
64 ReverseSubtract = 2,
65 Min = 3,
66 Max = 4,
67}
68
69#[repr(u64)]
70pub enum MTLBlendFactor {
71 Zero = 0,
72 One = 1,
73 SourceColor = 2,
74 OneMinusSourceColor = 3,
75 SourceAlpha = 4,
76 OneMinusSourceAlpha = 5,
77 DestinationColor = 6,
78 OneMinusDestinationColor = 7,
79 DestinationAlpha = 8,
80 OneMinusDestinationAlpha = 9,
81 SourceAlphaSaturated = 10,
82 BlendColor = 11,
83 OneMinusBlendColor = 12,
84 BlendAlpha = 13,
85 OneMinusBlendAlpha = 14,
86 Source1Color = 15,
87 OneMinusSource1Color = 16,
88 Source1Alpha = 17,
89 OneMinusSource1Alpha = 18,
90}
91
92pub struct MTLRenderPipelineColorAttachmentDescriptor(ObjectPointer);
93handle!(MTLRenderPipelineColorAttachmentDescriptor);
94
95impl MTLRenderPipelineColorAttachmentDescriptor {
96 pub unsafe fn new() -> MTLRenderPipelineColorAttachmentDescriptor {
97 MTLRenderPipelineColorAttachmentDescriptor::from_ptr(msg_send![
98 class!(MTLRenderPipelineColorAttachmentDescriptor),
99 new
100 ])
101 }
102 pub unsafe fn set_write_mask(&self, mask: BitFlags<MTLColorWriteMask>) {
103 msg_send![self.get_ptr(), setWriteMask:mask.bits()]
104 }
105 pub unsafe fn set_pixel_format(&self, format: MTLPixelFormat) {
106 msg_send![self.get_ptr(), setPixelFormat: format]
107 }
108 pub unsafe fn set_blending_enabled(&self, enabled: bool) {
109 msg_send![self.get_ptr(), setBlendingEnabled: enabled]
110 }
111 pub unsafe fn set_alpha_blend_operation(&self, operation: MTLBlendOperation) {
112 msg_send![self.get_ptr(), setAlphaBlendOperation: operation]
113 }
114 pub unsafe fn set_rgb_blend_operation(&self, operation: MTLBlendOperation) {
115 msg_send![self.get_ptr(), setRgbBlendOperation: operation]
116 }
117 pub unsafe fn set_destination_alpha_blend_factor(&self, factor: MTLBlendFactor) {
118 msg_send![self.get_ptr(), setDestinationAlphaBlendFactor: factor]
119 }
120 pub unsafe fn set_destination_rgb_blend_factor(&self, factor: MTLBlendFactor) {
121 msg_send![self.get_ptr(), setDestinationRGBBlendFactor: factor]
122 }
123 pub unsafe fn set_source_alpha_blend_factor(&self, factor: MTLBlendFactor) {
124 msg_send![self.get_ptr(), setSourceAlphaBlendFactor: factor]
125 }
126 pub unsafe fn set_source_rgb_blend_factor(&self, factor: MTLBlendFactor) {
127 msg_send![self.get_ptr(), setSourceRGBBlendFactor: factor]
128 }
129}
130
131impl Object for MTLRenderPipelineColorAttachmentDescriptor {
132 unsafe fn from_ptr(ptr: ObjectPointer) -> Self
133 where
134 Self: Sized,
135 {
136 MTLRenderPipelineColorAttachmentDescriptor(ptr)
137 }
138
139 fn get_ptr(&self) -> ObjectPointer {
140 self.0
141 }
142}
143
144#[repr(u64)]
145pub enum MTLPrimitiveTopologyClass {
146 Unspecified = 0,
147 Point = 1,
148 Line = 2,
149 Triangle = 3,
150}
151
152pub struct MTLRenderPipelineDescriptor(ObjectPointer);
153handle!(MTLRenderPipelineDescriptor);
154
155impl MTLRenderPipelineDescriptor {
156 pub unsafe fn new() -> MTLRenderPipelineDescriptor {
157 MTLRenderPipelineDescriptor::from_ptr({
158 let cl = class!(MTLRenderPipelineDescriptor);
159 msg_send![cl, new]
160 })
161 }
162 pub unsafe fn set_vertex_function(&self, function: &MTLFunction) {
163 msg_send![self.get_ptr(), setVertexFunction:function.get_ptr()]
164 }
165 pub unsafe fn set_fragment_function(&self, function: &MTLFunction) {
166 msg_send![self.get_ptr(), setFragmentFunction:function.get_ptr()]
167 }
168 pub unsafe fn set_vertex_descriptor(&self, desc: &MTLVertexDescriptor) {
169 msg_send![self.get_ptr(), setVertexDescriptor:desc.get_ptr()]
170 }
171 pub unsafe fn get_color_attachments(&self) -> MTLRenderPipelineColorAttachmentDescriptorArray {
172 MTLRenderPipelineColorAttachmentDescriptorArray::from_ptr({
173 let ptr = ObjectPointer(msg_send![self.get_ptr(), colorAttachments]);
174 let _: () = msg_send![ptr, retain];
178 ptr
179 })
180 }
181 pub unsafe fn reset(&self) {
182 msg_send![self.get_ptr(), reset]
183 }
184 pub unsafe fn set_depth_attachment_pixel_format(&self, format: MTLPixelFormat) {
185 msg_send![self.get_ptr(), setDepthAttachmentPixelFormat: format]
186 }
187 pub unsafe fn set_stencil_attachment_pixel_format(&self, format: MTLPixelFormat) {
188 msg_send![self.get_ptr(), setStencilAttachmentPixelFormat: format]
189 }
190 pub unsafe fn set_sample_count(&self, count: NSUInteger) {
191 msg_send![self.get_ptr(), setSampleCount: count]
192 }
193 pub unsafe fn set_alpha_to_coverage_enabled(&self, enabled: bool) {
194 msg_send![self.get_ptr(), setAlphaToCoverageEnabled: enabled]
195 }
196 pub unsafe fn set_alpha_to_one_enabled(&self, enabled: bool) {
197 msg_send![self.get_ptr(), setAlphaToOneEnabled: enabled]
198 }
199 pub unsafe fn set_rasterization_enabled(&self, enabled: bool) {
200 msg_send![self.get_ptr(), setRasteriationEnabled: enabled]
201 }
202 pub unsafe fn set_input_primitive_topology(&self, topology: MTLPrimitiveTopologyClass) {
203 msg_send![self.get_ptr(), setInputPrimitiveTopology: topology]
204 }
205}
206
207impl Object for MTLRenderPipelineDescriptor {
208 unsafe fn from_ptr(ptr: ObjectPointer) -> Self
209 where
210 Self: Sized,
211 {
212 MTLRenderPipelineDescriptor(ptr)
213 }
214
215 fn get_ptr(&self) -> ObjectPointer {
216 self.0
217 }
218}
219
220pub struct MTLRenderPipelineState(ObjectPointer);
221handle!(MTLRenderPipelineState);
222
223impl MTLRenderPipelineState {
224 }
226
227impl DeviceCreated for MTLRenderPipelineState {}
228
229impl Object for MTLRenderPipelineState {
230 unsafe fn from_ptr(ptr: ObjectPointer) -> Self
231 where
232 Self: Sized,
233 {
234 MTLRenderPipelineState(ptr)
235 }
236
237 fn get_ptr(&self) -> ObjectPointer {
238 self.0
239 }
240}