ombre 0.6.7

Shadowy game and graphics library for Rust
Documentation
//! OpenGL types.
use crate::gfx::gl::*;
use crate::gfx::*;

/// Types that can be converted to OpenGL format.
pub trait ToGl {
    /// Convert type to an OpenGL type, eg. `GLenum` or `GLuint`.
    fn to_gl(&self) -> u32;
}

impl ToGl for BufferUsage {
    fn to_gl(&self) -> u32 {
        match self {
            Self::Immutable => glow::STATIC_DRAW,
            Self::Dynamic => glow::DYNAMIC_DRAW,
            Self::Stream => glow::STREAM_DRAW,
        }
    }
}

impl ToGl for Comparison {
    fn to_gl(&self) -> u32 {
        match self {
            Self::Never => glow::NEVER,
            Self::Less => glow::LESS,
            Self::LessOrEqual => glow::LEQUAL,
            Self::Greater => glow::GREATER,
            Self::GreaterOrEqual => glow::GEQUAL,
            Self::Equal => glow::EQUAL,
            Self::NotEqual => glow::NOTEQUAL,
            Self::Always => glow::ALWAYS,
        }
    }
}

impl ToGl for Primitive {
    fn to_gl(&self) -> u32 {
        match self {
            Self::Triangles => glow::TRIANGLES,
            Self::Lines => glow::LINES,
        }
    }
}

impl ToGl for VertexFormat {
    fn to_gl(&self) -> u32 {
        match self {
            VertexFormat::Float1 => glow::FLOAT,
            VertexFormat::Float2 => glow::FLOAT,
            VertexFormat::Float3 => glow::FLOAT,
            VertexFormat::Float4 => glow::FLOAT,
            VertexFormat::Byte1 => glow::UNSIGNED_BYTE,
            VertexFormat::Byte2 => glow::UNSIGNED_BYTE,
            VertexFormat::Byte3 => glow::UNSIGNED_BYTE,
            VertexFormat::Byte4 => glow::UNSIGNED_BYTE,
            VertexFormat::Short1 => glow::UNSIGNED_SHORT,
            VertexFormat::Short2 => glow::UNSIGNED_SHORT,
            VertexFormat::Short3 => glow::UNSIGNED_SHORT,
            VertexFormat::Short4 => glow::UNSIGNED_SHORT,
            VertexFormat::Int1 => glow::UNSIGNED_INT,
            VertexFormat::Int2 => glow::UNSIGNED_INT,
            VertexFormat::Int3 => glow::UNSIGNED_INT,
            VertexFormat::Int4 => glow::UNSIGNED_INT,
        }
    }
}

impl ToGl for TextureTarget {
    fn to_gl(&self) -> u32 {
        match self {
            TextureTarget::Texture2D => glow::TEXTURE_2D,
        }
    }
}

impl ToGl for TextureWrap {
    fn to_gl(&self) -> u32 {
        match self {
            TextureWrap::Repeat => glow::REPEAT,
            TextureWrap::Mirror => glow::MIRRORED_REPEAT,
            TextureWrap::Clamp => glow::CLAMP_TO_EDGE,
        }
    }
}

impl ToGl for ElementSize {
    fn to_gl(&self) -> u32 {
        match self.0 {
            1 => glow::UNSIGNED_BYTE,
            2 => glow::UNSIGNED_SHORT,
            4 => glow::UNSIGNED_INT,
            _ => unreachable! {},
        }
    }
}

impl ToGl for FaceWinding {
    fn to_gl(&self) -> u32 {
        match self {
            Self::Clockwise => glow::CW,
            Self::CounterClockwise => glow::CCW,
        }
    }
}

impl ToGl for BufferKind {
    fn to_gl(&self) -> u32 {
        match self {
            BufferKind::Vertex => glow::ARRAY_BUFFER,
            BufferKind::Index => glow::ELEMENT_ARRAY_BUFFER,
        }
    }
}

impl ToGl for FilterMode {
    fn to_gl(&self) -> u32 {
        match self {
            Self::Linear => glow::LINEAR,
            Self::Nearest => glow::NEAREST,
        }
    }
}

impl ToGl for BlendOp {
    fn to_gl(&self) -> u32 {
        match self {
            BlendOp::Add => glow::FUNC_ADD,
            BlendOp::Subtract => glow::FUNC_SUBTRACT,
            BlendOp::SubtractReverse => glow::FUNC_REVERSE_SUBTRACT,
        }
    }
}

impl ToGl for BlendFactor {
    fn to_gl(&self) -> u32 {
        match self {
            Self::Zero => glow::ZERO,
            Self::One => glow::ONE,
            Self::Value(BlendValue::SourceColor) => glow::SRC_COLOR,
            Self::Value(BlendValue::SourceAlpha) => glow::SRC_ALPHA,
            Self::Value(BlendValue::DestinationColor) => glow::DST_COLOR,
            Self::Value(BlendValue::DestinationAlpha) => glow::DST_ALPHA,
            Self::OneMinusValue(BlendValue::SourceColor) => glow::ONE_MINUS_SRC_COLOR,
            Self::OneMinusValue(BlendValue::SourceAlpha) => glow::ONE_MINUS_SRC_ALPHA,
            Self::OneMinusValue(BlendValue::DestinationColor) => glow::ONE_MINUS_DST_COLOR,
            Self::OneMinusValue(BlendValue::DestinationAlpha) => glow::ONE_MINUS_DST_ALPHA,
            Self::SourceAlphaSaturate => glow::SRC_ALPHA_SATURATE,
        }
    }
}

impl ToGl for ShaderKind {
    fn to_gl(&self) -> u32 {
        match self {
            ShaderKind::Vertex => glow::VERTEX_SHADER,
            ShaderKind::Fragment => glow::FRAGMENT_SHADER,
        }
    }
}
impl ToGl for StencilOp {
    fn to_gl(&self) -> u32 {
        match self {
            Self::Keep => glow::KEEP,
            Self::Zero => glow::ZERO,
            Self::Replace => glow::REPLACE,
            Self::IncrementClamp => glow::INCR,
            Self::DecrementClamp => glow::DECR,
            Self::Invert => glow::INVERT,
            Self::IncrementWrap => glow::INCR_WRAP,
            Self::DecrementWrap => glow::DECR_WRAP,
        }
    }
}