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
use crate::Framebuffer;
use crate::Context;
use glow::HasContext;
pub struct ClearProgram<'context> {
context : &'context Context,
color : (f32, f32, f32, f32),
depth: f32,
stencil: i32
}
impl<'context> ClearProgram<'context> {
pub const COLOR : u32 = glow::COLOR_BUFFER_BIT;
pub const DEPTH : u32 = glow::DEPTH_BUFFER_BIT;
pub const STENCIL : u32 = glow::STENCIL_BUFFER_BIT;
pub fn new(context:&'context Context) -> Self {
let color = (0.0, 0.0, 0.0, 0.0);
let depth = 1.0;
let stencil = 0;
Self {context,color,depth,stencil}
}
pub fn set_color(&mut self, color: (f32, f32, f32, f32)) { self.color = color; }
pub fn color(&self) -> (f32, f32, f32, f32) { self.color }
pub fn set_depth(&mut self, depth: f32) { self.depth = depth; }
pub fn depth(&self) -> f32 { self.depth }
pub fn set_stencil(&mut self, stencil: i32) { self.stencil = stencil; }
pub fn stencil(&self) -> i32 { self.stencil }
pub fn clear(&self, framebuffer:&'context mut Framebuffer<'_>, clear_mask: u32) {
let gl = &self.context.gl;
unsafe {
framebuffer.bind();
gl.clear_color(self.color.0, self.color.1, self.color.2, self.color.3);
gl.clear_depth_f32(self.depth);
gl.clear_stencil(self.stencil);
gl.clear(clear_mask);
}
}
}