From 4e4a9d763d7bfd575c7e6c7f447be34b4429deee Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 24 Aug 2024 13:02:33 +0200 Subject: refactor(engine): use C string literals instead of cstr macro --- engine/Cargo.toml | 1 - engine/src/renderer/opengl.rs | 39 ++++++++++++++++----------------------- 2 files changed, 16 insertions(+), 24 deletions(-) (limited to 'engine') diff --git a/engine/Cargo.toml b/engine/Cargo.toml index 6d5effe..b3868ac 100644 --- a/engine/Cargo.toml +++ b/engine/Cargo.toml @@ -11,7 +11,6 @@ glfw = { path = "../glfw", features = ["opengl"] } thiserror = "1.0.49" gl = "0.14.0" bitflags = "2.4.0" -cstr = "0.2.11" tracing = { version = "0.1.39", optional = true } seq-macro = "0.3.5" paste = "1.0.14" diff --git a/engine/src/renderer/opengl.rs b/engine/src/renderer/opengl.rs index 888f760..463e654 100644 --- a/engine/src/renderer/opengl.rs +++ b/engine/src/renderer/opengl.rs @@ -5,7 +5,6 @@ use std::ffi::{c_void, CString}; use std::ops::Deref; use std::process::abort; -use cstr::cstr; use ecs::actions::Actions; use ecs::component::local::Local; use ecs::query::options::{Not, With}; @@ -427,14 +426,12 @@ fn apply_transformation_matrices( window_size: Dimens, ) { - gl_shader_program.set_uniform_matrix_4fv( - cstr!("model"), - &create_transformation_matrix(transformation), - ); + gl_shader_program + .set_uniform_matrix_4fv(c"model", &create_transformation_matrix(transformation)); let view = create_view(camera, camera_pos); - gl_shader_program.set_uniform_matrix_4fv(cstr!("view"), &view); + gl_shader_program.set_uniform_matrix_4fv(c"view", &view); #[allow(clippy::cast_precision_loss)] let projection = match &camera.projection { @@ -444,7 +441,7 @@ fn apply_transformation_matrices( ), }; - gl_shader_program.set_uniform_matrix_4fv(cstr!("projection"), &projection); + gl_shader_program.set_uniform_matrix_4fv(c"projection", &projection); } fn apply_light( @@ -488,10 +485,8 @@ fn apply_light( // There probably won't be more than 2147483648 directional lights #[allow(clippy::cast_possible_wrap, clippy::cast_possible_truncation)] - gl_shader_program.set_uniform_1i( - cstr!("directional_light_cnt"), - directional_lights.len() as i32, - ); + gl_shader_program + .set_uniform_1i(c"directional_light_cnt", directional_lights.len() as i32); for (point_light_index, point_light) in point_lights.iter().enumerate() { gl_shader_program.set_uniform_vec_3fv( @@ -516,10 +511,10 @@ fn apply_light( // There probably won't be more than 2147483648 point lights #[allow(clippy::cast_possible_wrap, clippy::cast_possible_truncation)] - gl_shader_program.set_uniform_1i(cstr!("point_light_cnt"), point_lights.len() as i32); + gl_shader_program.set_uniform_1i(c"point_light_cnt", point_lights.len() as i32); gl_shader_program.set_uniform_vec_3fv( - cstr!("material.ambient"), + c"material.ambient", &if material_flags.use_ambient_color { material.ambient.clone() } else { @@ -529,35 +524,33 @@ fn apply_light( ); gl_shader_program - .set_uniform_vec_3fv(cstr!("material.diffuse"), &material.diffuse.clone().into()); + .set_uniform_vec_3fv(c"material.diffuse", &material.diffuse.clone().into()); #[allow(clippy::cast_possible_wrap)] - gl_shader_program.set_uniform_vec_3fv( - cstr!("material.specular"), - &material.specular.clone().into(), - ); + gl_shader_program + .set_uniform_vec_3fv(c"material.specular", &material.specular.clone().into()); #[allow(clippy::cast_possible_wrap)] gl_shader_program.set_uniform_1i( - cstr!("material.ambient_map"), + c"material.ambient_map", material.ambient_map.into_inner() as i32, ); #[allow(clippy::cast_possible_wrap)] gl_shader_program.set_uniform_1i( - cstr!("material.diffuse_map"), + c"material.diffuse_map", material.diffuse_map.into_inner() as i32, ); #[allow(clippy::cast_possible_wrap)] gl_shader_program.set_uniform_1i( - cstr!("material.specular_map"), + c"material.specular_map", material.specular_map.into_inner() as i32, ); - gl_shader_program.set_uniform_1fv(cstr!("material.shininess"), material.shininess); + gl_shader_program.set_uniform_1fv(c"material.shininess", material.shininess); - gl_shader_program.set_uniform_vec_3fv(cstr!("view_pos"), &camera_pos.position); + gl_shader_program.set_uniform_vec_3fv(c"view_pos", &camera_pos.position); } fn set_light_attenuation_uniforms( -- cgit v1.2.3-18-g5258