use bytemuck::{Pod,Zeroable};
use strafesnet_common::model::{IndexedVertex,PolygonGroup,RenderConfigId};
#[derive(Clone,Copy,Pod,Zeroable)]
#[repr(C)]
pub struct GraphicsVertex{
	pub pos:[f32;3],
	pub tex:[f32;2],
	pub normal:[f32;3],
	pub color:[f32;4],
}
#[derive(Clone,Copy,id::Id)]
pub struct IndexedGraphicsMeshOwnedRenderConfigId(u32);
pub struct IndexedGraphicsMeshOwnedRenderConfig{
	pub unique_pos:Vec<[f32;3]>,
	pub unique_tex:Vec<[f32;2]>,
	pub unique_normal:Vec<[f32;3]>,
	pub unique_color:Vec<[f32;4]>,
	pub unique_vertices:Vec<IndexedVertex>,
	pub render_config:RenderConfigId,
	pub polys:PolygonGroup,
	pub instances:Vec<GraphicsModelOwned>,
}
pub enum Indices{
	U32(Vec<u32>),
	U16(Vec<u16>),
}
pub struct GraphicsMeshOwnedRenderConfig{
	pub vertices:Vec<GraphicsVertex>,
	pub indices:Indices,
	pub render_config:RenderConfigId,
	pub instances:Vec<GraphicsModelOwned>,
}
#[derive(Clone)]
pub struct GraphicsModelOwned{
	pub transform:glam::Mat4,
	pub normal_transform:glam::Mat3,
	pub color:glam::Vec4,
	pub texture_color:glam::Vec4,
}
impl GraphicsModelOwned{
	pub fn hashable_color(&self)->HashableColor{
		HashableColor([bytemuck::cast::<[f32;4],[u32;4]>(self.color.to_array()),bytemuck::cast::<[f32;4],[u32;4]>(self.texture_color.to_array())])
	}
}
#[derive(Clone,Copy,Eq,Hash,PartialEq)]
pub struct HashableColor([[u32;4];2]);
impl HashableColor{
	pub fn color(self)->(glam::Vec4,glam::Vec4){
		let [color,texture_color]=bytemuck::cast::<[[u32;4];2],[[f32;4];2]>(self.0);
		(glam::Vec4::from_array(color),glam::Vec4::from_array(texture_color))
	}
}
