From c6f71abbcac4bcb81c03e4c5fc53e7c7704e7e91 Mon Sep 17 00:00:00 2001 From: _ <> Date: Sun, 16 Feb 2020 23:48:26 +0000 Subject: [PATCH] :recycle: More safening --- src/bin/pumpkin.rs | 33 +++++++++++++++++++-------------- src/glezz.rs | 6 ++++++ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/bin/pumpkin.rs b/src/bin/pumpkin.rs index 9849319..0928d7d 100644 --- a/src/bin/pumpkin.rs +++ b/src/bin/pumpkin.rs @@ -317,28 +317,33 @@ fn main () { glezz::uniform_matrix_4fv (unis ["mvp"], &mvp_mat); glezz::uniform_3fv (unis ["object_space_light"], &object_space_light); + // This stuff actually still is unsafe because it's reading + // right from RAM I can still access. Using a VBO here + // might actually make it easier to make it safe. + unsafe { 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); + } + + if true { + glezz::uniform_3fv (unis ["albedo"], &green); - if true { - gl::Uniform3fv (unis ["albedo"], 1, &green as *const Vec3 as *const f32); - + unsafe { gl::DrawElements (gl::TRIANGLES, (model.meshes [1].num_triangles * 3) as i32, gl::UNSIGNED_INT, &model.get_index_slice (1) [0] as *const u8 as *const c_void); } + } + + let draw_sky = true; + if draw_sky { + glezz::uniform_matrix_4fv (unis ["mvp"], &sky_mvp_mat); + glezz::uniform_3fv (unis ["albedo"], &white); + glezz::uniform_3fv (unis ["min_bright"], &white); + glezz::uniform_3fv (unis ["min_albedo"], &black); + glezz::uniform_1i (unis ["texture"], 0); - let draw_sky = true; - if draw_sky { - //println! ("Drawing sky"); - - gl::UniformMatrix4fv (unis ["mvp"], 1, FALSE_U8, &sky_mvp_mat as *const Mat4 as *const f32); - - gl::Uniform3fv (unis ["albedo"], 1, &white as *const Vec3 as *const f32); - gl::Uniform3fv (unis ["min_bright"], 1, &white as *const Vec3 as *const f32); - gl::Uniform3fv (unis ["min_albedo"], 1, &black as *const Vec3 as *const f32); - gl::Uniform1i (unis ["texture"], 0); - + unsafe { point_to_model (&attrs, &sky_model); gl::DrawElements (gl::TRIANGLES, (sky_model.meshes [0].num_triangles * 3) as i32, gl::UNSIGNED_INT, &sky_model.get_index_slice (0) [0] as *const u8 as *const c_void); diff --git a/src/glezz.rs b/src/glezz.rs index 85254d6..65e4754 100644 --- a/src/glezz.rs +++ b/src/glezz.rs @@ -26,6 +26,12 @@ pub fn enable (constant: u32) { } } +pub fn uniform_1i (uni: i32, x: i32) { + unsafe { + gl::Uniform1i (uni, x); + } +} + pub fn uniform_3fv (uni: i32, v: &Vec3) { unsafe { gl::Uniform3fv (uni, 1, v as *const Vec3 as *const f32);