Skip to main content

grafix_toolbox/kit/opengl/
geom.rs

1pub use {camera::*, mesh::*, model::*, vao::*};
2
3pub type AnyMesh = Box<dyn AnyMeshT>;
4impl Default for AnyMesh {
5	fn default() -> Self {
6		Mesh::make_sphere(0.1, 6)
7	}
8}
9
10pub struct Mesh<I> {
11	pub geom: Geometry<I>,
12	pub draw: (I, GLenum),
13}
14
15pub mod Screen {
16	struct Model {
17		vao: Vao<u8>,
18		_xyuv: AttrArr<i8>,
19	}
20	pub fn Draw() {
21		GLSave!(DEPTH_TEST);
22		GLDisable!(DEPTH_TEST);
23		LeakyStatic!(Model, {
24			#[rustfmt::skip]
25			let _xyuv = AttrArr::new(&[ -1, -1, 0, 0,  3, -1, 2, 0,  -1, 3, 0, 2 ][..]);
26			let mut vao = Vao::default();
27			vao.AttribFmt(&_xyuv, (0, 4));
28			Model { vao, _xyuv }
29		})
30		.vao
31		.Bind()
32		.DrawUnindexed(3);
33		GLRestore!(DEPTH_TEST);
34	}
35	use super::*;
36}
37
38pub mod Skybox {
39	pub fn Draw() {
40		LeakyStatic!(Geometry<u8>, {
41			#[rustfmt::skip]
42			let idx = &[0, 1, 3,  3, 1, 2,
43						4, 5, 7,  7, 5, 6,
44						0, 1, 4,  4, 1, 5,
45						3, 2, 7,  7, 2, 6,
46						2, 1, 6,  6, 1, 5,
47						3, 7, 0,  0, 7, 4_u8][..];
48			#[rustfmt::skip]
49			let xyz = &[-1,  1, 1,   1,  1, 1,   1,  1, -1,  -1,  1, -1,
50						-1, -1, 1,   1, -1, 1,   1, -1, -1,  -1, -1, -1_i8][..];
51			Geometry::new(idx, (3, xyz))
52		})
53		.Draw(36);
54	}
55	use super::*;
56}
57
58mod args;
59mod camera;
60mod mesh;
61mod model;
62mod vao;
63
64use crate::lib::*;
65use {GL::buffer::*, GL::spec::*, args::*};
66
67SHADER!(
68	vs_mesh__2d_screen,
69	r"layout(location = 0) in vec4 Position;
70	out vec2 glUV;
71
72	void main() {
73		gl_Position = vec4(Position.xy, 0, 1);
74		glUV = Position.zw;
75	}"
76);
77
78SHADER!(
79	ps_mesh__2d_screen,
80	r"in vec2 glUV;
81	layout(location = 0) out vec4 glFragColor;
82	uniform sampler2D iTex;
83
84	void main() { glFragColor = texture(iTex, glUV); }"
85);