|
|
@ -48,6 +48,7 @@ impl Instance { |
|
|
|
/// # Errors
|
|
|
|
/// # Errors
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// Fails if `citro3d` cannot be initialized.
|
|
|
|
/// Fails if `citro3d` cannot be initialized.
|
|
|
|
|
|
|
|
#[doc(alias = "C3D_Init")] |
|
|
|
pub fn with_cmdbuf_size(size: usize) -> 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) |
|
|
@ -61,6 +62,7 @@ impl Instance { |
|
|
|
/// # Errors
|
|
|
|
/// # Errors
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// Fails if the given target cannot be used for drawing.
|
|
|
|
/// Fails if the given target cannot be used for drawing.
|
|
|
|
|
|
|
|
#[doc(alias = "C3D_FrameDrawOn")] |
|
|
|
pub fn select_render_target(&mut self, target: &render::Target<'_>) -> Result<()> { |
|
|
|
pub fn select_render_target(&mut self, target: &render::Target<'_>) -> Result<()> { |
|
|
|
let _ = self; |
|
|
|
let _ = self; |
|
|
|
if unsafe { citro3d_sys::C3D_FrameDrawOn(target.as_raw()) } { |
|
|
|
if unsafe { citro3d_sys::C3D_FrameDrawOn(target.as_raw()) } { |
|
|
@ -72,13 +74,13 @@ impl Instance { |
|
|
|
|
|
|
|
|
|
|
|
/// Render a frame. The passed in function/closure can mutate the instance,
|
|
|
|
/// Render a frame. The passed in function/closure can mutate the instance,
|
|
|
|
/// such as to [select a render target](Self::select_render_target).
|
|
|
|
/// such as to [select a render target](Self::select_render_target).
|
|
|
|
|
|
|
|
#[doc(alias = "C3D_FrameBegin")] |
|
|
|
|
|
|
|
#[doc(alias = "C3D_FrameEnd")] |
|
|
|
pub fn render_frame_with(&mut self, f: impl FnOnce(&mut Self)) { |
|
|
|
pub fn render_frame_with(&mut self, f: impl FnOnce(&mut Self)) { |
|
|
|
unsafe { |
|
|
|
unsafe { |
|
|
|
citro3d_sys::C3D_FrameBegin( |
|
|
|
citro3d_sys::C3D_FrameBegin( |
|
|
|
// TODO: begin + end flags should be configurable
|
|
|
|
// TODO: begin + end flags should be configurable
|
|
|
|
citro3d_sys::C3D_FRAME_SYNCDRAW |
|
|
|
citro3d_sys::C3D_FRAME_SYNCDRAW.try_into().unwrap(), |
|
|
|
.try_into() |
|
|
|
|
|
|
|
.expect("const is valid u8"), |
|
|
|
|
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -91,12 +93,14 @@ impl Instance { |
|
|
|
|
|
|
|
|
|
|
|
/// Get the buffer info being used, if it exists. Note that the resulting
|
|
|
|
/// Get the buffer info being used, if it exists. Note that the resulting
|
|
|
|
/// [`buffer::Info`] is copied from the one currently in use.
|
|
|
|
/// [`buffer::Info`] is copied from the one currently in use.
|
|
|
|
|
|
|
|
#[doc(alias = "C3D_GetBufInfo")] |
|
|
|
pub fn buffer_info(&self) -> Option<buffer::Info> { |
|
|
|
pub fn buffer_info(&self) -> Option<buffer::Info> { |
|
|
|
let raw = unsafe { citro3d_sys::C3D_GetBufInfo() }; |
|
|
|
let raw = unsafe { citro3d_sys::C3D_GetBufInfo() }; |
|
|
|
buffer::Info::copy_from(raw) |
|
|
|
buffer::Info::copy_from(raw) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Set the buffer info to use for any following draw calls.
|
|
|
|
/// Set the buffer info to use for any following draw calls.
|
|
|
|
|
|
|
|
#[doc(alias = "C3D_SetBufInfo")] |
|
|
|
pub fn set_buffer_info(&mut self, buffer_info: &buffer::Info) { |
|
|
|
pub fn set_buffer_info(&mut self, buffer_info: &buffer::Info) { |
|
|
|
let raw: *const _ = &buffer_info.0; |
|
|
|
let raw: *const _ = &buffer_info.0; |
|
|
|
// SAFETY: C3D_SetBufInfo actually copies the pointee instead of mutating it.
|
|
|
|
// SAFETY: C3D_SetBufInfo actually copies the pointee instead of mutating it.
|
|
|
@ -105,19 +109,22 @@ impl Instance { |
|
|
|
|
|
|
|
|
|
|
|
/// Get the attribute info being used, if it exists. Note that the resulting
|
|
|
|
/// Get the attribute info being used, if it exists. Note that the resulting
|
|
|
|
/// [`attrib::Info`] is copied from the one currently in use.
|
|
|
|
/// [`attrib::Info`] is copied from the one currently in use.
|
|
|
|
|
|
|
|
#[doc(alias = "C3D_GetAttrInfo")] |
|
|
|
pub fn attr_info(&self) -> Option<attrib::Info> { |
|
|
|
pub fn attr_info(&self) -> Option<attrib::Info> { |
|
|
|
let raw = unsafe { citro3d_sys::C3D_GetAttrInfo() }; |
|
|
|
let raw = unsafe { citro3d_sys::C3D_GetAttrInfo() }; |
|
|
|
attrib::Info::copy_from(raw) |
|
|
|
attrib::Info::copy_from(raw) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Set the attribute info to use for any following draw calls.
|
|
|
|
/// Set the attribute info to use for any following draw calls.
|
|
|
|
|
|
|
|
#[doc(alias = "C3D_SetAttrInfo")] |
|
|
|
pub fn set_attr_info(&mut self, attr_info: &attrib::Info) { |
|
|
|
pub fn set_attr_info(&mut self, attr_info: &attrib::Info) { |
|
|
|
let raw: *const _ = &attr_info.0; |
|
|
|
let raw: *const _ = &attr_info.0; |
|
|
|
// SAFETY: C3D_SetAttrInfo actually copies the pointee instead of mutating it.
|
|
|
|
// SAFETY: C3D_SetAttrInfo actually copies the pointee instead of mutating it.
|
|
|
|
unsafe { citro3d_sys::C3D_SetAttrInfo(raw.cast_mut()) }; |
|
|
|
unsafe { citro3d_sys::C3D_SetAttrInfo(raw.cast_mut()) }; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Draw the specified primitivearrays. The
|
|
|
|
/// Render primitives from the current vertex array buffer.
|
|
|
|
|
|
|
|
#[doc(alias = "C3D_DrawArrays")] |
|
|
|
pub fn draw_arrays(&mut self, primitive: buffer::Primitive, index: buffer::Slice) { |
|
|
|
pub fn draw_arrays(&mut self, primitive: buffer::Primitive, index: buffer::Slice) { |
|
|
|
self.set_buffer_info(index.info()); |
|
|
|
self.set_buffer_info(index.info()); |
|
|
|
|
|
|
|
|
|
|
@ -170,6 +177,7 @@ impl Instance { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl Drop for Instance { |
|
|
|
impl Drop for Instance { |
|
|
|
|
|
|
|
#[doc(alias = "C3D_Fini")] |
|
|
|
fn drop(&mut self) { |
|
|
|
fn drop(&mut self) { |
|
|
|
unsafe { |
|
|
|
unsafe { |
|
|
|
citro3d_sys::C3D_Fini(); |
|
|
|
citro3d_sys::C3D_Fini(); |
|
|
|