Browse Source

Update citro3d to use upstream ctru_sys types

pull/10/head
Ian Chamberlain 2 years ago
parent
commit
340a38489c
No known key found for this signature in database
GPG Key ID: AE5484D09405AA60
  1. 5
      citro3d/Cargo.toml
  2. 4
      citro3d/src/lib.rs
  3. 20
      citro3d/src/render.rs
  4. 13
      citro3d/src/render/transfer.rs
  5. 26
      citro3d/src/shader.rs

5
citro3d/Cargo.toml

@ -7,7 +7,6 @@ edition = "2021"
bitflags = "1.3.2" bitflags = "1.3.2"
bytemuck = { version = "1.10.0", features = ["extern_crate_std"] } bytemuck = { version = "1.10.0", features = ["extern_crate_std"] }
citro3d-sys = { git = "https://github.com/ian-h-chamberlain/citro3d-rs.git" } citro3d-sys = { git = "https://github.com/ian-h-chamberlain/citro3d-rs.git" }
ctru-rs = { git = "https://github.com/Meziu/ctru-rs.git" } ctru-rs = { git = "https://github.com/rust3ds/ctru-rs.git" }
ctru-sys = { git = "https://github.com/rust3ds/ctru-rs.git" }
libc = "0.2.125" libc = "0.2.125"
[dev-dependencies]

4
citro3d/src/lib.rs

