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

8
citro3d/src/lib.rs

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

16
citro3d/src/texenv.rs

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

Loading…
Cancel
Save