From 1a43ce15edec5b730922d73dae2f2bfe379bf930 Mon Sep 17 00:00:00 2001 From: Ludo <92421677+SmartManLudo@users.noreply.github.com> Date: Wed, 3 May 2023 19:31:37 +0530 Subject: [PATCH] added match statement instead of if-else block (#8500) # Objective Replaced the if-else statement block in favor of a match statement to give a more cleaner code. --- crates/bevy_sprite/src/mesh2d/mesh.rs | 44 ++++++++++++++++----------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/crates/bevy_sprite/src/mesh2d/mesh.rs b/crates/bevy_sprite/src/mesh2d/mesh.rs index 11d4552af5..be626ea08f 100644 --- a/crates/bevy_sprite/src/mesh2d/mesh.rs +++ b/crates/bevy_sprite/src/mesh2d/mesh.rs @@ -390,25 +390,33 @@ impl SpecializedMeshPipeline for Mesh2dPipeline { let method = key.intersection(Mesh2dPipelineKey::TONEMAP_METHOD_RESERVED_BITS); - if method == Mesh2dPipelineKey::TONEMAP_METHOD_NONE { - shader_defs.push("TONEMAP_METHOD_NONE".into()); - } else if method == Mesh2dPipelineKey::TONEMAP_METHOD_REINHARD { - shader_defs.push("TONEMAP_METHOD_REINHARD".into()); - } else if method == Mesh2dPipelineKey::TONEMAP_METHOD_REINHARD_LUMINANCE { - shader_defs.push("TONEMAP_METHOD_REINHARD_LUMINANCE".into()); - } else if method == Mesh2dPipelineKey::TONEMAP_METHOD_ACES_FITTED { - shader_defs.push("TONEMAP_METHOD_ACES_FITTED".into()); - } else if method == Mesh2dPipelineKey::TONEMAP_METHOD_AGX { - shader_defs.push("TONEMAP_METHOD_AGX".into()); - } else if method == Mesh2dPipelineKey::TONEMAP_METHOD_SOMEWHAT_BORING_DISPLAY_TRANSFORM - { - shader_defs.push("TONEMAP_METHOD_SOMEWHAT_BORING_DISPLAY_TRANSFORM".into()); - } else if method == Mesh2dPipelineKey::TONEMAP_METHOD_BLENDER_FILMIC { - shader_defs.push("TONEMAP_METHOD_BLENDER_FILMIC".into()); - } else if method == Mesh2dPipelineKey::TONEMAP_METHOD_TONY_MC_MAPFACE { - shader_defs.push("TONEMAP_METHOD_TONY_MC_MAPFACE".into()); + match method { + Mesh2dPipelineKey::TONEMAP_METHOD_NONE => { + shader_defs.push("TONEMAP_METHOD_NONE".into()); + } + Mesh2dPipelineKey::TONEMAP_METHOD_REINHARD => { + shader_defs.push("TONEMAP_METHOD_REINHARD".into()); + } + Mesh2dPipelineKey::TONEMAP_METHOD_REINHARD_LUMINANCE => { + shader_defs.push("TONEMAP_METHOD_REINHARD_LUMINANCE".into()); + } + Mesh2dPipelineKey::TONEMAP_METHOD_ACES_FITTED => { + shader_defs.push("TONEMAP_METHOD_ACES_FITTED".into()); + } + Mesh2dPipelineKey::TONEMAP_METHOD_AGX => { + shader_defs.push("TONEMAP_METHOD_AGX".into()); + } + Mesh2dPipelineKey::TONEMAP_METHOD_SOMEWHAT_BORING_DISPLAY_TRANSFORM => { + shader_defs.push("TONEMAP_METHOD_SOMEWHAT_BORING_DISPLAY_TRANSFORM".into()); + } + Mesh2dPipelineKey::TONEMAP_METHOD_BLENDER_FILMIC => { + shader_defs.push("TONEMAP_METHOD_BLENDER_FILMIC".into()); + } + Mesh2dPipelineKey::TONEMAP_METHOD_TONY_MC_MAPFACE => { + shader_defs.push("TONEMAP_METHOD_TONY_MC_MAPFACE".into()); + } + _ => {} } - // Debanding is tied to tonemapping in the shader, cannot run without it. if key.contains(Mesh2dPipelineKey::DEBAND_DITHER) { shader_defs.push("DEBAND_DITHER".into());