grafix_toolbox/kit/opengl/frame/
screen.rs

1use super::{GL::window::*, *};
2use crate::math::*;
3
4impl Frame for Window {
5	fn ClearColor(&self, args: impl ClearArgs) {
6		let (attach, c) = args.get();
7		GL!(glClearFramebuff(0, gl::COLOR, attach, c.as_ptr()));
8	}
9	fn ClearDepth<T>(&self, d: T)
10	where
11		f32: Cast<T>,
12	{
13		GL!(glClearFramebuff(0, gl::DEPTH, 0, &f32(d) as *const f32));
14	}
15	fn size(&self) -> uVec2 {
16		self.info().size
17	}
18	fn aspect(&self) -> Vec2 {
19		self.info().aspect
20	}
21	fn pixel(&self) -> f32 {
22		self.info().pixel
23	}
24	fn bind(&self) -> Binding<Framebuff> {
25		let (w, h) = self.size();
26		self.Viewport((0, 0, w, h));
27		self.Bind()
28	}
29}
30impl Window {
31	pub fn Viewport(&self, args: impl WINSize) {
32		let (x, y, w, h) = args.get();
33		GL::Viewport::Set((x, y, i32(w), i32(h)));
34	}
35	pub fn Bind(&self) -> Binding<Framebuff> {
36		Binding::<Framebuff>::zero()
37	}
38}
39
40pub struct FrameInfo {
41	pub size: uVec2,
42	pub aspect: Vec2,
43	pub pixel: f32,
44}
45impl FrameInfo {
46	pub fn new((w, h): uVec2) -> Self {
47		let size = (w, h);
48		let (w, h, min) = Vec3((w, h, w.min(h)));
49		let aspect = (w, h).div(min);
50		let pixel = 2. / min;
51		Self { size, aspect, pixel }
52	}
53}