Skip to content

Commit

Permalink
feat: add_bytes for buffer::Info
Browse files Browse the repository at this point in the history
  • Loading branch information
0x00002a committed Feb 15, 2024
1 parent 8d241b1 commit d235e1a
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions citro3d/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,46 @@ impl Info {
'this: 'idx,
'vbo: 'idx,
{
let stride = std::mem::size_of::<T>().try_into()?;
unsafe {
self.add_bytes(
std::slice::from_raw_parts(
vbo_data.as_ptr().cast(),
std::mem::size_of_val(vbo_data),
),
attrib_info,
std::mem::size_of::<T>() as u32,
)
}
}

/// Add vbo bytes directly
///
/// This is the same as [`Info::add`] except it requires manually specifying the
/// stride for each set of attributes, this is useful if you don't know the size
/// at compile time
///
/// # Safety
/// `vbo_data` must have data matching `attrib_info` every `stride` bytes or strangeness
/// will occur
#[doc(alias = "BufInfo_Add")]
pub unsafe fn add_bytes<'this, 'vbo, 'idx>(
&'this mut self,
vbo_data: &'vbo [u8],
attrib_info: &attrib::Info,
stride: u32,
) -> crate::Result<Slice<'idx>>
where
'this: 'idx,
'vbo: 'idx,
{
// SAFETY: the lifetime of the VBO data is encapsulated in the return value's
// 'vbo lifetime, and the pointer to &mut self.0 is used to access values
// in the BufInfo, not copied to be used later.
let res = unsafe {
citro3d_sys::BufInfo_Add(
&mut self.0,
vbo_data.as_ptr().cast(),
stride,
stride as isize,
attrib_info.attr_count(),
attrib_info.permutation(),
)
Expand Down

0 comments on commit d235e1a

Please sign in to comment.