Replace string lookups for uniforms with const int lookups
parent
3c37cd030b
commit
a1c21b92c9
|
@ -2,6 +2,8 @@ use glam::{Mat4, Vec3, Vec4};
|
|||
|
||||
use sdl2::event::Event;
|
||||
use sdl2::keyboard::{Keycode, Scancode};
|
||||
use std::collections::*;
|
||||
use std::iter::FromIterator;
|
||||
use std::time::{Duration};
|
||||
|
||||
use opengl_rust::*;
|
||||
|
@ -94,6 +96,18 @@ impl WorldState {
|
|||
}
|
||||
}
|
||||
|
||||
mod uniforms {
|
||||
use iota::iota;
|
||||
iota! {
|
||||
pub const MVP: u32 = iota;
|
||||
, OBJECT_SPACE_LIGHT
|
||||
, ALBEDO
|
||||
, MIN_ALBEDO
|
||||
, MIN_BRIGHT
|
||||
, TEXTURE
|
||||
}
|
||||
}
|
||||
|
||||
fn main () {
|
||||
let sdl_context = sdl2::init ().unwrap ();
|
||||
let video_subsystem = sdl_context.video ().unwrap ();
|
||||
|
@ -127,14 +141,24 @@ fn main () {
|
|||
|
||||
let shader_program = ShaderProgram::new (&vert_shader, &frag_shader).unwrap ();
|
||||
|
||||
let unis = shader_program.get_uniform_locations (vec! [
|
||||
"mvp",
|
||||
"object_space_light",
|
||||
"albedo",
|
||||
"min_albedo",
|
||||
"min_bright",
|
||||
"texture",
|
||||
].into_iter ());
|
||||
let uni_lookup: HashMap <_, &str> = HashMap::from_iter ({
|
||||
use uniforms::*;
|
||||
vec! [
|
||||
(MVP, "mvp"),
|
||||
(OBJECT_SPACE_LIGHT, "object_space_light"),
|
||||
(ALBEDO, "albedo"),
|
||||
(MIN_ALBEDO, "min_albedo"),
|
||||
(MIN_BRIGHT, "min_bright"),
|
||||
(TEXTURE, "texture"),
|
||||
].into_iter ()
|
||||
});
|
||||
|
||||
let unis = shader_program.get_uniform_locations (uni_lookup.values ().map (|s| *s));
|
||||
|
||||
let unis: HashMap <u32, i32> = HashMap::from_iter (
|
||||
uni_lookup.iter ()
|
||||
.map (|(key, name)| (*key, *unis.get (*name).unwrap ()))
|
||||
);
|
||||
|
||||
let attrs = shader_program.get_attribute_locations (vec! [
|
||||
"pos",
|
||||
|
@ -224,28 +248,31 @@ 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);
|
||||
{
|
||||
use uniforms::*;
|
||||
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);
|
||||
glezz::uniform_matrix_4fv (unis [&MVP], &mvp_mat);
|
||||
glezz::uniform_3fv (unis [&OBJECT_SPACE_LIGHT], &object_space_light);
|
||||
|
||||
renderable_model.draw (&attrs, 0);
|
||||
|
||||
glezz::uniform_3fv (unis ["albedo"], &green);
|
||||
glezz::uniform_3fv (unis [&ALBEDO], &green);
|
||||
renderable_model.draw (&attrs, 1);
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
renderable_sky.draw (&attrs, 0);
|
||||
}
|
||||
}
|
||||
|
||||
window.gl_swap_window ();
|
||||
|
||||
|
|
36
src/iqm.rs
36
src/iqm.rs
|
@ -40,26 +40,30 @@ iota! {
|
|||
}
|
||||
|
||||
pub mod types {
|
||||
pub const POSITION: usize = 0;
|
||||
pub const TEXCOORD: usize = 1;
|
||||
pub const NORMAL: usize = 2;
|
||||
pub const TANGENT: usize = 3;
|
||||
pub const BLENDINDEXES: usize = 4;
|
||||
pub const BLENDWEIGHTS: usize = 5;
|
||||
pub const COLOR: usize = 6;
|
||||
iota! {
|
||||
pub const POSITION: usize = iota;
|
||||
, TEXCOORD
|
||||
, NORMAL
|
||||
, TANGENT
|
||||
, BLENDINDEXES
|
||||
, BLENDWEIGHTS
|
||||
, COLOR
|
||||
}
|
||||
pub const CUSTOM: usize = 0x10;
|
||||
}
|
||||
|
||||
pub mod formats {
|
||||
pub const BYTE: u32 = 0;
|
||||
pub const UBYTE: u32 = 1;
|
||||
pub const SHORT: u32 = 2;
|
||||
pub const USHORT: u32 = 3;
|
||||
pub const INT: u32 = 4;
|
||||
pub const UINT: u32 = 5;
|
||||
pub const HALF: u32 = 6;
|
||||
pub const FLOAT: u32 = 7;
|
||||
pub const DOUBLE: u32 = 8;
|
||||
iota! {
|
||||
pub const BYTE: u32 = iota;
|
||||
, UBYTE
|
||||
, SHORT
|
||||
, USHORT
|
||||
, INT
|
||||
, UINT
|
||||
, HALF
|
||||
, FLOAT
|
||||
, DOUBLE
|
||||
}
|
||||
}
|
||||
|
||||
#[derive (Debug)]
|
||||
|
|
Loading…
Reference in New Issue