use ToGlEnum;
use gl;
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum SamplerWrapFunction {
Repeat,
Mirror,
Clamp,
BorderClamp,
MirrorClamp
}
impl ToGlEnum for SamplerWrapFunction {
#[inline]
fn to_glenum(&self) -> gl::types::GLenum {
match *self {
SamplerWrapFunction::Repeat => gl::REPEAT,
SamplerWrapFunction::Mirror => gl::MIRRORED_REPEAT,
SamplerWrapFunction::Clamp => gl::CLAMP_TO_EDGE,
SamplerWrapFunction::BorderClamp => gl::CLAMP_TO_BORDER,
SamplerWrapFunction::MirrorClamp => gl::MIRROR_CLAMP_TO_EDGE,
}
}
}
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum MagnifySamplerFilter {
Nearest,
Linear,
}
impl ToGlEnum for MagnifySamplerFilter {
#[inline]
fn to_glenum(&self) -> gl::types::GLenum {
match *self {
MagnifySamplerFilter::Nearest => gl::NEAREST,
MagnifySamplerFilter::Linear => gl::LINEAR,
}
}
}
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum MinifySamplerFilter {
Nearest,
Linear,
NearestMipmapNearest,
LinearMipmapNearest,
NearestMipmapLinear,
LinearMipmapLinear,
}
impl ToGlEnum for MinifySamplerFilter {
#[inline]
fn to_glenum(&self) -> gl::types::GLenum {
match *self {
MinifySamplerFilter::Nearest => gl::NEAREST,
MinifySamplerFilter::Linear => gl::LINEAR,
MinifySamplerFilter::NearestMipmapNearest => gl::NEAREST_MIPMAP_NEAREST,
MinifySamplerFilter::LinearMipmapNearest => gl::LINEAR_MIPMAP_NEAREST,
MinifySamplerFilter::NearestMipmapLinear => gl::NEAREST_MIPMAP_LINEAR,
MinifySamplerFilter::LinearMipmapLinear => gl::LINEAR_MIPMAP_LINEAR,
}
}
}
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum DepthTextureComparison {
LessOrEqual,
GreaterOrEqual,
Less,
Greater,
Equal,
NotEqual,
Always,
Never,
}
impl ToGlEnum for DepthTextureComparison {
#[inline]
fn to_glenum(&self) -> gl::types::GLenum {
match *self {
DepthTextureComparison::LessOrEqual => gl::LEQUAL,
DepthTextureComparison::GreaterOrEqual => gl::GEQUAL,
DepthTextureComparison::Less => gl::LESS,
DepthTextureComparison::Greater => gl::GREATER,
DepthTextureComparison::Equal => gl::EQUAL,
DepthTextureComparison::NotEqual => gl::NOTEQUAL,
DepthTextureComparison::Always => gl::ALWAYS,
DepthTextureComparison::Never => gl::NEVER,
}
}
}
#[derive(Debug, Hash, PartialEq, Eq)]
pub struct Sampler<'t, T: 't>(pub &'t T, pub SamplerBehavior);
impl<'t, T: 't> Sampler<'t, T> {
pub fn new(texture: &'t T) -> Sampler<'t, T> {
Sampler(texture, Default::default())
}
pub fn wrap_function(mut self, function: SamplerWrapFunction) -> Sampler<'t, T> {
self.1.wrap_function = (function, function, function);
self
}
pub fn minify_filter(mut self, filter: MinifySamplerFilter) -> Sampler<'t, T> {
self.1.minify_filter = filter;
self
}
pub fn magnify_filter(mut self, filter: MagnifySamplerFilter) -> Sampler<'t, T> {
self.1.magnify_filter = filter;
self
}
pub fn depth_texture_comparison(mut self, comparison: Option<DepthTextureComparison>) -> Sampler<'t, T> {
self.1.depth_texture_comparison = comparison;
self
}
pub fn anisotropy(mut self, level: u16) -> Sampler<'t, T> {
self.1.max_anisotropy = level;
self
}
}
impl<'t, T: 't> Copy for Sampler<'t, T> {}
impl<'t, T: 't> Clone for Sampler<'t, T> {
fn clone(&self) -> Self {
*self
}
}
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub struct SamplerBehavior {
pub wrap_function: (SamplerWrapFunction, SamplerWrapFunction, SamplerWrapFunction),
pub minify_filter: MinifySamplerFilter,
pub magnify_filter: MagnifySamplerFilter,
pub depth_texture_comparison: Option<DepthTextureComparison>,
pub max_anisotropy: u16,
}
impl Default for SamplerBehavior {
#[inline]
fn default() -> SamplerBehavior {
SamplerBehavior {
wrap_function: (
SamplerWrapFunction::Mirror,
SamplerWrapFunction::Mirror,
SamplerWrapFunction::Mirror
),
minify_filter: MinifySamplerFilter::LinearMipmapLinear,
magnify_filter: MagnifySamplerFilter::Linear,
depth_texture_comparison: None,
max_anisotropy: 1,
}
}
}