This repository has been archived by the owner on Nov 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from novorender/wasm_bindgen_parser
Full wasm bindgen parser
- Loading branch information
Showing
12 changed files
with
1,675 additions
and
537 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std::mem::size_of; | ||
|
||
pub fn copy_to_interleaved_array<T: Copy + Send + Sync>(dst: &mut [T], src: &[T], byte_offset: usize, byte_stride: usize, begin: usize, end: usize) { | ||
debug_assert_eq!(byte_offset % size_of::<T>(), 0); | ||
debug_assert_eq!(byte_stride % size_of::<T>(), 0); | ||
|
||
let offset = byte_offset / size_of::<T>(); | ||
let stride = byte_stride / size_of::<T>(); | ||
|
||
for (dst, src) in dst[offset..].iter_mut().step_by(stride).zip(&src[begin..end]) { | ||
*dst = *src | ||
} | ||
} | ||
|
||
|
||
pub fn fill_to_interleaved_array<T: Copy + Send + Sync>(dst: &mut [T], src: T, byte_offset: usize, byte_stride: usize, begin: usize, end: usize) { | ||
debug_assert_eq!(byte_offset % size_of::<T>(), 0); | ||
debug_assert_eq!(byte_stride % size_of::<T>(), 0); | ||
|
||
let offset = byte_offset / size_of::<T>(); | ||
let stride = byte_stride / size_of::<T>(); | ||
|
||
let end = (offset + stride * (end - begin)).min(dst.len()); | ||
|
||
for dst in dst[offset..end].iter_mut().step_by(stride) { | ||
*dst = src; | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use std::mem::size_of; | ||
|
||
#[test] | ||
fn test_copy_interleaved() { | ||
let src = [0f32, 1., 2., 3., 4., 5., 6.]; | ||
let mut dst = [0.; 14]; | ||
super::copy_to_interleaved_array(&mut dst, &src, size_of::<f32>() * 2, size_of::<f32>() * 2, 1, 7); | ||
assert_eq!(dst, [0., 0., 1., 0., 2., 0., 3., 0., 4., 0., 5., 0., 6., 0.]); | ||
} | ||
|
||
#[test] | ||
fn test_fill_interleaved() { | ||
let src = 1.; | ||
let mut dst = [0f32; 14]; | ||
super::fill_to_interleaved_array(&mut dst, src, size_of::<f32>() * 2, size_of::<f32>() * 2, 1, 7); | ||
assert_eq!(dst, [0., 0., 1., 0., 1., 0., 1., 0., 1., 0., 1., 0., 1., 0.]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen] | ||
#[derive(Clone)] | ||
pub struct TextureParameters { | ||
#[wasm_bindgen(skip)] | ||
pub kind: &'static str, | ||
#[wasm_bindgen(skip)] | ||
pub internal_format: &'static str, | ||
pub ty: u32, | ||
pub width: u32, | ||
pub height: u32, | ||
pub depth: u32, | ||
#[wasm_bindgen(skip)] | ||
pub image_data: Vec<u8>, | ||
} | ||
|
||
pub fn parse_ktx(ktx: &[u8]) -> TextureParameters { | ||
// TODO: | ||
TextureParameters { | ||
kind: "TEXTURE_2D", | ||
internal_format: "GL_RGBA8", | ||
ty: gl::BYTE, | ||
width: 1, | ||
height: 1, | ||
depth: 1, | ||
image_data: vec![0, 0, 0, 1], | ||
} | ||
} |
Oops, something went wrong.