Debian Codegraph @

third_party/rust/metal/src/vertexdescriptor.rs

raw
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::NSUInteger;
9
10 /// See <https://developer.apple.com/documentation/metal/mtlvertexformat>
11 #[repr(u64)]
12 #[allow(non_camel_case_types)]
13 #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
14 pub enum MTLVertexFormat {
15 Invalid = 0,
16 UChar2 = 1,
17 UChar3 = 2,
18 UChar4 = 3,
19 Char2 = 4,
20 Char3 = 5,
21 Char4 = 6,
22 UChar2Normalized = 7,
23 UChar3Normalized = 8,
24 UChar4Normalized = 9,
25 Char2Normalized = 10,
26 Char3Normalized = 11,
27 Char4Normalized = 12,
28 UShort2 = 13,
29 UShort3 = 14,
30 UShort4 = 15,
31 Short2 = 16,
32 Short3 = 17,
33 Short4 = 18,
34 UShort2Normalized = 19,
35 UShort3Normalized = 20,
36 UShort4Normalized = 21,
37 Short2Normalized = 22,
38 Short3Normalized = 23,
39 Short4Normalized = 24,
40 Half2 = 25,
41 Half3 = 26,
42 Half4 = 27,
43 Float = 28,
44 Float2 = 29,
45 Float3 = 30,
46 Float4 = 31,
47 Int = 32,
48 Int2 = 33,
49 Int3 = 34,
50 Int4 = 35,
51 UInt = 36,
52 UInt2 = 37,
53 UInt3 = 38,
54 UInt4 = 39,
55 Int1010102Normalized = 40,
56 UInt1010102Normalized = 41,
57 UChar4Normalized_BGRA = 42,
58 UChar = 45,
59 Char = 46,
60 UCharNormalized = 47,
61 CharNormalized = 48,
62 UShort = 49,
63 Short = 50,
64 UShortNormalized = 51,
65 ShortNormalized = 52,
66 Half = 53,
67 }
68
69 /// See <https://developer.apple.com/documentation/metal/mtlvertexstepfunction>
70 #[repr(u64)]
71 #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
72 pub enum MTLVertexStepFunction {
73 Constant = 0,
74 PerVertex = 1,
75 PerInstance = 2,
76 PerPatch = 3,
77 PerPatchControlPoint = 4,
78 }
79
80 /// See <https://developer.apple.com/documentation/metal/mtlvertexbufferlayoutdescriptor>
81 pub enum MTLVertexBufferLayoutDescriptor {}
82
83 foreign_obj_type! {
84 type CType = MTLVertexBufferLayoutDescriptor;
85 pub struct VertexBufferLayoutDescriptor;
86 }
87
88 impl VertexBufferLayoutDescriptor {
89 pub fn new() -> Self {
90 unsafe {
91 let class = class!(MTLVertexBufferLayoutDescriptor);
92 msg_send![class, new]
93 }
94 }
95 }
96
97 impl VertexBufferLayoutDescriptorRef {
98 pub fn stride(&self) -> NSUInteger {
99 unsafe { msg_send![self, stride] }
100 }
101
102 pub fn set_stride(&self, stride: NSUInteger) {
103 unsafe { msg_send![self, setStride: stride] }
104 }
105
106 pub fn step_function(&self) -> MTLVertexStepFunction {
107 unsafe { msg_send![self, stepFunction] }
108 }
109
110 pub fn set_step_function(&self, func: MTLVertexStepFunction) {
111 unsafe { msg_send![self, setStepFunction: func] }
112 }
113
114 pub fn step_rate(&self) -> NSUInteger {
115 unsafe { msg_send![self, stepRate] }
116 }
117
118 pub fn set_step_rate(&self, step_rate: NSUInteger) {
119 unsafe { msg_send![self, setStepRate: step_rate] }
120 }
121 }
122
123 /// See <https://developer.apple.com/documentation/metal/mtlvertexbufferlayoutdescriptorarray>
124 pub enum MTLVertexBufferLayoutDescriptorArray {}
125
126 foreign_obj_type! {
127 type CType = MTLVertexBufferLayoutDescriptorArray;
128 pub struct VertexBufferLayoutDescriptorArray;
129 }
130
131 impl VertexBufferLayoutDescriptorArrayRef {
132 pub fn object_at(&self, index: NSUInteger) -> Option<&VertexBufferLayoutDescriptorRef> {
133 unsafe { msg_send![self, objectAtIndexedSubscript: index] }
134 }
135
136 pub fn set_object_at(
137 &self,
138 index: NSUInteger,
139 layout: Option<&VertexBufferLayoutDescriptorRef>,
140 ) {
141 unsafe {
142 msg_send![self, setObject:layout
143 atIndexedSubscript:index]
144 }
145 }
146 }
147
148 /// See <https://developer.apple.com/documentation/metal/mtlvertexattributedescriptor>
149 pub enum MTLVertexAttributeDescriptor {}
150
151 foreign_obj_type! {
152 type CType = MTLVertexAttributeDescriptor;
153 pub struct VertexAttributeDescriptor;
154 }
155
156 impl VertexAttributeDescriptor {
157 pub fn new() -> Self {
158 unsafe {
159 let class = class!(MTLVertexAttributeDescriptor);
160 msg_send![class, new]
161 }
162 }
163 }
164
165 impl VertexAttributeDescriptorRef {
166 pub fn format(&self) -> MTLVertexFormat {
167 unsafe { msg_send![self, format] }
168 }
169
170 pub fn set_format(&self, format: MTLVertexFormat) {
171 unsafe { msg_send![self, setFormat: format] }
172 }
173
174 pub fn offset(&self) -> NSUInteger {
175 unsafe { msg_send![self, offset] }
176 }
177
178 pub fn set_offset(&self, offset: NSUInteger) {
179 unsafe { msg_send![self, setOffset: offset] }
180 }
181
182 pub fn buffer_index(&self) -> NSUInteger {
183 unsafe { msg_send![self, bufferIndex] }
184 }
185
186 pub fn set_buffer_index(&self, index: NSUInteger) {
187 unsafe { msg_send![self, setBufferIndex: index] }
188 }
189 }
190
191 /// See <https://developer.apple.com/documentation/metal/mtlvertexattributedescriptorarray>
192 pub enum MTLVertexAttributeDescriptorArray {}
193
194 foreign_obj_type! {
195 type CType = MTLVertexAttributeDescriptorArray;
196 pub struct VertexAttributeDescriptorArray;
197 }
198
199 impl VertexAttributeDescriptorArrayRef {
200 pub fn object_at(&self, index: NSUInteger) -> Option<&VertexAttributeDescriptorRef> {
201 unsafe { msg_send![self, objectAtIndexedSubscript: index] }
202 }
203
204 pub fn set_object_at(
205 &self,
206 index: NSUInteger,
207 attribute: Option<&VertexAttributeDescriptorRef>,
208 ) {
209 unsafe {
210 msg_send![self, setObject:attribute
211 atIndexedSubscript:index]
212 }
213 }
214 }
215
216 /// See <https://developer.apple.com/documentation/metal/mtlvertexdescriptor>
217 pub enum MTLVertexDescriptor {}
218
219 foreign_obj_type! {
220 type CType = MTLVertexDescriptor;
221 pub struct VertexDescriptor;
222 }
223
224 impl VertexDescriptor {
225 pub fn new<'a>() -> &'a VertexDescriptorRef {
226 unsafe {
227 let class = class!(MTLVertexDescriptor);
228 msg_send![class, vertexDescriptor]
229 }
230 }
231 }
232
233 impl VertexDescriptorRef {
234 pub fn layouts(&self) -> &VertexBufferLayoutDescriptorArrayRef {
235 unsafe { msg_send![self, layouts] }
236 }
237
238 pub fn attributes(&self) -> &VertexAttributeDescriptorArrayRef {
239 unsafe { msg_send![self, attributes] }
240 }
241
242 #[cfg(feature = "private")]
243 pub unsafe fn serialize_descriptor(&self) -> *mut std::ffi::c_void {
244 msg_send![self, newSerializedDescriptor]
245 }
246
247 pub fn reset(&self) {
248 unsafe { msg_send![self, reset] }
249 }
250 }