Skip to content

Commit 7713b18

Browse files
authored
feat: drawing gltf nodes (#67)
* 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
1 parent 426a032 commit 7713b18

17 files changed

+1861
-204
lines changed

crates/renderling-shader/src/array.rs

+32-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use crate::slab::Slabbed;
66

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

2628
impl<T> core::fmt::Debug for Array<T> {
2729
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
28-
f.debug_struct("Array")
29-
.field("index", &self.index)
30-
.field("len", &self.len)
31-
.field("_phantom", &self._phantom)
32-
.finish()
30+
f.debug_struct(if self.is_null() {
31+
"Array (null)"
32+
} else {
33+
"Array"
34+
})
35+
.field("index", &self.index)
36+
.field("len", &self.len)
37+
.field("_phantom", &self._phantom)
38+
.finish()
3339
}
3440
}
3541

@@ -75,7 +81,7 @@ impl<T: Slabbed> Default for Array<T> {
7581
}
7682
}
7783

78-
impl<T: Slabbed> Array<T> {
84+
impl<T> Array<T> {
7985
pub fn new(index: u32, len: u32) -> Self {
8086
Self {
8187
index,
@@ -92,11 +98,18 @@ impl<T: Slabbed> Array<T> {
9298
self.len == 0
9399
}
94100

101+
pub fn is_null(&self) -> bool {
102+
self.index == u32::MAX
103+
}
104+
95105
pub fn contains_index(&self, index: usize) -> bool {
96106
index >= self.index as usize && index < (self.index + self.len) as usize
97107
}
98108

99-
pub fn at(&self, index: usize) -> Id<T> {
109+
pub fn at(&self, index: usize) -> Id<T>
110+
where
111+
T: Slabbed,
112+
{
100113
if index >= self.len() {
101114
Id::NONE
102115
} else {
@@ -107,4 +120,16 @@ impl<T: Slabbed> Array<T> {
107120
pub fn starting_index(&self) -> usize {
108121
self.index as usize
109122
}
123+
124+
/// Convert this array into a `u32` array.
125+
pub fn into_u32_array(self) -> Array<u32>
126+
where
127+
T: Slabbed,
128+
{
129+
Array {
130+
index: self.index,
131+
len: self.len * T::slab_size() as u32,
132+
_phantom: PhantomData,
133+
}
134+
}
110135
}

0 commit comments

Comments
 (0)