diff options
author | HampusM <hampus@hampusmat.com> | 2024-08-24 13:02:33 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-08-24 13:02:33 +0200 |
commit | 4e4a9d763d7bfd575c7e6c7f447be34b4429deee (patch) | |
tree | 69cf94d85cce47f23a3a1e982f95c5959c210f4d | |
parent | cff2575a32219d4294ab05d69ad37eb6bd7a7b2d (diff) |
refactor(engine): use C string literals instead of cstr macro
-rw-r--r-- | Cargo.lock | 11 | ||||
-rw-r--r-- | engine/Cargo.toml | 1 | ||||
-rw-r--r-- | engine/src/renderer/opengl.rs | 39 |
3 files changed, 16 insertions, 35 deletions
@@ -109,16 +109,6 @@ dependencies = [ ] [[package]] -name = "cstr" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8aa998c33a6d3271e3678950a22134cd7dd27cef86dee1b611b5b14207d1d90b" -dependencies = [ - "proc-macro2", - "quote", -] - -[[package]] name = "ecs" version = "0.1.0" dependencies = [ @@ -145,7 +135,6 @@ name = "engine" version = "0.1.0" dependencies = [ "bitflags 2.4.0", - "cstr", "ecs", "gl", "glfw", 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<u32>, ) { - 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<PointLightHolder>( @@ -488,10 +485,8 @@ fn apply_light<PointLightHolder>( // 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<PointLightHolder>( // 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<PointLightHolder>( ); 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( |