Browse Source

Move draw call to Instance

Also add some notes about error handling for adding VBO data
pull/16/head
Ian Chamberlain 2 years ago
parent
commit
a645ba14df
No known key found for this signature in database
GPG Key ID: AE5484D09405AA60
  1. 2
      citro3d/examples/triangle.rs
  2. 6
      citro3d/src/buffers.rs
  3. 10
      citro3d/src/lib.rs
  4. 12
      citro3d/src/render.rs

2
citro3d/examples/triangle.rs

@ -110,7 +110,7 @@ fn main() {
); );
} }
target.draw_arrays(buffers::Primitive::Triangles, vbo_idx); instance.draw_arrays(buffers::Primitive::Triangles, vbo_idx);
}); });
}; };

6
citro3d/src/buffers.rs

@ -83,6 +83,12 @@ impl BufInfo {
}; };
if res < 0 { if res < 0 {
// TODO: should we convert to a more specific error if this fails?
// It looks like the common cases are
// - too many buffers already added (max 12)
// - physical memory address in the wrong place (this can be seen by
// using default allocator instead of LinearAllocator)
// <https://github.com/devkitPro/citro3d/blob/master/source/buffers.c#L13-L17>
Err(crate::Error::System(res)) Err(crate::Error::System(res))
} else { } else {
Ok(Index { Ok(Index {

10
citro3d/src/lib.rs

@ -73,6 +73,16 @@ impl Instance {
citro3d_sys::C3D_FrameEnd(0); citro3d_sys::C3D_FrameEnd(0);
} }
} }
pub fn draw_arrays(&mut self, primitive: buffers::Primitive, index: buffers::Index) {
unsafe {
citro3d_sys::C3D_DrawArrays(
primitive as ctru_sys::GPU_Primitive_t,
index.as_raw(),
index.size(),
);
}
}
} }
impl Drop for Instance { impl Drop for Instance {

12
citro3d/src/render.rs

@ -10,7 +10,7 @@ use ctru::gfx::Screen;
use ctru::services::gspgpu::FramebufferFormat; use ctru::services::gspgpu::FramebufferFormat;
use ctru_sys::{GPU_COLORBUF, GPU_DEPTHBUF}; use ctru_sys::{GPU_COLORBUF, GPU_DEPTHBUF};
use crate::{buffers, Error, Result}; use crate::{Error, Result};
mod transfer; mod transfer;
@ -91,16 +91,6 @@ impl<'screen> Target<'screen> {
pub(crate) fn as_raw(&self) -> *mut C3D_RenderTarget { pub(crate) fn as_raw(&self) -> *mut C3D_RenderTarget {
self.raw self.raw
} }
pub fn draw_arrays(&mut self, primitive: buffers::Primitive, index: buffers::Index) {
unsafe {
citro3d_sys::C3D_DrawArrays(
primitive as ctru_sys::GPU_Primitive_t,
index.as_raw(),
index.size(),
);
}
}
} }
bitflags::bitflags! { bitflags::bitflags! {

Loading…
Cancel
Save