Browse Source

Use RefMut and fix some lints

pull/4/head
Ian Chamberlain 2 years ago
parent
commit
5ffde47b85
No known key found for this signature in database
GPG Key ID: AE5484D09405AA60
  1. 21
      citro3d/examples/triangle.rs
  2. 12
      citro3d/src/render.rs
  3. 2
      citro3d/src/shader.rs

21
citro3d/examples/triangle.rs

@ -5,7 +5,7 @@ use ctru::services::apt::Apt;
use ctru::services::hid::{Hid, KeyPad}; use ctru::services::hid::{Hid, KeyPad};
use ctru::services::soc::Soc; use ctru::services::soc::Soc;
use citro3d::render::{ClearFlags, DepthFormat}; use citro3d::render::ClearFlags;
use std::ffi::CStr; use std::ffi::CStr;
use std::mem::MaybeUninit; use std::mem::MaybeUninit;
@ -29,7 +29,7 @@ struct Vertex {
color: Vec3, color: Vec3,
} }
const VERTICES: &[Vertex] = &[ static VERTICES: &[Vertex] = &[
Vertex { Vertex {
pos: Vec3::new(0.0, 0.5, 0.5), pos: Vec3::new(0.0, 0.5, 0.5),
color: Vec3::new(1.0, 0.0, 0.0), color: Vec3::new(1.0, 0.0, 0.0),
@ -44,7 +44,7 @@ const VERTICES: &[Vertex] = &[
}, },
]; ];
const SHADER_BYTES: &[u8] = static SHADER_BYTES: &[u8] =
include_aligned_bytes!(concat!(env!("OUT_DIR"), "/examples/assets/vshader.shbin")); include_aligned_bytes!(concat!(env!("OUT_DIR"), "/examples/assets/vshader.shbin"));
fn main() { fn main() {
@ -63,26 +63,17 @@ fn main() {
let mut instance = citro3d::Instance::new().expect("failed to initialize Citro3D"); let mut instance = citro3d::Instance::new().expect("failed to initialize Citro3D");
let mut render_target = citro3d::render::Target::new( let mut render_target = citro3d::render::Target::new(width, height, top_screen, None)
width,
height,
&mut *top_screen,
DepthFormat::Depth24Stencil8,
)
.expect("failed to create render target"); .expect("failed to create render target");
render_target.set_output(Side::Left); render_target.set_output(Side::Left);
render_target.set_output(Side::Right);
let mut bottom_screen = gfx.bottom_screen.borrow_mut(); let mut bottom_screen = gfx.bottom_screen.borrow_mut();
let frame_buffer = bottom_screen.get_raw_framebuffer(); let frame_buffer = bottom_screen.get_raw_framebuffer();
let (width, height) = (frame_buffer.width, frame_buffer.height); let (width, height) = (frame_buffer.width, frame_buffer.height);
let mut bottom_target = citro3d::render::Target::new( let mut bottom_target = citro3d::render::Target::new(width, height, bottom_screen, None)
width,
height,
&mut *bottom_screen,
DepthFormat::Depth24Stencil8,
)
.expect("failed to create bottom screen render target"); .expect("failed to create bottom screen render target");
bottom_target.set_output(Side::Left); bottom_target.set_output(Side::Left);

12
citro3d/src/render.rs

@ -1,6 +1,8 @@
//! This module provides render target types and options for controlling transfer //! This module provides render target types and options for controlling transfer
//! of data to the GPU, including the format of color and depth data to be rendered. //! of data to the GPU, including the format of color and depth data to be rendered.
use std::cell::RefMut;
use citro3d_sys::{ use citro3d_sys::{
C3D_RenderTarget, C3D_RenderTargetCreate, C3D_RenderTargetDelete, C3D_DEPTHTYPE, GPU_COLORBUF, C3D_RenderTarget, C3D_RenderTargetCreate, C3D_RenderTargetDelete, C3D_DEPTHTYPE, GPU_COLORBUF,
GPU_DEPTHBUF, GPU_DEPTHBUF,
@ -17,7 +19,7 @@ mod transfer;
pub struct Target<'s, S> { pub struct Target<'s, S> {
raw: *mut citro3d_sys::C3D_RenderTarget, raw: *mut citro3d_sys::C3D_RenderTarget,
color_format: ColorFormat, color_format: ColorFormat,
screen: &'s mut S, screen: RefMut<'s, S>,
} }
impl<'s, S> Drop for Target<'s, S> { impl<'s, S> Drop for Target<'s, S> {
@ -30,7 +32,7 @@ impl<'s, S> Drop for Target<'s, S> {
impl<'s, S> Target<'s, S> impl<'s, S> Target<'s, S>
where where
S: 's + Screen, S: Screen,
{ {
/// Create a new render target with the specified size, color format, /// Create a new render target with the specified size, color format,
/// and depth format. /// and depth format.
@ -41,8 +43,8 @@ where
pub fn new( pub fn new(
width: u16, width: u16,
height: u16, height: u16,
screen: &'s mut S, screen: RefMut<'s, S>,
depth_format: DepthFormat, depth_format: Option<DepthFormat>,
) -> Result<Self> { ) -> Result<Self> {
let color_format = screen.get_framebuffer_format().into(); let color_format = screen.get_framebuffer_format().into();
@ -51,7 +53,7 @@ where
width.into(), width.into(),
height.into(), height.into(),
color_format as GPU_COLORBUF, color_format as GPU_COLORBUF,
depth_format.as_raw(), depth_format.map_or(C3D_DEPTHTYPE { __i: -1 }, DepthFormat::as_raw),
) )
}; };

2
citro3d/src/shader.rs

@ -74,7 +74,7 @@ impl Program {
} }
} }
impl<'vert, 'geom> Drop for Program { impl Drop for Program {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
let _ = citro3d_sys::shaderProgramFree(self.as_raw()); let _ = citro3d_sys::shaderProgramFree(self.as_raw());

Loading…
Cancel
Save