use gl;
use gl::types::*;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Blending {
None,
Default,
Additive,
Subtractive,
Multiply,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum CullFace {
None,
Back,
Front,
FrontAndBack
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Depth {
None,
Never,
LessThan,
Equal,
LessThanOrEqual,
GreaterThan,
NotEqual,
GreaterThanOrEqual,
Always,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum FilterMode {
None,
Linear,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum DrawMode {
Points,
LineStrip,
LineLoop,
Lines,
LineStripAdjacency,
LineAdjacency,
TriangleStrip,
TriangleFan,
Triangles,
TriangleStripAdjacency,
TrianglesAdjacency,
Patches,
}
impl DrawMode {
#[inline]
pub fn to_gl(&self) -> GLenum {
match self {
&DrawMode::Points => gl::POINTS,
&DrawMode::LineStrip => gl::LINE_STRIP,
&DrawMode::LineLoop => gl::LINE_LOOP,
&DrawMode::Lines => gl::LINES,
&DrawMode::LineStripAdjacency => gl::LINE_STRIP_ADJACENCY,
&DrawMode::LineAdjacency => gl::LINES_ADJACENCY,
&DrawMode::TriangleStrip => gl::TRIANGLE_STRIP,
&DrawMode::TriangleFan => gl::TRIANGLE_FAN,
&DrawMode::Triangles => gl::TRIANGLES,
&DrawMode::TriangleStripAdjacency => gl::TRIANGLE_STRIP_ADJACENCY,
&DrawMode::TrianglesAdjacency => gl::TRIANGLES_ADJACENCY,
&DrawMode::Patches => gl::PATCHES,
}
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum IndexKind {
UnsignedByte,
UnsignedShort,
UnsignedInt,
}
impl IndexKind {
#[inline]
pub fn to_gl(&self) -> GLenum {
match self {
&IndexKind::UnsignedByte => gl::UNSIGNED_BYTE,
&IndexKind::UnsignedShort => gl::UNSIGNED_SHORT,
&IndexKind::UnsignedInt => gl::UNSIGNED_INT,
}
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Usage {
StreamDraw, StreamRead, StreamCopy,
StaticDraw, StaticRead, StaticCopy,
DynamicDraw, DynamicRead, DynamicCopy,
}
impl Usage {
#[inline]
pub fn to_gl(&self) -> GLenum {
match self {
&Usage::StreamDraw => gl::STREAM_DRAW,
&Usage::StreamRead => gl::STREAM_READ,
&Usage::StreamCopy => gl::STREAM_COPY,
&Usage::StaticDraw => gl::STATIC_DRAW,
&Usage::StaticRead => gl::STATIC_READ,
&Usage::StaticCopy => gl::STATIC_COPY,
&Usage::DynamicDraw => gl::DYNAMIC_DRAW,
&Usage::DynamicRead => gl::DYNAMIC_READ,
&Usage::DynamicCopy => gl::DYNAMIC_COPY,
}
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum BufferTarget {
Array,
AtomicCounter,
CopyRead,
CopyWrite,
DispatchIndirect,
DrawIndirect,
ElementArray,
PixelPack,
PixelUnpack,
Query,
ShaderStorage,
Texture,
TransformFeedback,
UniformKind,
}
impl BufferTarget {
#[inline]
pub fn to_gl(&self) -> GLenum {
match self {
&BufferTarget::Array => gl::ARRAY_BUFFER,
&BufferTarget::AtomicCounter => gl::ATOMIC_COUNTER_BUFFER,
&BufferTarget::CopyRead => gl::COPY_READ_BUFFER,
&BufferTarget::CopyWrite => gl::COPY_WRITE_BUFFER,
&BufferTarget::DispatchIndirect => gl::DISPATCH_INDIRECT_BUFFER,
&BufferTarget::DrawIndirect => gl::DRAW_INDIRECT_BUFFER,
&BufferTarget::ElementArray => gl::ELEMENT_ARRAY_BUFFER,
&BufferTarget::PixelPack => gl::PIXEL_PACK_BUFFER,
&BufferTarget::PixelUnpack => gl::PIXEL_UNPACK_BUFFER,
&BufferTarget::Query => gl::QUERY_BUFFER,
&BufferTarget::ShaderStorage => gl::SHADER_STORAGE_BUFFER,
&BufferTarget::Texture => gl::TEXTURE_BUFFER,
&BufferTarget::TransformFeedback => gl::TRANSFORM_FEEDBACK_BUFFER,
&BufferTarget::UniformKind => gl::UNIFORM_BUFFER,
}
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum TextureKind {
Texture1D,
Texture2D,
Texture3D,
Texture1DArray,
Texture2DArray,
TextureRectangle,
TextureCubeMap,
TextureCubeMapArray,
TextureBuffer,
Texture2DMultiSameple,
Texture2DMultiSamepleArray,
}
impl TextureKind {
#[inline]
pub fn to_gl(&self) -> GLenum {
match self {
&TextureKind::Texture1D => gl::TEXTURE_1D,
&TextureKind::Texture2D => gl::TEXTURE_2D,
&TextureKind::Texture3D => gl::TEXTURE_3D,
&TextureKind::Texture1DArray => gl::TEXTURE_1D_ARRAY,
&TextureKind::Texture2DArray => gl::TEXTURE_2D_ARRAY,
&TextureKind::TextureRectangle => gl::TEXTURE_RECTANGLE,
&TextureKind::TextureCubeMap => gl::TEXTURE_CUBE_MAP,
&TextureKind::TextureCubeMapArray => gl::TEXTURE_CUBE_MAP_ARRAY,
&TextureKind::TextureBuffer => gl::TEXTURE_BUFFER,
&TextureKind::Texture2DMultiSameple => gl::TEXTURE_2D_MULTISAMPLE,
&TextureKind::Texture2DMultiSamepleArray => gl::TEXTURE_2D_MULTISAMPLE_ARRAY,
}
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Attachment {
Color,
Depth,
Stencil
}
impl Attachment {
#[inline]
pub fn to_gl(&self) -> GLenum {
match self {
&Attachment::Color => gl::COLOR_ATTACHMENT0,
&Attachment::Depth => gl::DEPTH_ATTACHMENT,
&Attachment::Stencil => gl::STENCIL_ATTACHMENT,
}
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum DataFormat {
Red, RG, RGB, BGR, RGBA, BGRA,
RedInteger, RGInteger, RGBInteger, BGRInteger, RGBAInteger, BGRAInteger,
StencilInteger,
DepthComponent,
DepthStencil,
}
impl DataFormat {
#[inline]
pub fn to_gl(&self) -> GLenum {
match self {
&DataFormat::Red => gl::RED,
&DataFormat::RG => gl::RG,
&DataFormat::RGB => gl::RGB,
&DataFormat::BGR => gl::BGR,
&DataFormat::RGBA => gl::RGBA,
&DataFormat::BGRA => gl::BGRA,
&DataFormat::RedInteger => gl::RED_INTEGER,
&DataFormat::RGInteger => gl::RG_INTEGER,
&DataFormat::RGBInteger => gl::RGB_INTEGER,
&DataFormat::BGRInteger => gl::BGR_INTEGER,
&DataFormat::RGBAInteger => gl::RGBA_INTEGER,
&DataFormat::BGRAInteger => gl::BGRA_INTEGER,
&DataFormat::StencilInteger => gl::STENCIL_INDEX,
&DataFormat::DepthComponent => gl::DEPTH_COMPONENT,
&DataFormat::DepthStencil => gl::DEPTH_STENCIL,
}
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum DataKind {
UnsignedByte,
Byte,
UnsignedShort,
Short,
UnsignedInt,
Int,
Float,
Bool,
UnsignedByte332,
UnsignedByte223Rev,
UnsignedShort565,
UnsignedShort565Rev,
UnsignedShort4444,
UnsignedShort4444Rev,
UnsignedShort5551,
UnsignedShort1555Rev,
UnsignedInt8888,
UnsignedInt8888Rev,
UnsignedInt1010102,
UnsignedInt2101010Rev,
}
impl DataKind {
#[inline]
pub fn to_gl(&self) -> GLenum {
match self {
&DataKind::UnsignedByte => gl::UNSIGNED_BYTE,
&DataKind::Byte => gl::BYTE,
&DataKind::UnsignedShort => gl::UNSIGNED_SHORT,
&DataKind::Short => gl::SHORT,
&DataKind::UnsignedInt => gl::UNSIGNED_INT,
&DataKind::Int => gl::INT,
&DataKind::Float => gl::FLOAT,
&DataKind::Bool => gl::BOOL,
&DataKind::UnsignedByte332 => gl::UNSIGNED_BYTE_3_3_2,
&DataKind::UnsignedByte223Rev => gl::UNSIGNED_BYTE_2_3_3_REV,
&DataKind::UnsignedShort565 => gl::UNSIGNED_SHORT_5_6_5,
&DataKind::UnsignedShort565Rev => gl::UNSIGNED_SHORT_5_6_5_REV,
&DataKind::UnsignedShort4444 => gl::UNSIGNED_SHORT_4_4_4_4,
&DataKind::UnsignedShort4444Rev => gl::UNSIGNED_SHORT_4_4_4_4_REV,
&DataKind::UnsignedShort5551 => gl::UNSIGNED_SHORT_5_5_5_1,
&DataKind::UnsignedShort1555Rev => gl::UNSIGNED_SHORT_1_5_5_5_REV,
&DataKind::UnsignedInt8888 => gl::UNSIGNED_INT_8_8_8_8,
&DataKind::UnsignedInt8888Rev => gl::UNSIGNED_INT_8_8_8_8_REV,
&DataKind::UnsignedInt1010102 => gl::UNSIGNED_INT_10_10_10_2,
&DataKind::UnsignedInt2101010Rev => gl::UNSIGNED_INT_2_10_10_10_REV,
}
}
}
#[allow(non_camel_case_types)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum InternalFormat {
R8,
R8_SNORM,
R16F,
R32F,
R8UI,
R8I,
R16UI,
R16I,
R32UI,
R32I,
RG8,
RG8_SNORM,
RG16F,
RG32F,
RG8UI,
RG8I,
RG16UI,
RG16I,
RG32UI,
RG32I,
RGB8,
SRGB8,
RGB565,
RGB8_SNORM,
R11F_G11F_B10F,
RGB9_E5,
RGB16F,
RGB32F,
RGB8UI,
RGB8I,
RGB16UI,
RGB16I,
RGB32UI,
RGB32I,
RGBA8,
SRGB8_ALPHA8,
RGBA8_SNORM,
RGB5_A1,
RGBA4,
RGB10_A2,
RGBA16F,
RGBA32F,
RGBA8UI,
RGBA8I,
RGB10_A2UI,
RGBA16UI,
RGBA16I,
RGBA32I,
RGBA32UI,
}
impl InternalFormat {
#[inline]
pub fn to_gl(&self) -> GLenum {
match self {
&InternalFormat::R8 => gl::R8,
&InternalFormat::R8_SNORM => gl::R8_SNORM,
&InternalFormat::R16F => gl::R16F,
&InternalFormat::R32F => gl::R32F,
&InternalFormat::R8UI => gl::R8UI,
&InternalFormat::R8I => gl::R8I,
&InternalFormat::R16UI => gl::R16UI,
&InternalFormat::R16I => gl::R16I,
&InternalFormat::R32UI => gl::R32UI,
&InternalFormat::R32I => gl::R32I,
&InternalFormat::RG8 => gl::RG8,
&InternalFormat::RG8_SNORM => gl::RG8_SNORM,
&InternalFormat::RG16F => gl::RG16F,
&InternalFormat::RG32F => gl::RG32F,
&InternalFormat::RG8UI => gl::RG8UI,
&InternalFormat::RG8I => gl::RG8I,
&InternalFormat::RG16UI => gl::RG16UI,
&InternalFormat::RG16I => gl::RG16I,
&InternalFormat::RG32UI => gl::RG32UI,
&InternalFormat::RG32I => gl::RG32I,
&InternalFormat::RGB8 => gl::RGB8,
&InternalFormat::SRGB8 => gl::SRGB8,
&InternalFormat::RGB565 => gl::RGB565,
&InternalFormat::RGB8_SNORM => gl::RGB8_SNORM,
&InternalFormat::R11F_G11F_B10F => gl::R11F_G11F_B10F,
&InternalFormat::RGB9_E5 => gl::RGB9_E5,
&InternalFormat::RGB16F => gl::RGB16F,
&InternalFormat::RGB32F => gl::RGB32F,
&InternalFormat::RGB8UI => gl::RGB8UI,
&InternalFormat::RGB8I => gl::RGB8I,
&InternalFormat::RGB16UI => gl::RGB16UI,
&InternalFormat::RGB16I => gl::RGB16I,
&InternalFormat::RGB32UI => gl::RGB32UI,
&InternalFormat::RGB32I => gl::RGB32I,
&InternalFormat::RGBA8 => gl::RGBA8,
&InternalFormat::SRGB8_ALPHA8 => gl::SRGB8_ALPHA8,
&InternalFormat::RGBA8_SNORM => gl::RGBA8_SNORM,
&InternalFormat::RGB5_A1 => gl::RGB5_A1,
&InternalFormat::RGBA4 => gl::RGBA4,
&InternalFormat::RGB10_A2 => gl::RGB10_A2,
&InternalFormat::RGBA16F => gl::RGBA16F,
&InternalFormat::RGBA32F => gl::RGBA32F,
&InternalFormat::RGBA8UI => gl::RGBA8UI,
&InternalFormat::RGBA8I => gl::RGBA8I,
&InternalFormat::RGB10_A2UI => gl::RGB10_A2UI,
&InternalFormat::RGBA16UI => gl::RGBA16UI,
&InternalFormat::RGBA16I => gl::RGBA16I,
&InternalFormat::RGBA32I => gl::RGBA32I,
&InternalFormat::RGBA32UI => gl::RGBA32UI,
}
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum AttributeKind {
Bool,
Int,
Float,
BoolVec2,
IntVec2,
FloatVec2,
BoolVec3,
IntVec3,
FloatVec3,
BoolVec4,
IntVec4,
FloatVec4,
}
impl AttributeKind {
#[inline]
pub fn to_gl(&self) -> GLenum {
match self {
&AttributeKind::Bool => gl::BOOL,
&AttributeKind::Int => gl::INT,
&AttributeKind::Float => gl::FLOAT,
&AttributeKind::BoolVec2 => gl::BOOL_VEC2,
&AttributeKind::IntVec2 => gl::INT_VEC2,
&AttributeKind::FloatVec2 => gl::FLOAT_VEC2,
&AttributeKind::BoolVec3 => gl::BOOL_VEC3,
&AttributeKind::IntVec3 => gl::INT_VEC3,
&AttributeKind::FloatVec3 => gl::FLOAT_VEC3,
&AttributeKind::BoolVec4 => gl::BOOL_VEC4,
&AttributeKind::IntVec4 => gl::INT_VEC4,
&AttributeKind::FloatVec4 => gl::FLOAT_VEC4,
}
}
#[inline]
pub fn item_data(&self) -> (usize, DataKind) {
match self {
&AttributeKind::Bool => (1, DataKind::Bool),
&AttributeKind::Int => (1, DataKind::Int),
&AttributeKind::Float => (1, DataKind::Float),
&AttributeKind::BoolVec2 => (2, DataKind::Bool),
&AttributeKind::IntVec2 => (2, DataKind::Int),
&AttributeKind::FloatVec2 => (2, DataKind::Float),
&AttributeKind::BoolVec3 => (3, DataKind::Bool),
&AttributeKind::IntVec3 => (3, DataKind::Int),
&AttributeKind::FloatVec3 => (3, DataKind::Float),
&AttributeKind::BoolVec4 => (4, DataKind::Bool),
&AttributeKind::IntVec4 => (4, DataKind::Int),
&AttributeKind::FloatVec4 => (4, DataKind::Float),
}
}
#[inline]
pub fn from_gl(gl_enum: GLenum) -> Self {
match gl_enum {
gl::BOOL => AttributeKind::Bool,
gl::INT => AttributeKind::Int,
gl::FLOAT => AttributeKind::Float,
gl::BOOL_VEC2 => AttributeKind::BoolVec2,
gl::INT_VEC2 => AttributeKind::IntVec2,
gl::FLOAT_VEC2 => AttributeKind::FloatVec2,
gl::BOOL_VEC3 => AttributeKind::BoolVec3,
gl::INT_VEC3 => AttributeKind::IntVec3,
gl::FLOAT_VEC3 => AttributeKind::FloatVec3,
gl::BOOL_VEC4 => AttributeKind::BoolVec4,
gl::INT_VEC4 => AttributeKind::IntVec4,
gl::FLOAT_VEC4 => AttributeKind::FloatVec4,
_ => panic!("Invalid attribte type {:?}", gl_enum),
}
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum UniformKind {
Float,
Int,
FloatVec2,
IntVec2,
FloatVec3,
IntVec3,
FloatVec4,
IntVec4,
FloatMat2,
FloatMat3,
FloatMat4,
Sampler2D,
}
impl UniformKind {
#[inline]
pub fn to_gl(&self) -> GLenum {
match self {
&UniformKind::Float => gl::FLOAT,
&UniformKind::Int => gl::INT,
&UniformKind::FloatVec2 => gl::FLOAT_VEC2,
&UniformKind::IntVec2 => gl::INT_VEC2,
&UniformKind::FloatVec3 => gl::FLOAT_VEC3,
&UniformKind::IntVec3 => gl::INT_VEC3,
&UniformKind::FloatVec4 => gl::FLOAT_VEC4,
&UniformKind::IntVec4 => gl::INT_VEC4,
&UniformKind::FloatMat2 => gl::FLOAT_MAT2,
&UniformKind::FloatMat3 => gl::FLOAT_MAT3,
&UniformKind::FloatMat4 => gl::FLOAT_MAT4,
&UniformKind::Sampler2D => gl::SAMPLER_2D,
}
}
#[inline]
pub fn from_gl(gl_enum: GLenum) -> Self {
match gl_enum {
gl::FLOAT => UniformKind::Float,
gl::INT => UniformKind::Int,
gl::FLOAT_VEC2 => UniformKind::FloatVec2,
gl::INT_VEC2 => UniformKind::IntVec2,
gl::FLOAT_VEC3 => UniformKind::FloatVec3,
gl::INT_VEC3 => UniformKind::IntVec3,
gl::FLOAT_VEC4 => UniformKind::FloatVec4,
gl::INT_VEC4 => UniformKind::IntVec4,
gl::FLOAT_MAT2 => UniformKind::FloatMat2,
gl::FLOAT_MAT3 => UniformKind::FloatMat3,
gl::FLOAT_MAT4 => UniformKind::FloatMat4,
gl::SAMPLER_2D => UniformKind::Sampler2D,
_ => panic!("Invalid uniform type {:?}", gl_enum),
}
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Wrap {
Repeat,
Clamp,
MirroredRepeat,
}
impl Wrap {
#[inline]
pub fn to_gl(&self) -> GLenum {
match self {
&Wrap::Repeat => gl::REPEAT,
&Wrap::Clamp => gl::CLAMP_TO_EDGE,
&Wrap::MirroredRepeat => gl::MIRRORED_REPEAT,
}
}
}