ctru/services/
gspgpu.rs

1//! GSPGPU service
2
3/// GSPGPU events that can be awaited.
4#[doc(alias = "GSPGPU_Event")]
5#[derive(Copy, Clone, Debug, PartialEq, Eq)]
6#[repr(u8)]
7pub enum Event {
8    /// Memory fill 1 completed.
9    Psc0 = ctru_sys::GSPGPU_EVENT_PSC0,
10    /// Memory fill 2 completed.
11    Psc1 = ctru_sys::GSPGPU_EVENT_PSC1,
12    /// Top screen VBlank.
13    VBlank0 = ctru_sys::GSPGPU_EVENT_VBlank0,
14    /// Bottom screen VBlank.
15    VBlank1 = ctru_sys::GSPGPU_EVENT_VBlank1,
16    /// Display transfer completed.
17    PPF = ctru_sys::GSPGPU_EVENT_PPF,
18    /// Command list processing completed.
19    P3D = ctru_sys::GSPGPU_EVENT_P3D,
20    /// Direct Memory Access requested.
21    DMA = ctru_sys::GSPGPU_EVENT_DMA,
22}
23
24#[doc(alias = "GSPGPU_FramebufferFormat")]
25/// Framebuffer formats supported by the 3DS' screens.
26#[derive(Copy, Clone, Debug, PartialEq, Eq)]
27#[repr(u8)]
28pub enum FramebufferFormat {
29    /// RGBA8. 4 bytes per pixel
30    Rgba8 = ctru_sys::GSP_RGBA8_OES,
31    /// BGR8. 3 bytes per pixel
32    Bgr8 = ctru_sys::GSP_BGR8_OES,
33    /// RGB565. 2 bytes per pixel
34    Rgb565 = ctru_sys::GSP_RGB565_OES,
35    /// RGB5A1. 2 bytes per pixel
36    Rgb5A1 = ctru_sys::GSP_RGB5_A1_OES,
37    /// RGBA4. 2 bytes per pixel
38    Rgba4 = ctru_sys::GSP_RGBA4_OES,
39}
40
41impl FramebufferFormat {
42    /// Returns the number of bytes per pixel used by this FramebufferFormat
43    pub fn pixel_depth_bytes(&self) -> usize {
44        use self::FramebufferFormat::*;
45        match *self {
46            Rgba8 => 4,
47            Bgr8 => 3,
48            Rgb565 => 2,
49            Rgb5A1 => 2,
50            Rgba4 => 2,
51        }
52    }
53}
54
55/// Waits for a GSPGPU event to occur.
56///
57/// `discard_current` determines whether to discard the current event and wait for the next event
58#[doc(alias = "gspWaitForEvent")]
59pub fn wait_for_event(ev: Event, discard_current: bool) {
60    unsafe {
61        ctru_sys::gspWaitForEvent(ev.into(), discard_current);
62    }
63}
64
65impl From<ctru_sys::GSPGPU_FramebufferFormat> for FramebufferFormat {
66    fn from(g: ctru_sys::GSPGPU_FramebufferFormat) -> Self {
67        use self::FramebufferFormat::*;
68        match g {
69            ctru_sys::GSP_RGBA8_OES => Rgba8,
70            ctru_sys::GSP_BGR8_OES => Bgr8,
71            ctru_sys::GSP_RGB565_OES => Rgb565,
72            ctru_sys::GSP_RGB5_A1_OES => Rgb5A1,
73            ctru_sys::GSP_RGBA4_OES => Rgba4,
74            _ => unreachable!(),
75        }
76    }
77}
78
79from_impl!(FramebufferFormat, ctru_sys::GSPGPU_FramebufferFormat);
80from_impl!(Event, ctru_sys::GSPGPU_Event);