1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
use crate::{gl, prelude::*, GLbitfield, GLfloat, GLint, Vector4}; use std::option::Option; #[derive(Clone, Copy, Default, Debug)] pub struct ClearBuffers { accum: Option<Vector4>, color: Option<Vector4>, color_index: Option<GLfloat>, depth: Option<GLfloat>, stencil: Option<GLint>, } impl ClearBuffers { pub fn new() -> Self { Self { accum: None, color: None, color_index: None, depth: None, stencil: None, } } #[cfg(feature = "gl4")] pub fn with_accum(mut self, accum: Option<Vector4>) -> Self { self.accum = accum; self } pub fn with_color(mut self, color: Option<Vector4>) -> Self { self.color = color; self } #[cfg(feature = "gl4")] pub fn with_color_index(mut self, color_index: Option<GLfloat>) -> Self { self.color_index = color_index; self } pub fn with_depth(mut self, depth: Option<GLfloat>) -> Self { self.depth = depth; self } pub fn with_stencil(mut self, stencil: Option<GLint>) -> Self { self.stencil = stencil; self } #[cfg(feature = "gl4")] pub fn set_accum(&mut self, accum: Vector4) { self.accum = Some(accum); } pub fn set_color(&mut self, color: Vector4) { self.color = Some(color); } #[cfg(feature = "gl4")] pub fn set_color_index(&mut self, color_index: GLfloat) { self.color_index = Some(color_index); } pub fn set_depth(&mut self, depth: GLfloat) { self.depth = Some(depth); } pub fn set_stencil(&mut self, stencil: GLint) { self.stencil = Some(stencil); } } impl Bindable for ClearBuffers { fn bind(&self) { let mut mask: GLbitfield = 0; #[cfg(feature = "gl4")] { if let Some(ref v) = self.accum { crate::clear_accum(v); mask |= gl::ACCUM_BUFFER_BIT; } } if let Some(v) = self.color { crate::clear_color(v.x, v.y, v.z, v.w); mask |= gl::COLOR_BUFFER_BIT; } #[cfg(feature = "gl4")] { if let Some(v) = self.index { crate::clear_index(v); mask |= gl::COLOR_BUFFER_BIT; } } if let Some(v) = self.depth { crate::clear_depthf(v); mask |= gl::DEPTH_BUFFER_BIT; } if let Some(v) = self.stencil { crate::clear_stencil(v); mask |= gl::STENCIL_BUFFER_BIT; } if mask != 0 { crate::clear(mask); } } fn unbind(&self) {} }