2021-32-bit-holiday-jam/src/glezz.rs

63 lines
1.1 KiB
Rust

// 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);
}
}
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);
}
}
pub fn enable_vertex_attrib_array (id: Option <u32>) {
if let Some (id) = id {
// Are safety checks really needed here?
unsafe {
gl::EnableVertexAttribArray (id);
}
}
}
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);
}
}
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);
}
}