Browse Source

Do some cleanup and fix swap trait impls

Oops! The argument to `gfxScreenSwapBuffers` is gfxScreen_t, not
gfx3dSide_t ! Unfortunately they are both alias to libc::c_uint so we
didn't get any help from the Rust compiler when passing the screen side
into this function.
pull/118/head
Ian Chamberlain 2 years ago
parent
commit
0ef017cf4d
No known key found for this signature in database
GPG Key ID: AE5484D09405AA60
  1. 3
      ctru-rs/examples/gfx-3d-mode.rs
  2. 54
      ctru-rs/src/services/gfx.rs

3
ctru-rs/examples/gfx-3d-mode.rs

@ -62,8 +62,7 @@ fn main() { @@ -62,8 +62,7 @@ fn main() {
buf.copy_from(IMAGE.as_ptr(), IMAGE.len());
}
drop(left);
drop(right);
drop((left, right));
top_screen.flush_buffers();
top_screen.swap_buffers();

54
ctru-rs/src/services/gfx.rs

@ -81,20 +81,32 @@ pub struct TopScreen3D<'top_screen> { @@ -81,20 +81,32 @@ pub struct TopScreen3D<'top_screen> {
}
pub trait Swap: private::Sealed {
/// Swaps the video buffers.
///
/// This should be used even if double buffering is disabled.
fn swap_buffers(&mut self);
}
trait SwappableScreen: Screen {}
impl SwappableScreen for TopScreen {}
impl SwappableScreen for BottomScreen {}
impl Swap for TopScreen3D<'_> {
fn swap_buffers(&mut self) {
unsafe {
ctru_sys::gfxScreenSwapBuffers(ctru_sys::GFX_TOP, true);
}
}
}
impl<S: SwappableScreen> Swap for S {
/// Swaps the video buffers.
///
/// This should be used even if double buffering is disabled.
impl Swap for TopScreen {
fn swap_buffers(&mut self) {
unsafe {
ctru_sys::gfxScreenSwapBuffers(ctru_sys::GFX_TOP, false);
}
}
}
impl Swap for BottomScreen {
fn swap_buffers(&mut self) {
unsafe {
ctru_sys::gfxScreenSwapBuffers(self.side().into(), false);
ctru_sys::gfxScreenSwapBuffers(ctru_sys::GFX_BOTTOM, false);
}
}
}
@ -124,23 +136,6 @@ impl<S: FlushableScreen> Flush for S { @@ -124,23 +136,6 @@ impl<S: FlushableScreen> Flush for S {
}
}
impl Swap for TopScreen3D<'_> {
fn swap_buffers(&mut self) {
unsafe {
ctru_sys::gfxScreenSwapBuffers(Side::Left.into(), true);
}
}
}
impl TopScreen3D<'_> {
/// Flush the buffers for both the left and right sides of the screen.
pub fn flush_buffers(&mut self) {
let (mut left, mut right) = self.split_mut();
left.flush_buffer();
right.flush_buffer();
}
}
/// The left side of the top screen, when using 3D mode.
#[derive(Debug)]
#[non_exhaustive]
@ -253,6 +248,13 @@ impl TopScreen3D<'_> { @@ -253,6 +248,13 @@ impl TopScreen3D<'_> {
(&mut screen.left as _, &mut screen.right as _)
})
}
/// Convenient helper to flush the buffers for both the left and right sides of the screen.
pub fn flush_buffers(&mut self) {
let (mut left, mut right) = self.split_mut();
left.flush_buffer();
right.flush_buffer();
}
}
impl<'top_screen> From<&'top_screen RefCell<TopScreen>> for TopScreen3D<'top_screen> {
@ -296,7 +298,7 @@ impl TopScreen { @@ -296,7 +298,7 @@ impl TopScreen {
impl Screen for TopScreen {
fn as_raw(&self) -> ctru_sys::gfxScreen_t {
self.left.as_raw()
ctru_sys::GFX_TOP
}
fn side(&self) -> Side {

Loading…
Cancel
Save