Skip to main content

mtl_gpu/encoder/render_encoder/
viewport.rs

1//! Viewport and scissor configuration methods.
2
3use mtl_foundation::{Referencing, UInteger};
4use mtl_sys::{msg_send_1, sel};
5
6use crate::types::{ScissorRect, Viewport};
7
8use super::RenderCommandEncoder;
9
10impl RenderCommandEncoder {
11    // =========================================================================
12    // Viewport and Scissor
13    // =========================================================================
14
15    /// Set the viewport.
16    ///
17    /// C++ equivalent: `void setViewport(MTL::Viewport)`
18    #[inline]
19    pub fn set_viewport(&self, viewport: Viewport) {
20        unsafe {
21            msg_send_1::<(), Viewport>(self.as_ptr(), sel!(setViewport:), viewport);
22        }
23    }
24
25    /// Set multiple viewports.
26    ///
27    /// C++ equivalent: `void setViewports(const Viewport*, NS::UInteger)`
28    #[inline]
29    pub fn set_viewports(&self, viewports: &[Viewport]) {
30        unsafe {
31            mtl_sys::msg_send_2::<(), *const Viewport, UInteger>(
32                self.as_ptr(),
33                sel!(setViewports: count:),
34                viewports.as_ptr(),
35                viewports.len() as UInteger,
36            );
37        }
38    }
39
40    /// Set the scissor rectangle.
41    ///
42    /// C++ equivalent: `void setScissorRect(MTL::ScissorRect)`
43    #[inline]
44    pub fn set_scissor_rect(&self, rect: ScissorRect) {
45        unsafe {
46            msg_send_1::<(), ScissorRect>(self.as_ptr(), sel!(setScissorRect:), rect);
47        }
48    }
49
50    /// Set multiple scissor rectangles.
51    ///
52    /// C++ equivalent: `void setScissorRects(const ScissorRect*, NS::UInteger)`
53    #[inline]
54    pub fn set_scissor_rects(&self, rects: &[ScissorRect]) {
55        unsafe {
56            mtl_sys::msg_send_2::<(), *const ScissorRect, UInteger>(
57                self.as_ptr(),
58                sel!(setScissorRects: count:),
59                rects.as_ptr(),
60                rects.len() as UInteger,
61            );
62        }
63    }
64}