@ -25,7 +25,7 @@ impl Instance {
/// ///
/// Fails if `citro3d` cannot be initialized. /// Fails if `citro3d` cannot be initialized.
pub fn new() -> Result<Self> { pub fn new() -> Result<Self> {
Self::with_cmdbuf_size(citro3d_sys::C3D_DEFAULT_CMDBUF_SIZE) Self::with_cmdbuf_size(citro3d_sys::C3D_DEFAULT_CMDBUF_SIZE.try_into().unwrap())
} }
/// Initialize the instance with a specified command buffer size. /// Initialize the instance with a specified command buffer size.
@ -33,7 +33,7 @@ impl Instance {
/// # Errors /// # Errors
/// ///
/// Fails if `citro3d` cannot be initialized. /// Fails if `citro3d` cannot be initialized.
pub fn with_cmdbuf_size(size: u32) -> Result<Self> { pub fn with_cmdbuf_size(size: usize) -> Result<Self> {
if unsafe { citro3d_sys::C3D_Init(size) } { if unsafe { citro3d_sys::C3D_Init(size) } {
Ok(Self) Ok(Self)
} else { } else {

20
citro3d/src/render.rs

@ -2,11 +2,11 @@
//! 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 citro3d_sys::{ use citro3d_sys::{
C3D_RenderTarget, C3D_RenderTargetCreate, C3D_RenderTargetDelete, C3D_DEPTHTYPE, GPU_COLORBUF, C3D_RenderTarget, C3D_RenderTargetCreate, C3D_RenderTargetDelete, C3D_DEPTHTYPE,
GPU_DEPTHBUF,
}; };
use ctru::gfx; use ctru::gfx;
use ctru::services::gspgpu::FramebufferFormat; use ctru::services::gspgpu::FramebufferFormat;
use ctru_sys::{GPU_COLORBUF, GPU_DEPTHBUF};
use crate::{Error, Result}; use crate::{Error, Result};
@ -103,15 +103,15 @@ bitflags::bitflags! {
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub enum ColorFormat { pub enum ColorFormat {
/// 8-bit Red + 8-bit Green + 8-bit Blue + 8-bit Alpha. /// 8-bit Red + 8-bit Green + 8-bit Blue + 8-bit Alpha.
RGBA8 = citro3d_sys::GPU_RB_RGBA8, RGBA8 = ctru_sys::GPU_RB_RGBA8,
/// 8-bit Red + 8-bit Green + 8-bit Blue. /// 8-bit Red + 8-bit Green + 8-bit Blue.
RGB8 = citro3d_sys::GPU_RB_RGB8, RGB8 = ctru_sys::GPU_RB_RGB8,
/// 5-bit Red + 5-bit Green + 5-bit Blue + 1-bit Alpha. /// 5-bit Red + 5-bit Green + 5-bit Blue + 1-bit Alpha.
RGBA5551 = citro3d_sys::GPU_RB_RGBA5551, RGBA5551 = ctru_sys::GPU_RB_RGBA5551,
/// 5-bit Red + 6-bit Green + 5-bit Blue. /// 5-bit Red + 6-bit Green + 5-bit Blue.
RGB565 = citro3d_sys::GPU_RB_RGB565, RGB565 = ctru_sys::GPU_RB_RGB565,
/// 4-bit Red + 4-bit Green + 4-bit Blue + 4-bit Alpha. /// 4-bit Red + 4-bit Green + 4-bit Blue + 4-bit Alpha.
RGBA4 = citro3d_sys::GPU_RB_RGBA4, RGBA4 = ctru_sys::GPU_RB_RGBA4,
} }
impl From<FramebufferFormat> for ColorFormat { impl From<FramebufferFormat> for ColorFormat {
@ -132,11 +132,11 @@ impl From<FramebufferFormat> for ColorFormat {
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub enum DepthFormat { pub enum DepthFormat {
/// 16-bit depth. /// 16-bit depth.
Depth16 = citro3d_sys::GPU_RB_DEPTH16, Depth16 = ctru_sys::GPU_RB_DEPTH16,
/// 24-bit depth. /// 24-bit depth.
Depth24 = citro3d_sys::GPU_RB_DEPTH24, Depth24 = ctru_sys::GPU_RB_DEPTH24,
/// 24-bit depth + 8-bit Stencil. /// 24-bit depth + 8-bit Stencil.
Depth24Stencil8 = citro3d_sys::GPU_RB_DEPTH24_STENCIL8, Depth24Stencil8 = ctru_sys::GPU_RB_DEPTH24_STENCIL8,
} }
impl DepthFormat { impl DepthFormat {

13
citro3d/src/render/transfer.rs

@ -1,4 +1,5 @@
use citro3d_sys::{GX_TRANSFER_FORMAT, GX_TRANSFER_IN_FORMAT, GX_TRANSFER_OUT_FORMAT}; use citro3d_sys::{GX_TRANSFER_IN_FORMAT, GX_TRANSFER_OUT_FORMAT};
use ctru_sys::GX_TRANSFER_FORMAT;
use super::ColorFormat; use super::ColorFormat;
@ -33,15 +34,15 @@ impl Flags {
#[repr(u32)] #[repr(u32)]
pub enum Format { pub enum Format {
/// 8-bit Red + 8-bit Green + 8-bit Blue + 8-bit Alpha. /// 8-bit Red + 8-bit Green + 8-bit Blue + 8-bit Alpha.
RGBA8 = citro3d_sys::GX_TRANSFER_FMT_RGBA8, RGBA8 = ctru_sys::GX_TRANSFER_FMT_RGBA8,
/// 8-bit Red + 8-bit Green + 8-bit Blue. /// 8-bit Red + 8-bit Green + 8-bit Blue.
RGB8 = citro3d_sys::GX_TRANSFER_FMT_RGB8, RGB8 = ctru_sys::GX_TRANSFER_FMT_RGB8,
/// 5-bit Red + 5-bit Green + 5-bit Blue + 1-bit Alpha. /// 5-bit Red + 5-bit Green + 5-bit Blue + 1-bit Alpha.
RGB565 = citro3d_sys::GX_TRANSFER_FMT_RGB565, RGB565 = ctru_sys::GX_TRANSFER_FMT_RGB565,
/// 5-bit Red + 6-bit Green + 5-bit Blue. /// 5-bit Red + 6-bit Green + 5-bit Blue.
RGB5A1 = citro3d_sys::GX_TRANSFER_FMT_RGB5A1, RGB5A1 = ctru_sys::GX_TRANSFER_FMT_RGB5A1,
/// 4-bit Red + 4-bit Green + 4-bit Blue + 4-bit Alpha. /// 4-bit Red + 4-bit Green + 4-bit Blue + 4-bit Alpha.
RGBA4 = citro3d_sys::GX_TRANSFER_FMT_RGBA4, RGBA4 = ctru_sys::GX_TRANSFER_FMT_RGBA4,
} }
impl From<ColorFormat> for Format { impl From<ColorFormat> for Format {

26
citro3d/src/shader.rs

@ -16,7 +16,7 @@ pub mod macros;
/// ///
/// The PICA200 does not support user-programmable fragment shaders. /// The PICA200 does not support user-programmable fragment shaders.
pub struct Program { pub struct Program {
program: citro3d_sys::shaderProgram_s, program: ctru_sys::shaderProgram_s,
} }
impl Program { impl Program {
@ -30,14 +30,14 @@ impl Program {
pub fn new(vertex_shader: Entrypoint) -> Result<Self, ctru::Error> { pub fn new(vertex_shader: Entrypoint) -> Result<Self, ctru::Error> {
let mut program = unsafe { let mut program = unsafe {
let mut program = MaybeUninit::uninit(); let mut program = MaybeUninit::uninit();
let result = citro3d_sys::shaderProgramInit(program.as_mut_ptr()); let result = ctru_sys::shaderProgramInit(program.as_mut_ptr());
if result != 0 { if result != 0 {
return Err(ctru::Error::from(result)); return Err(ctru::Error::from(result));
} }
program.assume_init() program.assume_init()
}; };
let ret = unsafe { citro3d_sys::shaderProgramSetVsh(&mut program, vertex_shader.as_raw()) }; let ret = unsafe { ctru_sys::shaderProgramSetVsh(&mut program, vertex_shader.as_raw()) };
if ret == 0 { if ret == 0 {
Ok(Self { program }) Ok(Self { program })
@ -58,7 +58,7 @@ impl Program {
stride: u8, stride: u8,
) -> Result<(), ctru::Error> { ) -> Result<(), ctru::Error> {
let ret = unsafe { let ret = unsafe {
citro3d_sys::shaderProgramSetGsh(&mut self.program, geometry_shader.as_raw(), stride) ctru_sys::shaderProgramSetGsh(&mut self.program, geometry_shader.as_raw(), stride)
}; };
if ret == 0 { if ret == 0 {
@ -69,15 +69,15 @@ impl Program {
} }
// TODO: pub(crate) // TODO: pub(crate)
pub fn as_raw(&mut self) -> *mut citro3d_sys::shaderProgram_s { pub fn as_raw(&mut self) -> *mut ctru_sys::shaderProgram_s {
&mut self.program &mut self.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 _ = ctru_sys::shaderProgramFree(self.as_raw());
} }
} }
} }
@ -88,7 +88,7 @@ impl<'vert, 'geom> Drop for Program {
/// ///
/// This is the result of parsing a shader binary (shbin), and the resulting /// This is the result of parsing a shader binary (shbin), and the resulting
/// [`Entrypoint`]s can be used as part of a [`Program`]. /// [`Entrypoint`]s can be used as part of a [`Program`].
pub struct Library(*mut citro3d_sys::DVLB_s); pub struct Library(*mut ctru_sys::DVLB_s);
impl Library { impl Library {
/// Parse a new shader library from input bytes. /// Parse a new shader library from input bytes.
@ -100,7 +100,7 @@ impl Library {
pub fn from_bytes(bytes: &[u8]) -> Result<Self, Box<dyn Error>> { pub fn from_bytes(bytes: &[u8]) -> Result<Self, Box<dyn Error>> {
let aligned: &[u32] = bytemuck::try_cast_slice(bytes)?; let aligned: &[u32] = bytemuck::try_cast_slice(bytes)?;
Ok(Self(unsafe { Ok(Self(unsafe {
citro3d_sys::DVLB_ParseFile( ctru_sys::DVLB_ParseFile(
// SAFETY: we're trusting the parse implementation doesn't mutate // SAFETY: we're trusting the parse implementation doesn't mutate
// the contents of the data. From a quick read it looks like that's // the contents of the data. From a quick read it looks like that's
// correct and it should just take a const arg in the API. // correct and it should just take a const arg in the API.
@ -132,7 +132,7 @@ impl Library {
self.len() == 0 self.len() == 0
} }
fn as_raw(&mut self) -> *mut citro3d_sys::DVLB_s { fn as_raw(&mut self) -> *mut ctru_sys::DVLB_s {
self.0 self.0
} }
} }
@ -140,7 +140,7 @@ impl Library {
impl Drop for Library { impl Drop for Library {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
citro3d_sys::DVLB_Free(self.as_raw()); ctru_sys::DVLB_Free(self.as_raw());
} }
} }
} }
@ -149,12 +149,12 @@ impl Drop for Library {
/// vertex or a geometry shader. /// vertex or a geometry shader.
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub struct Entrypoint<'lib> { pub struct Entrypoint<'lib> {
ptr: *mut citro3d_sys::DVLE_s, ptr: *mut ctru_sys::DVLE_s,
_library: &'lib Library, _library: &'lib Library,
} }
impl<'lib> Entrypoint<'lib> { impl<'lib> Entrypoint<'lib> {
fn as_raw(self) -> *mut citro3d_sys::DVLE_s { fn as_raw(self) -> *mut ctru_sys::DVLE_s {
self.ptr self.ptr
} }
} }

Loading…
Cancel
Save