Galactica/crates/render/src/globaluniform/object.rs

51 lines
1019 B
Rust
Raw Normal View History

use bytemuck::{Pod, Zeroable};
use galactica_constants::OBJECT_SPRITE_INSTANCE_LIMIT;
use std::mem;
use wgpu;
#[repr(C)]
#[derive(Debug, Copy, Clone, Pod, Zeroable, Default)]
2024-01-06 14:02:50 -08:00
pub struct ObjectData {
pub xpos: f32,
pub ypos: f32,
pub zpos: f32,
pub angle: f32,
pub size: f32,
2024-01-06 14:02:50 -08:00
/// Index of parent object
pub parent: u32,
/// 1 if has parent, 0 if not
pub is_child: u32,
pub _padding: [f32; 1],
}
2024-01-06 14:02:50 -08:00
impl ObjectData {
pub const SIZE: u64 = mem::size_of::<Self>() as wgpu::BufferAddress;
}
#[derive(Debug, Copy, Clone)]
pub struct ObjectLocationArray {
2024-01-06 14:02:50 -08:00
pub data: [ObjectData; OBJECT_SPRITE_INSTANCE_LIMIT as usize],
}
unsafe impl Pod for ObjectLocationArray {}
unsafe impl Zeroable for ObjectLocationArray {
fn zeroed() -> Self {
Self {
2024-01-06 14:02:50 -08:00
data: [ObjectData::zeroed(); OBJECT_SPRITE_INSTANCE_LIMIT as usize],
}
}
}
impl Default for ObjectLocationArray {
fn default() -> Self {
Self::zeroed()
}
}
impl ObjectLocationArray {
pub const SIZE: u64 = mem::size_of::<Self>() as wgpu::BufferAddress;
}