1use optic_core::{Cull, PolyMode, RGBA, Size2D};
2
3pub struct GL;
15
16impl GL {
17 pub fn clear() {
19 unsafe { gl::Clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT); }
20 }
21
22 pub fn set_clear(color: RGBA) {
24 unsafe { gl::ClearColor(color.0, color.1, color.2, color.3); }
25 }
26
27 pub fn resize(size: Size2D) {
29 unsafe { gl::Viewport(0, 0, size.w as i32, size.h as i32); }
30 }
31
32 pub fn poly_mode(mode: PolyMode) {
34 unsafe {
35 match mode {
36 PolyMode::WireFrame => gl::PolygonMode(gl::FRONT_AND_BACK, gl::LINE),
37 PolyMode::Filled => gl::PolygonMode(gl::FRONT_AND_BACK, gl::FILL),
38 PolyMode::Points => {
39 gl::PointSize(10.0);
40 gl::PolygonMode(gl::FRONT_AND_BACK, gl::POINT);
41 }
42 }
43 }
44 }
45
46 pub fn enable_msaa(enable: bool) {
48 unsafe {
49 match enable {
50 true => gl::Enable(gl::MULTISAMPLE),
51 false => gl::Disable(gl::MULTISAMPLE),
52 }
53 }
54 }
55
56 pub fn enable_depth(enable: bool) {
58 unsafe {
59 match enable {
60 true => gl::Enable(gl::DEPTH_TEST),
61 false => gl::Disable(gl::DEPTH_TEST),
62 }
63 }
64 }
65
66 pub fn enable_alpha(enable: bool) {
68 unsafe {
69 match enable {
70 true => {
71 gl::Enable(gl::BLEND);
72 gl::BlendFunc(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA);
73 }
74 false => gl::Disable(gl::BLEND),
75 }
76 }
77 }
78
79 pub fn enable_cull(enable: bool) {
81 unsafe {
82 match enable {
83 true => {
84 gl::Enable(gl::CULL_FACE);
85 gl::CullFace(gl::BACK);
86 }
87 false => gl::Disable(gl::CULL_FACE),
88 }
89 }
90 }
91
92 pub fn set_cull_face(face: Cull) {
94 unsafe {
95 match face {
96 Cull::Clock => gl::FrontFace(gl::CW),
97 Cull::AntiClock => gl::FrontFace(gl::CCW),
98 }
99 }
100 }
101
102 pub fn set_point_size(size: f32) {
104 unsafe { gl::PointSize(size); }
105 }
106
107 pub fn set_wire_width(width: f32) {
109 unsafe { gl::LineWidth(width); }
110 }
111
112 pub fn bind_shader(id: u32) {
114 unsafe { gl::UseProgram(id); }
115 }
116
117 pub fn unbind_shader() {
119 unsafe { gl::UseProgram(0); }
120 }
121
122 pub fn bind_texture_at(tex_id: u32, slot: u32) {
124 unsafe {
125 gl::ActiveTexture(gl::TEXTURE0 + slot);
126 gl::BindTexture(gl::TEXTURE_2D, tex_id);
127 }
128 }
129
130 pub fn unbind_texture() {
132 unsafe { gl::BindTexture(gl::TEXTURE_2D, 0); }
133 }
134
135 pub fn bind_vao(id: u32) {
137 unsafe { gl::BindVertexArray(id); }
138 }
139
140 pub fn unbind_vao() {
142 unsafe { gl::BindVertexArray(0); }
143 }
144
145 pub fn bind_buffer(id: u32) {
147 unsafe { gl::BindBuffer(gl::ARRAY_BUFFER, id); }
148 }
149
150 pub fn unbind_buffer() {
152 unsafe { gl::BindBuffer(gl::ARRAY_BUFFER, 0); }
153 }
154
155 pub fn bind_ebo(id: u32) {
157 unsafe { gl::BindBuffer(gl::ELEMENT_ARRAY_BUFFER, id); }
158 }
159
160 pub fn unbind_ebo() {
162 unsafe { gl::BindBuffer(gl::ELEMENT_ARRAY_BUFFER, 0); }
163 }
164
165 pub fn bind_ssbo(id: u32) {
167 unsafe { gl::BindBuffer(gl::SHADER_STORAGE_BUFFER, id); }
168 }
169
170 pub fn unbind_ssbo() {
172 unsafe { gl::BindBuffer(gl::SHADER_STORAGE_BUFFER, 0); }
173 }
174}