Browse Source

Minor cleanups

pull/33/head
Ian Chamberlain 1 year ago
parent
commit
0fbd4418d8
No known key found for this signature in database
GPG Key ID: AE5484D09405AA60
  1. 26
      citro3d/examples/triangle.rs
  2. 8
      citro3d/src/lib.rs
  3. 16
      citro3d/src/texenv.rs

26
citro3d/examples/triangle.rs

@ -48,6 +48,7 @@ static VERTICES: &[Vertex] = &[
]; ];
static SHADER_BYTES: &[u8] = include_shader!("assets/vshader.pica"); static SHADER_BYTES: &[u8] = include_shader!("assets/vshader.pica");
const CLEAR_COLOR: u32 = 0x68_B0_D8_FF;
fn main() { fn main() {
let mut soc = Soc::new().expect("failed to get SOC"); let mut soc = Soc::new().expect("failed to get SOC");
@ -87,12 +88,13 @@ fn main() {
vbo_data.extend_from_slice(VERTICES); vbo_data.extend_from_slice(VERTICES);
let mut buf_info = buffer::Info::new(); let mut buf_info = buffer::Info::new();
let (attr_info, vbo_idx) = prepare_vbos(&mut buf_info, &vbo_data); let (attr_info, vbo_data) = prepare_vbos(&mut buf_info, &vbo_data);
// Configure the first fragment shading substage to just pass through the vertex color // Configure the first fragment shading substage to just pass through the vertex color
// See https://www.opengl.org/sdk/docs/man2/xhtml/glTexEnv.xml for more insight // See https://www.opengl.org/sdk/docs/man2/xhtml/glTexEnv.xml for more insight
let stage0 = texenv::Stage::new(0).unwrap();
instance instance
.texenv(texenv::Stage::new(0).unwrap()) .texenv(stage0)
.src(texenv::Mode::BOTH, texenv::Source::PrimaryColor, None, None) .src(texenv::Mode::BOTH, texenv::Source::PrimaryColor, None, None)
.func(texenv::Mode::BOTH, texenv::CombineFunc::Replace); .func(texenv::Mode::BOTH, texenv::CombineFunc::Replace);
@ -107,18 +109,17 @@ fn main() {
instance.render_frame_with(|instance| { instance.render_frame_with(|instance| {
let mut render_to = |target: &mut render::Target, projection| { let mut render_to = |target: &mut render::Target, projection| {
target.clear(ClearFlags::ALL, CLEAR_COLOR, 0);
instance instance
.select_render_target(target) .select_render_target(target)
.expect("failed to set render target"); .expect("failed to set render target");
let clear_color: u32 = 0x7F_7F_7F_FF;
target.clear(ClearFlags::ALL, clear_color, 0);
instance.bind_vertex_uniform(projection_uniform_idx, projection); instance.bind_vertex_uniform(projection_uniform_idx, projection);
instance.set_attr_info(&attr_info); instance.set_attr_info(&attr_info);
instance.draw_arrays(buffer::Primitive::Triangles, vbo_idx); instance.draw_arrays(buffer::Primitive::Triangles, vbo_data);
}; };
let Projections { let Projections {
@ -134,15 +135,10 @@ fn main() {
} }
} }
// sheeeesh, this sucks to type: fn prepare_vbos<'a>(
fn prepare_vbos<'buf, 'info, 'vbo>( buf_info: &'a mut buffer::Info,
buf_info: &'info mut buffer::Info, vbo_data: &'a [Vertex],
vbo_data: &'vbo [Vertex], ) -> (attrib::Info, buffer::Slice<'a>) {
) -> (attrib::Info, buffer::Slice<'buf>)
where
'info: 'buf,
'vbo: 'buf,
{
// Configure attributes for use with the vertex shader // Configure attributes for use with the vertex shader
let mut attr_info = attrib::Info::new(); let mut attr_info = attrib::Info::new();

8
citro3d/src/lib.rs

@ -148,16 +148,16 @@ impl Instance {
/// Render primitives from the current vertex array buffer. /// Render primitives from the current vertex array buffer.
#[doc(alias = "C3D_DrawArrays")] #[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, vbo_data: buffer::Slice) {
self.set_buffer_info(index.info()); self.set_buffer_info(vbo_data.info());
// TODO: should we also require the attrib info directly here? // TODO: should we also require the attrib info directly here?
unsafe { unsafe {
citro3d_sys::C3D_DrawArrays( citro3d_sys::C3D_DrawArrays(
primitive as ctru_sys::GPU_Primitive_t, primitive as ctru_sys::GPU_Primitive_t,
index.index(), vbo_data.index(),
index.len(), vbo_data.len(),
); );
} }
} }

16
citro3d/src/texenv.rs

@ -6,20 +6,14 @@ use bitflags::bitflags;
/// A texture combiner, also called a "texture environment" (hence the struct name). /// A texture combiner, also called a "texture environment" (hence the struct name).
/// See also [`texenv.h` documentation](https://oreo639.github.io/citro3d/texenv_8h.html). /// See also [`texenv.h` documentation](https://oreo639.github.io/citro3d/texenv_8h.html).
#[doc(alias = "C3D_TexEnv")] #[doc(alias = "C3D_TexEnv")]
pub struct TexEnv { pub struct TexEnv(*mut citro3d_sys::C3D_TexEnv);
raw: *mut citro3d_sys::C3D_TexEnv,
}
// https://oreo639.github.io/citro3d/texenv_8h.html#a9eda91f8e7252c91f873b1d43e3728b6 // https://oreo639.github.io/citro3d/texenv_8h.html#a9eda91f8e7252c91f873b1d43e3728b6
pub(crate) const TEXENV_COUNT: usize = 6; pub(crate) const TEXENV_COUNT: usize = 6;
impl TexEnv { impl TexEnv {
pub(crate) fn new(stage: Stage) -> Self { pub(crate) fn new(stage: Stage) -> Self {
let mut result = unsafe { let mut result = unsafe { Self(citro3d_sys::C3D_GetTexEnv(stage.0 as _)) };
Self {
raw: citro3d_sys::C3D_GetTexEnv(stage.0 as _),
}
};
result.reset(); result.reset();
result result
} }
@ -27,7 +21,7 @@ impl TexEnv {
/// Re-initialize the texture combiner to its default state. /// Re-initialize the texture combiner to its default state.
pub fn reset(&mut self) { pub fn reset(&mut self) {
unsafe { unsafe {
citro3d_sys::C3D_TexEnvInit(self.raw); citro3d_sys::C3D_TexEnvInit(self.0);
} }
} }
@ -48,7 +42,7 @@ impl TexEnv {
) -> &mut Self { ) -> &mut Self {
unsafe { unsafe {
citro3d_sys::C3D_TexEnvSrc( citro3d_sys::C3D_TexEnvSrc(
self.raw, self.0,
mode.bits(), mode.bits(),
source0 as _, source0 as _,
source1.unwrap_or(Source::PrimaryColor) as _, source1.unwrap_or(Source::PrimaryColor) as _,
@ -67,7 +61,7 @@ impl TexEnv {
#[doc(alias = "C3D_TexEnvFunc")] #[doc(alias = "C3D_TexEnvFunc")]
pub fn func(&mut self, mode: Mode, func: CombineFunc) -> &mut Self { pub fn func(&mut self, mode: Mode, func: CombineFunc) -> &mut Self {
unsafe { unsafe {
citro3d_sys::C3D_TexEnvFunc(self.raw, mode.bits(), func as _); citro3d_sys::C3D_TexEnvFunc(self.0, mode.bits(), func as _);
} }
self self

Loading…
Cancel
Save