/*
    wearechat - generic multiplayer game with voip
    Copyright (C) 2025 metamuffin
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, version 3 of the License only.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.
    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see .
*/
use glam::Mat4;
use std::sync::Arc;
use weareshared::resources::Armature;
use wgpu::{Buffer, BufferDescriptor, BufferUsages, Device, Queue};
const MAX_JOINTS: usize = 128;
pub struct RArmature {
    pub joint_mat_uniform_buffer: Arc,
    joint_mat: Vec,
    _data: Armature,
}
impl RArmature {
    pub fn new(device: &Device, armature: Armature) -> Self {
        Self {
            joint_mat_uniform_buffer: Arc::new(device.create_buffer(&BufferDescriptor {
                label: Some("joint uniform"),
                size: (MAX_JOINTS * size_of::() * 16) as u64,
                usage: BufferUsages::COPY_DST | BufferUsages::UNIFORM,
                mapped_at_creation: false,
            })),
            _data: armature,
            joint_mat: vec![],
        }
    }
    pub fn update(&mut self) {
        self.joint_mat.fill(Mat4::IDENTITY);
    }
    pub fn write_uniform(&self, queue: &Queue) {
        queue.write_buffer(
            &self.joint_mat_uniform_buffer,
            0,
            bytemuck::cast_slice(self.joint_mat.as_slice()),
        );
    }
}