use crate::texture::{ColorTexture, DepthTexture};
use open_enum::open_enum;
macro_rules! bitfield_bit {
($field:ident << $shift:expr) => {
((if $field { 1 } else { 0 }) << $shift)
};
($field:ident, $($fields:ident),+ << $shift:expr) => {
bitfield_bit!($field << $shift)
| bitfield_bit!($($fields),+ << $shift + 1)
};
}
macro_rules! enum_bitfield {
($base_name:ident, $name:ident($($field:ident),+ $(,)?)) => {
#[allow(non_snake_case)]
#[inline]
pub(crate) fn $name($($field: bool),+) -> Self {
Self(
Self::$base_name.0
| bitfield_bit!($($field),+ << 0)
)
}
};
}
macro_rules! enum_effectfield {
($base_name:ident, $name:ident($($texture:ident: Option<$textureType:ty>),+ $(,)?)) => {
#[allow(non_snake_case)]
#[inline]
pub(crate) fn $name($($texture: Option<$textureType>),*) -> Self {
Self(
Self::$base_name.0
$( | $texture.map(|t| t.id()).unwrap_or(0))*
)
}
};
($base_name:ident, $name:ident(Option<...Default>)) => {
enum_effectfield!($base_name, $name(color_texture: Option<ColorTexture>, depth_texture: Option<DepthTexture>));
};
($base_name:ident, $name:ident($($texture:ident: $textureType:ty),+ $(,)?)) => {
#[allow(non_snake_case)]
#[inline]
pub(crate) fn $name($($texture: $textureType),*) -> Self {
Self(
Self::$base_name.0
$( | $texture.id())*
)
}
};
($base_name:ident, $name:ident(...Default)) => {
enum_effectfield!($base_name, $name(color_texture: ColorTexture, depth_texture: DepthTexture));
};
}
#[allow(missing_docs)]
#[open_enum]
#[repr(u16)]
pub enum GeometryId {
Screen = 0x8000,
Skybox = 0x8001,
TerrainPatch = 0x8002,
Sprites = 0x8004,
WaterPatch = 0x8005,
MeshBase = 0x8010, ParticleSystemBase = 0x8040, InstancedMeshBase = 0x8080, }
impl GeometryId {
enum_bitfield!(MeshBase, Mesh(normal, tangents, uv, color));
enum_bitfield!(
ParticleSystemBase,
ParticleSystem(normal, tangents, uv, color, instance_color, instance_uv)
);
enum_bitfield!(
InstancedMeshBase,
InstancedMesh(normal, tangents, uv, color, instance_color, instance_uv)
);
}
#[allow(missing_docs)]
#[open_enum]
#[repr(u16)]
pub enum EffectMaterialId {
LightingPassEffectBase = 0x5000, WaterEffectBase = 0x5800, CopyEffectBase = 0x6000, ScreenEffectBase = 0x6800, FogEffectBase = 0x7000, FxaaEffectBase = 0x7800, ColorMaterialBase = 0x8000, DepthMaterial = 0x8002,
PositionMaterial = 0x8003,
SkyboxMaterial = 0x8004,
UVMaterial = 0x8005,
NormalMaterialBase = 0x8006, IntersectionMaterial = 0x800B,
IsosurfaceMaterial = 0x800C,
ImpostersMaterial = 0x800D,
BrdfMaterial = 0x800E,
IrradianceMaterial = 0x800F,
ORMMaterialBase = 0x8010, PhysicalMaterialBase = 0x8020, DeferredPhysicalMaterialBase = 0x8040, PrefilterMaterial = 0x8080,
}
impl EffectMaterialId {
enum_effectfield!(LightingPassEffectBase, LightingPassEffect(...Default));
enum_effectfield!(WaterEffectBase, WaterEffect(...Default));
enum_effectfield!(CopyEffectBase, CopyEffect(Option<...Default>));
enum_effectfield!(ScreenEffectBase, ScreenEffect(Option<...Default>));
enum_effectfield!(FogEffectBase, FogEffect(...Default));
enum_effectfield!(FxaaEffectBase, FxaaEffect(color_texture: ColorTexture));
enum_bitfield!(ColorMaterialBase, ColorMaterial(texture));
enum_bitfield!(NormalMaterialBase, NormalMaterial(normal_texture));
enum_bitfield!(
ORMMaterialBase,
ORMMaterial(metallic_roughness_texture, occlusion_texture)
);
enum_bitfield!(
PhysicalMaterialBase,
PhysicalMaterial(
albedo_texture,
metallic_roughness_texture,
occlusion_texture,
normal_texture,
emissive_texture,
)
);
enum_bitfield!(
DeferredPhysicalMaterialBase,
DeferredPhysicalMaterial(
albedo_texture,
metallic_roughness_texture,
occlusion_texture,
normal_texture,
emissive_texture,
alpha_cutout,
)
);
}
#[allow(missing_docs)]
#[open_enum]
#[repr(u8)]
pub enum LightId {
AmbientLightBase = 0x80, DirectionalLightBase = 0x82, PointLight = 0x84,
SpotLightBase = 0x86, }
impl LightId {
enum_bitfield!(AmbientLightBase, AmbientLight(environment));
enum_bitfield!(DirectionalLightBase, DirectionalLight(shadow_texture));
enum_bitfield!(SpotLightBase, SpotLight(shadow_texture));
}