From bf4358ed0c545a14686af0d91ab78d784b988def Mon Sep 17 00:00:00 2001 From: Aaron Carlisle Date: Thu, 30 Dec 2021 17:39:23 -0500 Subject: Cleanup: Use switch to get gpu shader name Rather than using the array syntax that doesnt work in C++, use a switch state which is also much easier to read. --- .../nodes/shader/nodes/node_shader_mapping.c | 26 ++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/source/blender/nodes/shader/nodes/node_shader_mapping.c b/source/blender/nodes/shader/nodes/node_shader_mapping.c index cabfecdb6ee..7f192058307 100644 --- a/source/blender/nodes/shader/nodes/node_shader_mapping.c +++ b/source/blender/nodes/shader/nodes/node_shader_mapping.c @@ -37,21 +37,29 @@ static bNodeSocketTemplate sh_node_mapping_out[] = { {-1, ""}, }; +static const char *gpu_shader_get_name(int mode) +{ + switch (mode) { + case NODE_MAPPING_TYPE_POINT: + return "mapping_point"; + case NODE_MAPPING_TYPE_TEXTURE: + return "mapping_texture"; + case NODE_MAPPING_TYPE_VECTOR: + return "mapping_vector"; + case NODE_MAPPING_TYPE_NORMAL: + return "mapping_normal"; + } + return NULL; +} + static int gpu_shader_mapping(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - static const char *names[] = { - [NODE_MAPPING_TYPE_POINT] = "mapping_point", - [NODE_MAPPING_TYPE_TEXTURE] = "mapping_texture", - [NODE_MAPPING_TYPE_VECTOR] = "mapping_vector", - [NODE_MAPPING_TYPE_NORMAL] = "mapping_normal", - }; - - if (node->custom1 < ARRAY_SIZE(names) && names[node->custom1]) { - return GPU_stack_link(mat, node, names[node->custom1], in, out); + if (gpu_shader_get_name(node->custom1)) { + return GPU_stack_link(mat, node, gpu_shader_get_name(node->custom1), in, out); } return 0; -- cgit v1.2.3