gpu/code/programs/
clear_program.rs1use crate::prelude::*;
2use crate::{Context, Framebuffer, GLContext};
3
4
5
6pub struct ClearProgram {
12 gl: GLContext,
13 color: (f32, f32, f32, f32),
14 depth: f32,
15 stencil: i32
16}
17
18impl ClearProgram {
19 pub const COLOR : u32 = glow::COLOR_BUFFER_BIT;
21 pub const DEPTH : u32 = glow::DEPTH_BUFFER_BIT;
23 pub const STENCIL : u32 = glow::STENCIL_BUFFER_BIT;
25
26 pub fn new(context:&Context) -> Self {
28 let gl = context.gl_context();
29 let color = (0.0, 0.0, 0.0, 0.0);
30 let depth = 1.0; let stencil = 0; Self { gl, color, depth, stencil}
33 }
34
35 pub fn set_color(&mut self, color: (f32, f32, f32, f32)) { self.color = color; }
37 pub fn color(&self) -> (f32, f32, f32, f32) { self.color }
39
40 pub fn set_depth(&mut self, depth: f32) { self.depth = depth; }
42 pub fn depth(&self) -> f32 { self.depth }
44
45 pub fn set_stencil(&mut self, stencil: i32) { self.stencil = stencil; }
47 pub fn stencil(&self) -> i32 { self.stencil }
49
50 pub fn clear(&self, framebuffer:&mut Framebuffer, clear_mask: u32) {
56 let gl = &self.gl;
57 unsafe {
58 framebuffer.bind();
59 gl.clear_color(self.color.0, self.color.1, self.color.2, self.color.3);
60 gl.clear_depth_f32(self.depth);
61 gl.clear_stencil(self.stencil);
62 gl.clear(clear_mask);
63 }
64 }
65}