2022-11-14 16:14:05 +11:00
|
|
|
#[cfg(feature = "opengl")]
|
|
|
|
pub mod gl;
|
|
|
|
|
2022-10-22 12:04:00 +11:00
|
|
|
use std::convert::Infallible;
|
|
|
|
use std::str::FromStr;
|
|
|
|
|
2022-10-22 17:54:06 +11:00
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
2022-10-22 12:04:00 +11:00
|
|
|
pub struct ShaderSource {
|
|
|
|
pub vertex: String,
|
|
|
|
pub fragment: String,
|
|
|
|
pub name: Option<String>,
|
|
|
|
pub parameters: Vec<ShaderParameter>,
|
|
|
|
pub format: ShaderFormat,
|
|
|
|
}
|
|
|
|
|
2022-10-22 14:37:47 +11:00
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
2022-10-22 12:04:00 +11:00
|
|
|
pub struct ShaderParameter {
|
|
|
|
pub id: String,
|
|
|
|
pub description: String,
|
|
|
|
pub initial: f32,
|
|
|
|
pub minimum: f32,
|
|
|
|
pub maximum: f32,
|
|
|
|
pub step: f32,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(u32)]
|
2022-10-22 14:37:47 +11:00
|
|
|
#[derive(Default, Copy, Clone, Debug, Eq, PartialEq)]
|
2022-10-22 12:04:00 +11:00
|
|
|
pub enum ShaderFormat {
|
2022-10-22 14:37:47 +11:00
|
|
|
#[default]
|
2022-10-22 12:04:00 +11:00
|
|
|
Unknown = 0,
|
|
|
|
|
|
|
|
/* 8-bit */
|
|
|
|
R8Unorm,
|
|
|
|
R8Uint,
|
|
|
|
R8Sint,
|
|
|
|
R8G8Unorm,
|
|
|
|
R8G8Uint,
|
|
|
|
R8G8Sint,
|
|
|
|
R8G8B8A8Unorm,
|
|
|
|
R8G8B8A8Uint,
|
|
|
|
R8G8B8A8Sint,
|
|
|
|
R8G8B8A8Srgb,
|
|
|
|
|
|
|
|
/* 10-bit */
|
|
|
|
A2B10G10R10UnormPack32,
|
|
|
|
A2B10G10R10UintPack32,
|
|
|
|
|
|
|
|
/* 16-bit */
|
|
|
|
R16Uint,
|
|
|
|
R16Sint,
|
|
|
|
R16Sfloat,
|
|
|
|
R16G16Uint,
|
|
|
|
R16G16Sint,
|
|
|
|
R16G16Sfloat,
|
|
|
|
R16G16B16A16Uint,
|
|
|
|
R16G16B16A16Sint,
|
|
|
|
R16G16B16A16Sfloat,
|
|
|
|
|
|
|
|
/* 32-bit */
|
|
|
|
R32Uint,
|
|
|
|
R32Sint,
|
|
|
|
R32Sfloat,
|
|
|
|
R32G32Uint,
|
|
|
|
R32G32Sint,
|
|
|
|
R32G32Sfloat,
|
|
|
|
R32G32B32A32Uint,
|
|
|
|
R32G32B32A32Sint,
|
|
|
|
R32G32B32A32Sfloat,
|
|
|
|
}
|
|
|
|
|
2022-11-14 16:14:05 +11:00
|
|
|
#[repr(i32)]
|
|
|
|
#[derive(Copy, Clone, Default, Debug)]
|
|
|
|
pub enum FilterMode {
|
|
|
|
#[default]
|
|
|
|
Linear = 0,
|
|
|
|
Nearest,
|
|
|
|
Unspecified,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for WrapMode {
|
|
|
|
type Err = Infallible;
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
Ok(match s {
|
|
|
|
"clamp_to_border" => WrapMode::ClampToBorder,
|
|
|
|
"clamp_to_edge" => WrapMode::ClampToEdge,
|
|
|
|
"repeat" => WrapMode::Repeat,
|
|
|
|
"mirrored_repeat" => WrapMode::MirroredRepeat,
|
|
|
|
_ => WrapMode::ClampToBorder,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[repr(i32)]
|
|
|
|
#[derive(Copy, Clone, Default, Debug)]
|
|
|
|
pub enum WrapMode {
|
|
|
|
#[default]
|
|
|
|
ClampToBorder = 0,
|
|
|
|
ClampToEdge,
|
|
|
|
Repeat,
|
|
|
|
MirroredRepeat,
|
|
|
|
}
|
|
|
|
|
2022-10-22 12:04:00 +11:00
|
|
|
impl FromStr for ShaderFormat {
|
|
|
|
type Err = Infallible;
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
Ok(match s {
|
|
|
|
"UNKNOWN" => Self::Unknown,
|
|
|
|
|
|
|
|
"R8_UNORM" => Self::R8Unorm,
|
|
|
|
"R8_UINT" => Self::R8Uint,
|
|
|
|
"R8_SINT" => Self::R8Sint,
|
|
|
|
"R8G8_UNORM" => Self::R8G8Unorm,
|
|
|
|
"R8G8_UINT" => Self::R8Uint,
|
|
|
|
"R8G8_SINT" => Self::R8G8Sint,
|
|
|
|
"R8G8B8A8_UNORM" => Self::R8G8B8A8Unorm,
|
|
|
|
"R8G8B8A8_UINT" => Self::R8G8B8A8Uint,
|
|
|
|
"R8G8B8A8_SINT" => Self::R8G8B8A8Sint,
|
|
|
|
"R8G8B8A8_SRGB" => Self::R8G8B8A8Srgb,
|
|
|
|
|
|
|
|
"A2B10G10R10_UNORM_PACK32" => Self::A2B10G10R10UnormPack32,
|
|
|
|
"A2B10G10R10_UINT_PACK32" => Self::A2B10G10R10UintPack32,
|
|
|
|
|
|
|
|
"R16_UINT" => Self::R16Uint,
|
|
|
|
"R16_SINT" => Self::R16Sint,
|
|
|
|
"R16_SFLOAT" => Self::R16Sfloat,
|
|
|
|
"R16G16_UINT" => Self::R16G16Uint,
|
|
|
|
"R16G16_SINT" => Self::R16G16Sint,
|
|
|
|
"R16G16_SFLOAT" => Self::R16G16Sfloat,
|
|
|
|
"R16G16B16A16_UINT" => Self::R16G16B16A16Uint,
|
|
|
|
"R16G16B16A16_SINT" => Self::R16G16B16A16Sint,
|
|
|
|
"R16G16B16A16_SFLOAT" => Self::R16G16B16A16Sfloat,
|
|
|
|
|
|
|
|
"R32_UINT" => Self::R32Uint,
|
|
|
|
"R32_SINT" => Self::R32Sint,
|
|
|
|
"R32_SFLOAT" => Self::R32Sfloat,
|
|
|
|
"R32G32_UINT" => Self::R32G32Uint,
|
|
|
|
"R32G32_SINT" => Self::R32G32Sint,
|
|
|
|
"R32G32_SFLOAT" => Self::R32G32Sfloat,
|
2022-10-22 14:37:47 +11:00
|
|
|
"R32G32B32A32_UINT" => Self::R32G32B32A32Uint,
|
|
|
|
"R32G32B32A32_SINT" => Self::R32G32B32A32Sint,
|
|
|
|
"R32G32B32A32_SFLOAT" => Self::R32G32B32A32Sfloat,
|
2022-10-22 12:04:00 +11:00
|
|
|
_ => Self::Unknown,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|