Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: drawing gltf nodes #67

Merged
merged 5 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading