| 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::*; |
| 9 |
|
| 10 |
/// See <https://developer.apple.com/documentation/metal/mtlloadaction> |
| 11 |
#[repr(u64)] |
| 12 |
#[derive(Copy, Clone, Debug)] |
| 13 |
pub enum MTLLoadAction { |
| 14 |
DontCare = 0, |
| 15 |
Load = 1, |
| 16 |
Clear = 2, |
| 17 |
} |
| 18 |
|
| 19 |
/// See <https://developer.apple.com/documentation/metal/mtlstoreaction> |
| 20 |
#[repr(u64)] |
| 21 |
#[derive(Copy, Clone, Debug)] |
| 22 |
pub enum MTLStoreAction { |
| 23 |
DontCare = 0, |
| 24 |
Store = 1, |
| 25 |
MultisampleResolve = 2, |
| 26 |
StoreAndMultisampleResolve = 3, |
| 27 |
Unknown = 4, |
| 28 |
CustomSampleDepthStore = 5, |
| 29 |
} |
| 30 |
|
| 31 |
/// See <https://developer.apple.com/documentation/metal/mtlclearcolor> |
| 32 |
#[repr(C)] |
| 33 |
#[derive(Copy, Clone, Debug)] |
| 34 |
pub struct MTLClearColor { |
| 35 |
pub red: f64, |
| 36 |
pub green: f64, |
| 37 |
pub blue: f64, |
| 38 |
pub alpha: f64, |
| 39 |
} |
| 40 |
|
| 41 |
impl MTLClearColor { |
| 42 |
#[inline] |
| 43 |
pub fn new(red: f64, green: f64, blue: f64, alpha: f64) -> Self { |
| 44 |
Self { |
| 45 |
red, |
| 46 |
green, |
| 47 |
blue, |
| 48 |
alpha, |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
/// See <https://developer.apple.com/documentation/metal/mtlmultisamplestencilresolvefilter> |
| 54 |
#[repr(u32)] |
| 55 |
#[allow(non_camel_case_types)] |
| 56 |
pub enum MTLMultisampleStencilResolveFilter { |
| 57 |
Sample0 = 0, |
| 58 |
DepthResolvedSample = 1, |
| 59 |
} |
| 60 |
|
| 61 |
/// See <https://developer.apple.com/documentation/metal/mtlrenderpassattachmentdescriptor> |
| 62 |
pub enum MTLRenderPassAttachmentDescriptor {} |
| 63 |
|
| 64 |
foreign_obj_type! { |
| 65 |
type CType = MTLRenderPassAttachmentDescriptor; |
| 66 |
pub struct RenderPassAttachmentDescriptor; |
| 67 |
} |
| 68 |
|
| 69 |
impl RenderPassAttachmentDescriptorRef { |
| 70 |
pub fn texture(&self) -> Option<&TextureRef> { |
| 71 |
unsafe { msg_send![self, texture] } |
| 72 |
} |
| 73 |
|
| 74 |
pub fn set_texture(&self, texture: Option<&TextureRef>) { |
| 75 |
unsafe { msg_send![self, setTexture: texture] } |
| 76 |
} |
| 77 |
|
| 78 |
pub fn level(&self) -> NSUInteger { |
| 79 |
unsafe { msg_send![self, level] } |
| 80 |
} |
| 81 |
|
| 82 |
pub fn set_level(&self, level: NSUInteger) { |
| 83 |
unsafe { msg_send![self, setLevel: level] } |
| 84 |
} |
| 85 |
|
| 86 |
pub fn slice(&self) -> NSUInteger { |
| 87 |
unsafe { msg_send![self, slice] } |
| 88 |
} |
| 89 |
|
| 90 |
pub fn set_slice(&self, slice: NSUInteger) { |
| 91 |
unsafe { msg_send![self, setSlice: slice] } |
| 92 |
} |
| 93 |
|
| 94 |
pub fn depth_plane(&self) -> NSUInteger { |
| 95 |
unsafe { msg_send![self, depthPlane] } |
| 96 |
} |
| 97 |
|
| 98 |
pub fn set_depth_plane(&self, depth_plane: NSUInteger) { |
| 99 |
unsafe { msg_send![self, setDepthPlane: depth_plane] } |
| 100 |
} |
| 101 |
|
| 102 |
pub fn resolve_texture(&self) -> Option<&TextureRef> { |
| 103 |
unsafe { msg_send![self, resolveTexture] } |
| 104 |
} |
| 105 |
|
| 106 |
pub fn set_resolve_texture(&self, resolve_texture: Option<&TextureRef>) { |
| 107 |
unsafe { msg_send![self, setResolveTexture: resolve_texture] } |
| 108 |
} |
| 109 |
|
| 110 |
pub fn resolve_level(&self) -> NSUInteger { |
| 111 |
unsafe { msg_send![self, resolveLevel] } |
| 112 |
} |
| 113 |
|
| 114 |
pub fn set_resolve_level(&self, resolve_level: NSUInteger) { |
| 115 |
unsafe { msg_send![self, setResolveLevel: resolve_level] } |
| 116 |
} |
| 117 |
|
| 118 |
pub fn resolve_slice(&self) -> NSUInteger { |
| 119 |
unsafe { msg_send![self, resolveSlice] } |
| 120 |
} |
| 121 |
|
| 122 |
pub fn set_resolve_slice(&self, resolve_slice: NSUInteger) { |
| 123 |
unsafe { msg_send![self, setResolveSlice: resolve_slice] } |
| 124 |
} |
| 125 |
|
| 126 |
pub fn resolve_depth_plane(&self) -> NSUInteger { |
| 127 |
unsafe { msg_send![self, resolveDepthPlane] } |
| 128 |
} |
| 129 |
|
| 130 |
pub fn set_resolve_depth_plane(&self, resolve_depth_plane: NSUInteger) { |
| 131 |
unsafe { msg_send![self, setResolveDepthPlane: resolve_depth_plane] } |
| 132 |
} |
| 133 |
|
| 134 |
pub fn load_action(&self) -> MTLLoadAction { |
| 135 |
unsafe { msg_send![self, loadAction] } |
| 136 |
} |
| 137 |
|
| 138 |
pub fn set_load_action(&self, load_action: MTLLoadAction) { |
| 139 |
unsafe { msg_send![self, setLoadAction: load_action] } |
| 140 |
} |
| 141 |
|
| 142 |
pub fn store_action(&self) -> MTLStoreAction { |
| 143 |
unsafe { msg_send![self, storeAction] } |
| 144 |
} |
| 145 |
|
| 146 |
pub fn set_store_action(&self, store_action: MTLStoreAction) { |
| 147 |
unsafe { msg_send![self, setStoreAction: store_action] } |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
/// See <https://developer.apple.com/documentation/metal/mtlrenderpasscolorattachmentdescriptor> |
| 152 |
pub enum MTLRenderPassColorAttachmentDescriptor {} |
| 153 |
|
| 154 |
foreign_obj_type! { |
| 155 |
type CType = MTLRenderPassColorAttachmentDescriptor; |
| 156 |
pub struct RenderPassColorAttachmentDescriptor; |
| 157 |
type ParentType = RenderPassAttachmentDescriptor; |
| 158 |
} |
| 159 |
|
| 160 |
impl RenderPassColorAttachmentDescriptor { |
| 161 |
pub fn new() -> Self { |
| 162 |
unsafe { |
| 163 |
let class = class!(MTLRenderPassColorAttachmentDescriptor); |
| 164 |
msg_send![class, new] |
| 165 |
} |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
impl RenderPassColorAttachmentDescriptorRef { |
| 170 |
pub fn clear_color(&self) -> MTLClearColor { |
| 171 |
unsafe { msg_send![self, clearColor] } |
| 172 |
} |
| 173 |
|
| 174 |
pub fn set_clear_color(&self, clear_color: MTLClearColor) { |
| 175 |
unsafe { msg_send![self, setClearColor: clear_color] } |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
/// See <https://developer.apple.com/documentation/metal/mtlrenderpassdepthattachmentdescriptor> |
| 180 |
pub enum MTLRenderPassDepthAttachmentDescriptor {} |
| 181 |
|
| 182 |
foreign_obj_type! { |
| 183 |
type CType = MTLRenderPassDepthAttachmentDescriptor; |
| 184 |
pub struct RenderPassDepthAttachmentDescriptor; |
| 185 |
type ParentType = RenderPassAttachmentDescriptor; |
| 186 |
} |
| 187 |
|
| 188 |
impl RenderPassDepthAttachmentDescriptorRef { |
| 189 |
pub fn clear_depth(&self) -> f64 { |
| 190 |
unsafe { msg_send![self, clearDepth] } |
| 191 |
} |
| 192 |
|
| 193 |
pub fn set_clear_depth(&self, clear_depth: f64) { |
| 194 |
unsafe { msg_send![self, setClearDepth: clear_depth] } |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
/// See <https://developer.apple.com/documentation/metal/mtlrenderpassstencilattachmentdescriptor> |
| 199 |
pub enum MTLRenderPassStencilAttachmentDescriptor {} |
| 200 |
|
| 201 |
foreign_obj_type! { |
| 202 |
type CType = MTLRenderPassStencilAttachmentDescriptor; |
| 203 |
pub struct RenderPassStencilAttachmentDescriptor; |
| 204 |
type ParentType = RenderPassAttachmentDescriptor; |
| 205 |
} |
| 206 |
|
| 207 |
impl RenderPassStencilAttachmentDescriptorRef { |
| 208 |
pub fn clear_stencil(&self) -> u32 { |
| 209 |
unsafe { msg_send![self, clearStencil] } |
| 210 |
} |
| 211 |
|
| 212 |
pub fn set_clear_stencil(&self, clear_stencil: u32) { |
| 213 |
unsafe { msg_send![self, setClearStencil: clear_stencil] } |
| 214 |
} |
| 215 |
|
| 216 |
pub fn stencil_resolve_filter(&self) -> MTLMultisampleStencilResolveFilter { |
| 217 |
unsafe { msg_send![self, stencilResolveFilter] } |
| 218 |
} |
| 219 |
|
| 220 |
pub fn set_stencil_resolve_filter( |
| 221 |
&self, |
| 222 |
stencil_resolve_filter: MTLMultisampleStencilResolveFilter, |
| 223 |
) { |
| 224 |
unsafe { msg_send![self, setStencilResolveFilter: stencil_resolve_filter] } |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
/// See <https://developer.apple.com/documentation/metal/mtlrenderpasscolorattachmentdescriptorarray> |
| 229 |
pub enum MTLRenderPassColorAttachmentDescriptorArray {} |
| 230 |
|
| 231 |
foreign_obj_type! { |
| 232 |
type CType = MTLRenderPassColorAttachmentDescriptorArray; |
| 233 |
pub struct RenderPassColorAttachmentDescriptorArray; |
| 234 |
} |
| 235 |
|
| 236 |
impl RenderPassColorAttachmentDescriptorArrayRef { |
| 237 |
pub fn object_at(&self, index: NSUInteger) -> Option<&RenderPassColorAttachmentDescriptorRef> { |
| 238 |
unsafe { msg_send![self, objectAtIndexedSubscript: index] } |
| 239 |
} |
| 240 |
|
| 241 |
pub fn set_object_at( |
| 242 |
&self, |
| 243 |
index: NSUInteger, |
| 244 |
attachment: Option<&RenderPassColorAttachmentDescriptorRef>, |
| 245 |
) { |
| 246 |
unsafe { |
| 247 |
msg_send![self, setObject:attachment |
| 248 |
atIndexedSubscript:index] |
| 249 |
} |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
/// See <https://developer.apple.com/documentation/metal/mtlrenderpasssamplebufferattachmentdescriptor> |
| 254 |
pub enum MTLRenderPassSampleBufferAttachmentDescriptor {} |
| 255 |
|
| 256 |
foreign_obj_type! { |
| 257 |
type CType = MTLRenderPassSampleBufferAttachmentDescriptor; |
| 258 |
pub struct RenderPassSampleBufferAttachmentDescriptor; |
| 259 |
} |
| 260 |
|
| 261 |
impl RenderPassSampleBufferAttachmentDescriptor { |
| 262 |
pub fn new() -> Self { |
| 263 |
let class = class!(MTLRenderPassSampleBufferAttachmentDescriptor); |
| 264 |
unsafe { msg_send![class, new] } |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
impl RenderPassSampleBufferAttachmentDescriptorRef { |
| 269 |
pub fn sample_buffer(&self) -> Option<&CounterSampleBufferRef> { |
| 270 |
unsafe { msg_send![self, sampleBuffer] } |
| 271 |
} |
| 272 |
|
| 273 |
pub fn set_sample_buffer(&self, sample_buffer: &CounterSampleBufferRef) { |
| 274 |
unsafe { msg_send![self, setSampleBuffer: sample_buffer] } |
| 275 |
} |
| 276 |
|
| 277 |
pub fn start_of_vertex_sample_index(&self) -> NSUInteger { |
| 278 |
unsafe { msg_send![self, startOfVertexSampleIndex] } |
| 279 |
} |
| 280 |
|
| 281 |
pub fn set_start_of_vertex_sample_index(&self, start_of_vertex_sample_index: NSUInteger) { |
| 282 |
unsafe { |
| 283 |
msg_send![ |
| 284 |
self, |
| 285 |
setStartOfVertexSampleIndex: start_of_vertex_sample_index |
| 286 |
] |
| 287 |
} |
| 288 |
} |
| 289 |
|
| 290 |
pub fn end_of_vertex_sample_index(&self) -> NSUInteger { |
| 291 |
unsafe { msg_send![self, endOfVertexSampleIndex] } |
| 292 |
} |
| 293 |
|
| 294 |
pub fn set_end_of_vertex_sample_index(&self, end_of_vertex_sample_index: NSUInteger) { |
| 295 |
unsafe { msg_send![self, setEndOfVertexSampleIndex: end_of_vertex_sample_index] } |
| 296 |
} |
| 297 |
|
| 298 |
pub fn start_of_fragment_sample_index(&self) -> NSUInteger { |
| 299 |
unsafe { msg_send![self, startOfFragmentSampleIndex] } |
| 300 |
} |
| 301 |
|
| 302 |
pub fn set_start_of_fragment_sample_index(&self, start_of_fragment_sample_index: NSUInteger) { |
| 303 |
unsafe { |
| 304 |
msg_send![ |
| 305 |
self, |
| 306 |
setStartOfFragmentSampleIndex: start_of_fragment_sample_index |
| 307 |
] |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
pub fn end_of_fragment_sample_index(&self) -> NSUInteger { |
| 312 |
unsafe { msg_send![self, endOfFragmentSampleIndex] } |
| 313 |
} |
| 314 |
|
| 315 |
pub fn set_end_of_fragment_sample_index(&self, end_of_fragment_sample_index: NSUInteger) { |
| 316 |
unsafe { |
| 317 |
msg_send![ |
| 318 |
self, |
| 319 |
setEndOfFragmentSampleIndex: end_of_fragment_sample_index |
| 320 |
] |
| 321 |
} |
| 322 |
} |
| 323 |
} |
| 324 |
|
| 325 |
/// See <https://developer.apple.com/documentation/metal/mtlrenderpasssamplebufferattachmentdescriptorarray> |
| 326 |
pub enum MTLRenderPassSampleBufferAttachmentDescriptorArray {} |
| 327 |
|
| 328 |
foreign_obj_type! { |
| 329 |
type CType = MTLRenderPassSampleBufferAttachmentDescriptorArray; |
| 330 |
pub struct RenderPassSampleBufferAttachmentDescriptorArray; |
| 331 |
} |
| 332 |
|
| 333 |
impl RenderPassSampleBufferAttachmentDescriptorArrayRef { |
| 334 |
pub fn object_at( |
| 335 |
&self, |
| 336 |
index: NSUInteger, |
| 337 |
) -> Option<&RenderPassSampleBufferAttachmentDescriptorRef> { |
| 338 |
unsafe { msg_send![self, objectAtIndexedSubscript: index] } |
| 339 |
} |
| 340 |
|
| 341 |
pub fn set_object_at( |
| 342 |
&self, |
| 343 |
index: NSUInteger, |
| 344 |
attachment: Option<&RenderPassSampleBufferAttachmentDescriptorRef>, |
| 345 |
) { |
| 346 |
unsafe { |
| 347 |
msg_send![self, setObject:attachment |
| 348 |
atIndexedSubscript:index] |
| 349 |
} |
| 350 |
} |
| 351 |
} |
| 352 |
|
| 353 |
/// ## Important! |
| 354 |
/// When configuring a [`MTLTextureDescriptor`] object for use with an attachment, set its usage |
| 355 |
/// value to renderTarget if you already know that you intend to use the resulting MTLTexture object in |
| 356 |
/// an attachment. This may significantly improve your app’s performance with certain hardware. |
| 357 |
/// |
| 358 |
/// See <https://developer.apple.com/documentation/metal/mtlrenderpassdescriptor> |
| 359 |
pub enum MTLRenderPassDescriptor {} |
| 360 |
|
| 361 |
foreign_obj_type! { |
| 362 |
type CType = MTLRenderPassDescriptor; |
| 363 |
pub struct RenderPassDescriptor; |
| 364 |
} |
| 365 |
|
| 366 |
impl RenderPassDescriptor { |
| 367 |
/// Creates a default render pass descriptor with no attachments. |
| 368 |
pub fn new<'a>() -> &'a RenderPassDescriptorRef { |
| 369 |
unsafe { msg_send![class!(MTLRenderPassDescriptor), renderPassDescriptor] } |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
impl RenderPassDescriptorRef { |
| 374 |
pub fn color_attachments(&self) -> &RenderPassColorAttachmentDescriptorArrayRef { |
| 375 |
unsafe { msg_send![self, colorAttachments] } |
| 376 |
} |
| 377 |
|
| 378 |
pub fn depth_attachment(&self) -> Option<&RenderPassDepthAttachmentDescriptorRef> { |
| 379 |
unsafe { msg_send![self, depthAttachment] } |
| 380 |
} |
| 381 |
|
| 382 |
pub fn set_depth_attachment( |
| 383 |
&self, |
| 384 |
depth_attachment: Option<&RenderPassDepthAttachmentDescriptorRef>, |
| 385 |
) { |
| 386 |
unsafe { msg_send![self, setDepthAttachment: depth_attachment] } |
| 387 |
} |
| 388 |
|
| 389 |
pub fn stencil_attachment(&self) -> Option<&RenderPassStencilAttachmentDescriptorRef> { |
| 390 |
unsafe { msg_send![self, stencilAttachment] } |
| 391 |
} |
| 392 |
|
| 393 |
pub fn set_stencil_attachment( |
| 394 |
&self, |
| 395 |
stencil_attachment: Option<&RenderPassStencilAttachmentDescriptorRef>, |
| 396 |
) { |
| 397 |
unsafe { msg_send![self, setStencilAttachment: stencil_attachment] } |
| 398 |
} |
| 399 |
|
| 400 |
pub fn visibility_result_buffer(&self) -> Option<&BufferRef> { |
| 401 |
unsafe { msg_send![self, visibilityResultBuffer] } |
| 402 |
} |
| 403 |
|
| 404 |
pub fn set_visibility_result_buffer(&self, buffer: Option<&BufferRef>) { |
| 405 |
unsafe { msg_send![self, setVisibilityResultBuffer: buffer] } |
| 406 |
} |
| 407 |
|
| 408 |
pub fn render_target_array_length(&self) -> NSUInteger { |
| 409 |
unsafe { msg_send![self, renderTargetArrayLength] } |
| 410 |
} |
| 411 |
|
| 412 |
pub fn set_render_target_array_length(&self, length: NSUInteger) { |
| 413 |
unsafe { msg_send![self, setRenderTargetArrayLength: length] } |
| 414 |
} |
| 415 |
|
| 416 |
pub fn render_target_width(&self) -> NSUInteger { |
| 417 |
unsafe { msg_send![self, renderTargetWidth] } |
| 418 |
} |
| 419 |
|
| 420 |
pub fn set_render_target_width(&self, size: NSUInteger) { |
| 421 |
unsafe { msg_send![self, setRenderTargetWidth: size] } |
| 422 |
} |
| 423 |
|
| 424 |
pub fn render_target_height(&self) -> NSUInteger { |
| 425 |
unsafe { msg_send![self, renderTargetHeight] } |
| 426 |
} |
| 427 |
|
| 428 |
pub fn set_render_target_height(&self, size: NSUInteger) { |
| 429 |
unsafe { msg_send![self, setRenderTargetHeight: size] } |
| 430 |
} |
| 431 |
|
| 432 |
pub fn default_raster_sample_count(&self) -> NSUInteger { |
| 433 |
unsafe { msg_send![self, defaultRasterSampleCount] } |
| 434 |
} |
| 435 |
|
| 436 |
pub fn set_default_raster_sample_count(&self, count: NSUInteger) { |
| 437 |
unsafe { msg_send![self, setDefaultRasterSampleCount: count] } |
| 438 |
} |
| 439 |
|
| 440 |
pub fn sample_buffer_attachments(&self) -> &RenderPassSampleBufferAttachmentDescriptorArrayRef { |
| 441 |
unsafe { msg_send![self, sampleBufferAttachments] } |
| 442 |
} |
| 443 |
} |