♻️ Extract GLES functions that are trivially safe

main
_ 2020-02-16 23:32:35 +00:00
parent 6b9b2a4e93
commit 963b344122
3 changed files with 36 additions and 12 deletions

View File

@ -241,14 +241,12 @@ fn main () {
const FALSE_U8: u8 = 0; const FALSE_U8: u8 = 0;
unsafe { enable_vertex_attrib_array (attrs ["pos"]);
enable_vertex_attrib_array (attrs ["pos"]); enable_vertex_attrib_array (attrs ["uv"]);
enable_vertex_attrib_array (attrs ["uv"]); enable_vertex_attrib_array (attrs ["normal"]);
enable_vertex_attrib_array (attrs ["normal"]);
gl::Enable (gl::DEPTH_TEST); glezz::enable (gl::DEPTH_TEST);
gl::Enable (gl::TEXTURE); glezz::enable (gl::TEXTURE);
}
let mut time_step = TimeStep::new (60, 1000); let mut time_step = TimeStep::new (60, 1000);
let mut state = WorldState::new (); let mut state = WorldState::new ();
@ -307,11 +305,11 @@ fn main () {
let orange = orange * orange; let orange = orange * orange;
let green = green * green; let green = green * green;
unsafe { glezz::clear_color (1.0f32, 1.0f32, 1.0f32, 1.0f32);
gl::ClearColor (1.0f32, 1.0f32, 1.0f32, 1.0f32); glezz::clear (gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT);
gl::Clear (gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT); glezz::disable (gl::CULL_FACE);
gl::Disable (gl::CULL_FACE);
unsafe {
gl::Uniform3fv (unis ["min_bright"], 1, &black as *const Vec3 as *const f32); gl::Uniform3fv (unis ["min_bright"], 1, &black as *const Vec3 as *const f32);
gl::Uniform3fv (unis ["min_albedo"], 1, &white as *const Vec3 as *const f32); gl::Uniform3fv (unis ["min_albedo"], 1, &white as *const Vec3 as *const f32);

25
src/glezz.rs Normal file
View File

@ -0,0 +1,25 @@
// Trivial wrappers around GLESv2 C functions that should be safe
pub fn clear_color (r: f32, g: f32, b: f32, a: f32) {
unsafe {
gl::ClearColor (1.0f32, 1.0f32, 1.0f32, 1.0f32);
}
}
pub fn clear (flags: u32) {
unsafe {
gl::Clear (flags);
}
}
pub fn disable (constant: u32) {
unsafe {
gl::Disable (constant);
}
}
pub fn enable (constant: u32) {
unsafe {
gl::Enable (constant);
}
}

View File

@ -1,4 +1,5 @@
pub mod file; pub mod file;
pub mod glezz;
pub mod iqm; pub mod iqm;
pub mod shader; pub mod shader;
pub mod texture; pub mod texture;