use crate::{SsbhArray, SsbhString, SsbhString8, Version};
use binrw::BinRead;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use ssbh_write::SsbhWrite;
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, BinRead, SsbhWrite, Clone, PartialEq)]
#[br(import(major_version: u16, minor_version: u16))]
pub enum Nufx {
#[br(pre_assert(major_version == 1 && minor_version == 0))]
V0(NufxV0),
#[br(pre_assert(major_version == 1 && minor_version == 1))]
V1(NufxV1),
}
impl Version for Nufx {
fn major_minor_version(&self) -> (u16, u16) {
match self {
Nufx::V0(_) => (1, 0),
Nufx::V1(_) => (1, 1),
}
}
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, BinRead, SsbhWrite, Clone, PartialEq)]
pub struct NufxV0 {
pub programs: SsbhArray<ShaderProgramV0>,
pub unk_string_list: SsbhArray<UnkItem>,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, BinRead, SsbhWrite, Clone, PartialEq)]
pub struct NufxV1 {
pub programs: SsbhArray<ShaderProgramV1>,
pub unk_string_list: SsbhArray<UnkItem>,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, BinRead, SsbhWrite, Clone, PartialEq)]
pub struct VertexAttribute {
pub name: SsbhString,
pub attribute_name: SsbhString,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, BinRead, SsbhWrite, Clone, PartialEq)]
#[ssbhwrite(pad_after = 8)]
pub struct MaterialParameter {
pub param_id: u64,
#[br(pad_after = 8)]
pub parameter_name: SsbhString8,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, BinRead, SsbhWrite, Clone, PartialEq)]
pub struct ShaderStages {
pub vertex_shader: SsbhString,
pub unk_shader1: SsbhString, pub unk_shader2: SsbhString,
pub geometry_shader: SsbhString,
pub pixel_shader: SsbhString,
pub compute_shader: SsbhString,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, BinRead, SsbhWrite, Clone, PartialEq)]
pub struct ShaderProgramV0 {
pub name: SsbhString,
pub render_pass: SsbhString,
pub shaders: ShaderStages,
pub material_parameters: SsbhArray<MaterialParameter>,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, BinRead, SsbhWrite, Clone, PartialEq)]
pub struct ShaderProgramV1 {
pub name: SsbhString,
pub render_pass: SsbhString,
pub shaders: ShaderStages,
pub vertex_attributes: SsbhArray<VertexAttribute>,
pub material_parameters: SsbhArray<MaterialParameter>,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, BinRead, SsbhWrite, Clone, PartialEq)]
pub struct UnkItem {
pub name: SsbhString,
pub unk1: SsbhArray<SsbhString>,
}