pub trait Pixel {
type Encoding;
fn pixel_format() -> PixelFormat;
}
pub trait ColorPixel: Pixel {}
pub trait DepthPixel: Pixel {}
#[derive(Clone, Copy, Debug)]
pub struct PixelFormat {
pub encoding: Type
, pub format: Format
}
#[derive(Clone, Copy, Debug)]
pub enum Type {
Integral,
Unsigned,
Floating
}
#[derive(Clone, Copy, Debug)]
pub enum Format {
R(u8),
RG(u8, u8),
RGB(u8, u8, u8),
RGBA(u8, u8, u8, u8),
Depth(u8)
}
pub fn is_color_pixel(f: PixelFormat) -> bool {
match f.format {
Format::Depth(_) => false
, _ => true
}
}
pub fn is_depth_pixel(f: PixelFormat) -> bool {
!is_color_pixel(f)
}
#[derive(Clone, Copy, Debug)]
pub struct RGB8UI;
impl Pixel for RGB8UI {
type Encoding = (u8, u8, u8);
fn pixel_format() -> PixelFormat {
PixelFormat {
encoding: Type::Unsigned
, format: Format::RGB(8, 8, 8)
}
}
}
impl ColorPixel for RGB8UI {}
#[derive(Clone, Copy, Debug)]
pub struct RGBA8UI;
impl Pixel for RGBA8UI {
type Encoding = (u8, u8, u8, u8);
fn pixel_format() -> PixelFormat {
PixelFormat {
encoding: Type::Unsigned
, format: Format::RGBA(8, 8, 8, 8)
}
}
}
impl ColorPixel for RGBA8UI {}
#[derive(Clone, Copy, Debug)]
pub struct RGB32F;
impl Pixel for RGB32F {
type Encoding = (f32, f32, f32);
fn pixel_format() -> PixelFormat {
PixelFormat {
encoding: Type::Floating
, format: Format::RGB(32, 32, 32)
}
}
}
impl ColorPixel for RGB32F {}
#[derive(Clone, Copy, Debug)]
pub struct RGBA32F;
impl Pixel for RGBA32F {
type Encoding = (f32, f32, f32, f32);
fn pixel_format() -> PixelFormat {
PixelFormat {
encoding: Type::Floating
, format: Format::RGBA(32, 32, 32, 32)
}
}
}
impl ColorPixel for RGBA32F {}
#[derive(Clone, Copy, Debug)]
pub struct Depth32F;
impl Pixel for Depth32F {
type Encoding = f32;
fn pixel_format() -> PixelFormat {
PixelFormat {
encoding: Type::Floating
, format: Format::Depth(32)
}
}
}
impl DepthPixel for RGBA32F {}