Skip to content

Commit

Permalink
feat: drawing gltf nodes (#67)
Browse files Browse the repository at this point in the history
* WIP drawing gltf nodes

* better accessor support

* extract u8,i8,u16,i16 in shaders as u32,i32

* successfully rendering simple gltf files w/ the new gpu-driven gltf pipeline

* fixed typo causing scene tangent errors
  • Loading branch information
schell authored Dec 6, 2023
1 parent c8121d4 commit 180c325
Show file tree
Hide file tree
Showing 17 changed files with 1,861 additions and 204 deletions.
39 changes: 32 additions & 7 deletions crates/renderling-shader/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use crate::slab::Slabbed;

#[repr(C)]
pub struct Array<T> {
// u32 offset in the slab
index: u32,
// number of `T` elements in the array
len: u32,
_phantom: PhantomData<T>,
}
Expand All @@ -25,11 +27,15 @@ impl<T> Copy for Array<T> {}

impl<T> core::fmt::Debug for Array<T> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("Array")
.field("index", &self.index)
.field("len", &self.len)
.field("_phantom", &self._phantom)
.finish()
f.debug_struct(if self.is_null() {
"Array (null)"
} else {
"Array"
})
.field("index", &self.index)
.field("len", &self.len)
.field("_phantom", &self._phantom)
.finish()
}
}

Expand Down Expand Up @@ -75,7 +81,7 @@ impl<T: Slabbed> Default for Array<T> {
}
}

impl<T: Slabbed> Array<T> {
impl<T> Array<T> {
pub fn new(index: u32, len: u32) -> Self {
Self {
index,
Expand All @@ -92,11 +98,18 @@ impl<T: Slabbed> Array<T> {
self.len == 0
}

pub fn is_null(&self) -> bool {
self.index == u32::MAX
}

pub fn contains_index(&self, index: usize) -> bool {
index >= self.index as usize && index < (self.index + self.len) as usize
}

pub fn at(&self, index: usize) -> Id<T> {
pub fn at(&self, index: usize) -> Id<T>
where
T: Slabbed,
{
if index >= self.len() {
Id::NONE
} else {
Expand All @@ -107,4 +120,16 @@ impl<T: Slabbed> Array<T> {
pub fn starting_index(&self) -> usize {
self.index as usize
}

/// Convert this array into a `u32` array.
pub fn into_u32_array(self) -> Array<u32>
where
T: Slabbed,
{
Array {
index: self.index,
len: self.len * T::slab_size() as u32,
_phantom: PhantomData,
}
}
}
Loading

0 comments on commit 180c325

Please sign in to comment.