♻️ Make more safe wrappers

main
_ 2020-02-16 23:44:01 +00:00
parent 963b344122
commit 09ce9ab580
2 changed files with 30 additions and 8 deletions

View File

@ -296,6 +296,7 @@ fn main () {
let light = Vec3::from ((2.0, 0.0, 5.0)).normalize ();
let object_space_light = model_mat.inverse () * Vec4::from ((light.x (), light.y (), light.z (), 0.0));
let object_space_light = Vec3::from ((object_space_light.x (), object_space_light.y (), object_space_light.z ()));
let orange = color_from_255 ((255.0, 154.0, 0.0));
let green = color_from_255 ((14.0, 127.0, 24.0));
@ -309,15 +310,14 @@ fn main () {
glezz::clear (gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT);
glezz::disable (gl::CULL_FACE);
glezz::uniform_3fv (unis ["min_bright"], &black);
glezz::uniform_3fv (unis ["min_albedo"], &white);
glezz::uniform_3fv (unis ["albedo"], &orange);
glezz::uniform_matrix_4fv (unis ["mvp"], &mvp_mat);
glezz::uniform_3fv (unis ["object_space_light"], &object_space_light);
unsafe {
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::UniformMatrix4fv (unis ["mvp"], 1, FALSE_U8, &mvp_mat as *const Mat4 as *const f32);
gl::Uniform3fv (unis ["object_space_light"], 1, &object_space_light as *const Vec4 as *const f32);
gl::Uniform3fv (unis ["albedo"], 1, &orange as *const Vec3 as *const f32);
point_to_model (&attrs, &model);
gl::DrawElements (gl::TRIANGLES, (model.meshes [0].num_triangles * 3) as i32, gl::UNSIGNED_INT, &model.get_index_slice (0) [0] as *const u8 as *const c_void);

View File

@ -1,5 +1,7 @@
// Trivial wrappers around GLESv2 C functions that should be safe
use glam::{Mat4, Vec3, Vec4};
pub fn clear_color (r: f32, g: f32, b: f32, a: f32) {
unsafe {
gl::ClearColor (1.0f32, 1.0f32, 1.0f32, 1.0f32);
@ -23,3 +25,23 @@ pub fn enable (constant: u32) {
gl::Enable (constant);
}
}
pub fn uniform_3fv (uni: i32, v: &Vec3) {
unsafe {
gl::Uniform3fv (uni, 1, v as *const Vec3 as *const f32);
}
}
pub fn uniform_4fv (uni: i32, v: &Vec4) {
unsafe {
gl::Uniform4fv (uni, 1, v as *const Vec4 as *const f32);
}
}
pub fn uniform_matrix_4fv (uni: i32, m: &Mat4) {
const FALSE_U8: u8 = 0;
unsafe {
gl::UniformMatrix4fv (uni, 1, FALSE_U8, m as *const Mat4 as *const f32);
}
}