Cleanup: avoid static vars to store legacy shaders
authorCampbell Barton <ideasman42@gmail.com>
Fri, 25 Jan 2019 23:31:53 +0000 (10:31 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 25 Jan 2019 23:33:14 +0000 (10:33 +1100)
source/blender/gpu/intern/gpu_shader.c

index 4cbdefc09a9f8247280b73997b079f09fcc3030c..4456f13e223d5befadcccf28dcac47ad22f976f4 100644 (file)
@@ -1111,28 +1111,28 @@ static const GPUShaderStages builtin_shader_stages[GPU_NUM_BUILTIN_SHADERS] = {
 
 GPUShader *GPU_shader_get_builtin_shader(eGPUBuiltinShader shader)
 {
-       BLI_assert(shader != GPU_NUM_BUILTIN_SHADERS); /* don't be a troll */
+       BLI_assert(shader < GPU_NUM_BUILTIN_SHADERS);
 
        if (builtin_shaders[shader] == NULL) {
+               GPUShaderStages stages_legacy = {NULL};
                const GPUShaderStages *stages = &builtin_shader_stages[shader];
 
-               if (shader == GPU_SHADER_EDGES_FRONT_BACK_PERSP && !GLEW_VERSION_3_2) {
+               if (shader == GPU_SHADER_EDGES_FRONT_BACK_PERSP) {
                        /* TODO: remove after switch to core profile (maybe) */
-                       static const GPUShaderStages legacy_fancy_edges = {
-                               .vert = datatoc_gpu_shader_edges_front_back_persp_legacy_vert_glsl,
-                               .frag = datatoc_gpu_shader_flat_color_alpha_test_0_frag_glsl,
-                       };
-                       stages = &legacy_fancy_edges;
+                       if (!GLEW_VERSION_3_2) {
+                               stages_legacy.vert = datatoc_gpu_shader_edges_front_back_persp_legacy_vert_glsl;
+                               stages_legacy.frag = datatoc_gpu_shader_flat_color_alpha_test_0_frag_glsl;
+                               stages = &stages_legacy;
+                       }
                }
-
-               if (shader == GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR && !GLEW_VERSION_3_2) {
+               else if (shader == GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR) {
                        /* Dashed need geometry shader, which are not supported by legacy OpenGL, fallback to solid lines. */
                        /* TODO: remove after switch to core profile (maybe) */
-                       static const GPUShaderStages legacy_dashed_lines = {
-                               .vert = datatoc_gpu_shader_3D_line_dashed_uniform_color_legacy_vert_glsl,
-                               .frag = datatoc_gpu_shader_2D_line_dashed_frag_glsl,
-                       };
-                       stages = &legacy_dashed_lines;
+                       if (!GLEW_VERSION_3_2) {
+                               stages_legacy.vert = datatoc_gpu_shader_3D_line_dashed_uniform_color_legacy_vert_glsl;
+                               stages_legacy.frag = datatoc_gpu_shader_2D_line_dashed_frag_glsl;
+                               stages = &stages_legacy;
+                       }
                }
 
                /* common case */