mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
This will make it easier for contributors to understand the file layout,
at the cost of said layout containing several more nested directories.
I will personally appreciate not having to remember to look for
`root.rs` instead of `main.rs`.
I also renamed the test targets so that they do not *all* share the
superfluous suffix “-test” (test targets live in a different namespace
than other target types and packages, so the name can presume that it
is always known that they are tests).
The Naga snapshot data sets `naga/tests/{in,out}` have been left in
their original positions.
84 lines
2.2 KiB
Rust
84 lines
2.2 KiB
Rust
use bytemuck::{Pod, Zeroable};
|
|
use glam::Affine3A;
|
|
|
|
#[repr(C)]
|
|
#[derive(Clone, Copy, Pod, Zeroable)]
|
|
pub struct Vertex {
|
|
_pos: [f32; 4],
|
|
_tex_coord: [f32; 2],
|
|
}
|
|
|
|
fn vertex(pos: [i8; 3], tc: [i8; 2]) -> Vertex {
|
|
Vertex {
|
|
_pos: [pos[0] as f32, pos[1] as f32, pos[2] as f32, 1.0],
|
|
_tex_coord: [tc[0] as f32, tc[1] as f32],
|
|
}
|
|
}
|
|
|
|
pub fn create_vertices() -> (Vec<Vertex>, Vec<u16>) {
|
|
let vertex_data = [
|
|
// top (0, 0, 1)
|
|
vertex([-1, -1, 1], [0, 0]),
|
|
vertex([1, -1, 1], [1, 0]),
|
|
vertex([1, 1, 1], [1, 1]),
|
|
vertex([-1, 1, 1], [0, 1]),
|
|
// bottom (0, 0, -1)
|
|
vertex([-1, 1, -1], [1, 0]),
|
|
vertex([1, 1, -1], [0, 0]),
|
|
vertex([1, -1, -1], [0, 1]),
|
|
vertex([-1, -1, -1], [1, 1]),
|
|
// right (1, 0, 0)
|
|
vertex([1, -1, -1], [0, 0]),
|
|
vertex([1, 1, -1], [1, 0]),
|
|
vertex([1, 1, 1], [1, 1]),
|
|
vertex([1, -1, 1], [0, 1]),
|
|
// left (-1, 0, 0)
|
|
vertex([-1, -1, 1], [1, 0]),
|
|
vertex([-1, 1, 1], [0, 0]),
|
|
vertex([-1, 1, -1], [0, 1]),
|
|
vertex([-1, -1, -1], [1, 1]),
|
|
// front (0, 1, 0)
|
|
vertex([1, 1, -1], [1, 0]),
|
|
vertex([-1, 1, -1], [0, 0]),
|
|
vertex([-1, 1, 1], [0, 1]),
|
|
vertex([1, 1, 1], [1, 1]),
|
|
// back (0, -1, 0)
|
|
vertex([1, -1, 1], [0, 0]),
|
|
vertex([-1, -1, 1], [1, 0]),
|
|
vertex([-1, -1, -1], [1, 1]),
|
|
vertex([1, -1, -1], [0, 1]),
|
|
];
|
|
|
|
let index_data: &[u16] = &[
|
|
0, 1, 2, 2, 3, 0, // top
|
|
4, 5, 6, 6, 7, 4, // bottom
|
|
8, 9, 10, 10, 11, 8, // right
|
|
12, 13, 14, 14, 15, 12, // left
|
|
16, 17, 18, 18, 19, 16, // front
|
|
20, 21, 22, 22, 23, 20, // back
|
|
];
|
|
|
|
(vertex_data.to_vec(), index_data.to_vec())
|
|
}
|
|
|
|
pub fn affine_to_rows(mat: &Affine3A) -> [f32; 12] {
|
|
let row_0 = mat.matrix3.row(0);
|
|
let row_1 = mat.matrix3.row(1);
|
|
let row_2 = mat.matrix3.row(2);
|
|
let translation = mat.translation;
|
|
[
|
|
row_0.x,
|
|
row_0.y,
|
|
row_0.z,
|
|
translation.x,
|
|
row_1.x,
|
|
row_1.y,
|
|
row_1.z,
|
|
translation.y,
|
|
row_2.x,
|
|
row_2.y,
|
|
row_2.z,
|
|
translation.z,
|
|
]
|
|
}
|