Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion citro3d/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ impl<'instance> Frame<'instance> {
}

/// Use the given [`shader::Program`] for the following draw calls.
pub fn bind_program(&mut self, program: &'instance shader::Program) {
pub fn bind_program(&mut self, program: &'instance shader::Program<'_>) {
// SAFETY: AFAICT C3D_BindProgram just copies pointers from the given program,
// instead of mutating the pointee in any way that would cause UB
unsafe {
Expand Down
17 changes: 11 additions & 6 deletions citro3d/src/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use std::error::Error;
use std::ffi::CString;
use std::marker::PhantomData;
use std::mem::MaybeUninit;

use crate::uniform;
Expand All @@ -18,11 +19,12 @@ use crate::uniform;
/// The PICA200 does not support user-programmable fragment shaders.
#[doc(alias = "shaderProgram_s")]
#[must_use]
pub struct Program {
pub struct Program<'lib> {
program: ctru_sys::shaderProgram_s,
_lib: PhantomData<&'lib Library>,
}

impl Program {
impl<'lib> Program<'lib> {
/// Create a new shader program from a vertex shader.
///
/// # Errors
Expand All @@ -32,7 +34,7 @@ impl Program {
/// * the input shader is not a vertex shader or is otherwise invalid
#[doc(alias = "shaderProgramInit")]
#[doc(alias = "shaderProgramSetVsh")]
pub fn new(vertex_shader: Entrypoint) -> Result<Self, ctru::Error> {
pub fn new(vertex_shader: Entrypoint<'lib>) -> Result<Self, ctru::Error> {
let mut program = unsafe {
let mut program = MaybeUninit::uninit();
let result = ctru_sys::shaderProgramInit(program.as_mut_ptr());
Expand All @@ -45,7 +47,10 @@ impl Program {
let ret = unsafe { ctru_sys::shaderProgramSetVsh(&mut program, vertex_shader.as_raw()) };

if ret == 0 {
Ok(Self { program })
Ok(Self {
program,
_lib: PhantomData,
})
} else {
Err(ctru::Error::from(ret))
}
Expand All @@ -60,7 +65,7 @@ impl Program {
#[doc(alias = "shaderProgramSetGsh")]
pub fn set_geometry_shader(
&mut self,
geometry_shader: Entrypoint,
geometry_shader: Entrypoint<'lib>,
stride: u8,
) -> Result<(), ctru::Error> {
let ret = unsafe {
Expand Down Expand Up @@ -105,7 +110,7 @@ impl Program {
}
}

impl Drop for Program {
impl<'lib> Drop for Program<'lib> {
#[doc(alias = "shaderProgramFree")]
fn drop(&mut self) {
unsafe {
Expand Down