#[cfg(feature = "serde")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[derive(Clone, Debug, Copy)]
pub struct GLContextAttributes {
pub alpha: bool,
pub depth: bool,
pub stencil: bool,
pub antialias: bool,
pub premultiplied_alpha: bool,
pub preserve_drawing_buffer: bool,
}
#[cfg(feature = "serde")]
impl<'de> Deserialize<'de> for GLContextAttributes {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>
{
let values = (<[_; 6]>::deserialize(deserializer))?;
Ok(GLContextAttributes {
alpha: values[0],
depth: values[1],
stencil: values[2],
antialias: values[3],
premultiplied_alpha: values[4],
preserve_drawing_buffer: values[5],
})
}
}
#[cfg(feature = "serde")]
impl Serialize for GLContextAttributes {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer
{
let values = [
self.alpha, self.depth, self.stencil,
self.antialias, self.premultiplied_alpha, self.preserve_drawing_buffer,
];
values.serialize(serializer)
}
}
impl GLContextAttributes {
pub fn any() -> GLContextAttributes {
GLContextAttributes {
alpha: false,
depth: false,
stencil: false,
antialias: false,
premultiplied_alpha: false,
preserve_drawing_buffer: false,
}
}
}
impl Default for GLContextAttributes {
fn default() -> GLContextAttributes {
GLContextAttributes {
alpha: true,
depth: true,
stencil: false,
antialias: false,
premultiplied_alpha: true,
preserve_drawing_buffer: false
}
}
}