use bitflags::bitflags; use crate::data_types::dimens::Dimens; use crate::vector::Vec2; pub mod buffer; pub mod shader; pub mod texture; pub mod vertex_array; mod util; #[cfg(feature = "debug")] pub mod debug; pub fn set_viewport(position: Vec2, size: Dimens) { unsafe { #[allow(clippy::cast_possible_wrap)] gl::Viewport( position.x as i32, position.y as i32, size.width as i32, size.height as i32, ); } } pub fn clear_buffers(mask: BufferClearMask) { unsafe { gl::Clear(mask.bits()); } } pub fn set_polygon_mode(face: impl Into, mode: impl Into) { unsafe { gl::PolygonMode(face.into() as u32, mode.into() as u32); } } pub fn enable(capacity: Capability) { unsafe { gl::Enable(capacity as u32); } } bitflags! { #[derive(Debug, Clone, Copy)] pub struct BufferClearMask: u32 { const COLOR = gl::COLOR_BUFFER_BIT; const DEPTH = gl::DEPTH_BUFFER_BIT; const STENCIL = gl::STENCIL_BUFFER_BIT; } } #[derive(Debug)] #[repr(u32)] pub enum Capability { DepthTest = gl::DEPTH_TEST, MultiSample = gl::MULTISAMPLE, } #[derive(Debug)] #[repr(u32)] pub enum PolygonMode { Point = gl::POINT, Line = gl::LINE, Fill = gl::FILL, } impl From for PolygonMode { fn from(mode: crate::draw_flags::PolygonMode) -> Self { match mode { crate::draw_flags::PolygonMode::Point => Self::Point, crate::draw_flags::PolygonMode::Fill => Self::Fill, crate::draw_flags::PolygonMode::Line => Self::Line, } } } #[derive(Debug)] #[repr(u32)] pub enum PolygonModeFace { Front = gl::FRONT, Back = gl::BACK, FrontAndBack = gl::FRONT_AND_BACK, } impl From for PolygonModeFace { fn from(face: crate::draw_flags::PolygonModeFace) -> Self { match face { crate::draw_flags::PolygonModeFace::Front => Self::Front, crate::draw_flags::PolygonModeFace::Back => Self::Back, crate::draw_flags::PolygonModeFace::FrontAndBack => Self::FrontAndBack, } } }