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. 25
      citro3d/examples/triangle.rs
  2. 12
      citro3d/src/render.rs
  3. 2
      citro3d/src/shader.rs

25
citro3d/examples/triangle.rs

@ -5,7 +5,7 @@ use ctru::services::apt::Apt; @@ -5,7 +5,7 @@ use ctru::services::apt::Apt;
use ctru::services::hid::{Hid, KeyPad};
use ctru::services::soc::Soc;
use citro3d::render::{ClearFlags, DepthFormat};
use citro3d::render::ClearFlags;
use std::ffi::CStr;
use std::mem::MaybeUninit;
@ -29,7 +29,7 @@ struct Vertex { @@ -29,7 +29,7 @@ struct Vertex {
color: Vec3,
}
const VERTICES: &[Vertex] = &[
static VERTICES: &[Vertex] = &[
Vertex {
pos: Vec3::new(0.0, 0.5, 0.5),
color: Vec3::new(1.0, 0.0, 0.0),
@ -44,7 +44,7 @@ const VERTICES: &[Vertex] = &[ @@ -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"));
fn main() {
@ -63,27 +63,18 @@ fn main() { @@ -63,27 +63,18 @@ fn main() {
let mut instance = citro3d::Instance::new().expect("failed to initialize Citro3D");
let mut render_target = citro3d::render::Target::new(
width,
height,
&mut *top_screen,
DepthFormat::Depth24Stencil8,
)
.expect("failed to create render target");
let mut render_target = citro3d::render::Target::new(width, height, top_screen, None)
.expect("failed to create render target");
render_target.set_output(Side::Left);
render_target.set_output(Side::Right);
let mut bottom_screen = gfx.bottom_screen.borrow_mut();
let frame_buffer = bottom_screen.get_raw_framebuffer();
let (width, height) = (frame_buffer.width, frame_buffer.height);
let mut bottom_target = citro3d::render::Target::new(
width,
height,
&mut *bottom_screen,
DepthFormat::Depth24Stencil8,
)
.expect("failed to create bottom screen render target");
let mut bottom_target = citro3d::render::Target::new(width, height, bottom_screen, None)
.expect("failed to create bottom screen render target");
bottom_target.set_output(Side::Left);

12
citro3d/src/render.rs

@ -1,6 +1,8 @@ @@ -1,6 +1,8 @@
//! 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.
use std::cell::RefMut;
use citro3d_sys::{
C3D_RenderTarget, C3D_RenderTargetCreate, C3D_RenderTargetDelete, C3D_DEPTHTYPE, GPU_COLORBUF,
GPU_DEPTHBUF,
@ -17,7 +19,7 @@ mod transfer; @@ -17,7 +19,7 @@ mod transfer;
pub struct Target<'s, S> {
raw: *mut citro3d_sys::C3D_RenderTarget,
color_format: ColorFormat,
screen: &'s mut S,
screen: RefMut<'s, S>,
}
impl<'s, S> Drop for Target<'s, S> {
@ -30,7 +32,7 @@ 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>
where
S: 's + Screen,
S: Screen,
{
/// Create a new render target with the specified size, color format,
/// and depth format.
@ -41,8 +43,8 @@ where @@ -41,8 +43,8 @@ where
pub fn new(
width: u16,
height: u16,
screen: &'s mut S,
depth_format: DepthFormat,
screen: RefMut<'s, S>,
depth_format: Option<DepthFormat>,
) -> Result<Self> {
let color_format = screen.get_framebuffer_format().into();
@ -51,7 +53,7 @@ where @@ -51,7 +53,7 @@ where
width.into(),
height.into(),
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 { @@ -74,7 +74,7 @@ impl Program {
}
}
impl<'vert, 'geom> Drop for Program {
impl Drop for Program {
fn drop(&mut self) {
unsafe {
let _ = citro3d_sys::shaderProgramFree(self.as_raw());

Loading…
Cancel
Save