Cleanup: move clipping shader lib & define into struct
authorCampbell Barton <ideasman42@gmail.com>
Sun, 10 Feb 2019 00:06:22 +0000 (11:06 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 10 Feb 2019 00:16:31 +0000 (11:16 +1100)
Also compare clipping with the draw context instead of
accessing the RegionView3D, currently they're matching
but this might not always be the case.

12 files changed:
source/blender/draw/engines/basic/basic_engine.c
source/blender/draw/intern/draw_common.c
source/blender/draw/modes/edit_curve_mode.c
source/blender/draw/modes/edit_lattice_mode.c
source/blender/draw/modes/edit_mesh_mode.c
source/blender/draw/modes/edit_metaball_mode.c
source/blender/draw/modes/object_mode.c
source/blender/draw/modes/overlay_mode.c
source/blender/draw/modes/paint_vertex_mode.c
source/blender/draw/modes/paint_weight_mode.c
source/blender/gpu/GPU_shader.h
source/blender/gpu/intern/gpu_shader.c

index 72ff8de..5123132 100644 (file)
@@ -94,9 +94,8 @@ static void basic_cache_init(void *vedata)
        const DRWContextState *draw_ctx = DRW_context_state_get();
        BASIC_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
        const RegionView3D *rv3d = draw_ctx->rv3d;
-       const bool is_clip = (rv3d->rflag & RV3D_CLIPPING) != 0;
 
-       if (is_clip) {
+       if (draw_ctx->sh_cfg == GPU_SHADER_CFG_CLIPPED) {
                DRW_state_clip_planes_set_from_rv3d(draw_ctx->rv3d);
        }
 
@@ -109,7 +108,7 @@ static void basic_cache_init(void *vedata)
                psl->depth_pass = DRW_pass_create(
                        "Depth Pass", DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_WIRE);
                stl->g_data->depth_shgrp = DRW_shgroup_create(sh_data->depth, psl->depth_pass);
-               if (rv3d->rflag & RV3D_CLIPPING) {
+               if (draw_ctx->sh_cfg == GPU_SHADER_CFG_CLIPPED) {
                        DRW_shgroup_world_clip_planes_from_rv3d(stl->g_data->depth_shgrp, rv3d);
                }
 
@@ -117,7 +116,7 @@ static void basic_cache_init(void *vedata)
                        "Depth Pass Cull",
                        DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_CULL_BACK);
                stl->g_data->depth_shgrp_cull = DRW_shgroup_create(sh_data->depth, psl->depth_pass_cull);
-               if (rv3d->rflag & RV3D_CLIPPING) {
+               if (draw_ctx->sh_cfg == GPU_SHADER_CFG_CLIPPED) {
                        DRW_shgroup_world_clip_planes_from_rv3d(stl->g_data->depth_shgrp_cull, rv3d);
                }
        }
index e222a6b..b44e973 100644 (file)
@@ -228,7 +228,6 @@ extern char datatoc_armature_stick_frag_glsl[];
 extern char datatoc_armature_dof_vert_glsl[];
 
 extern char datatoc_common_globals_lib_glsl[];
-extern char datatoc_gpu_shader_cfg_world_clip_lib_glsl[];
 
 extern char datatoc_gpu_shader_flat_color_frag_glsl[];
 extern char datatoc_gpu_shader_3D_smooth_color_frag_glsl[];
@@ -501,13 +500,12 @@ DRWShadingGroup *shgroup_instance_alpha(DRWPass *pass, struct GPUBatch *geom, eG
 DRWShadingGroup *shgroup_instance_empty_axes(DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig sh_cfg)
 {
        COMMON_Shaders *sh_data = &g_shaders[sh_cfg];
-       const char *world_clip_lib_or_empty = (sh_cfg == GPU_SHADER_CFG_CLIPPED) ? datatoc_gpu_shader_cfg_world_clip_lib_glsl : "";
-       const char *world_clip_def_or_empty = (sh_cfg == GPU_SHADER_CFG_CLIPPED) ? "#define USE_WORLD_CLIP_PLANES\n" : "";
        if (sh_data->empty_axes_sh == NULL) {
+               const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg];
                sh_data->empty_axes_sh = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_object_empty_axes_vert_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_object_empty_axes_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_gpu_shader_flat_color_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
        }
 
@@ -702,13 +700,11 @@ DRWShadingGroup *shgroup_instance_mball_handles(DRWPass *pass, eGPUShaderConfig
 {
        COMMON_Shaders *sh_data = &g_shaders[sh_cfg];
        if (sh_data->mball_handles == NULL) {
-               bool is_clip = (sh_cfg == GPU_SHADER_CFG_CLIPPED);
-               const char *world_clip_lib_or_empty = is_clip ? datatoc_gpu_shader_cfg_world_clip_lib_glsl : "";
-               const char *world_clip_def_or_empty = is_clip ? "#define USE_WORLD_CLIP_PLANES\n" : "";
+               const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg];
                sh_data->mball_handles = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_object_mball_handles_vert_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_object_mball_handles_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_gpu_shader_flat_color_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
        }
 
@@ -735,13 +731,12 @@ DRWShadingGroup *shgroup_instance_bone_shape_outline(
 {
        COMMON_Shaders *sh_data = &g_shaders[sh_cfg];
        if (sh_data->shape_outline == NULL) {
-               const char *world_clip_lib_or_empty = (sh_cfg == GPU_SHADER_CFG_CLIPPED) ? datatoc_gpu_shader_cfg_world_clip_lib_glsl : "";
-               const char *world_clip_def_or_empty = (sh_cfg == GPU_SHADER_CFG_CLIPPED) ? "#define USE_WORLD_CLIP_PLANES\n" : "";
+               const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg];
                sh_data->shape_outline = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_armature_shape_outline_vert_glsl, NULL},
-                       .geom = (const char *[]){world_clip_lib_or_empty, datatoc_armature_shape_outline_geom_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_armature_shape_outline_vert_glsl, NULL},
+                       .geom = (const char *[]){sh_cfg_data->lib, datatoc_armature_shape_outline_geom_glsl, NULL},
                        .frag = (const char *[]){datatoc_gpu_shader_flat_color_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
        }
 
@@ -765,12 +760,11 @@ DRWShadingGroup *shgroup_instance_bone_shape_solid(
 {
        COMMON_Shaders *sh_data = &g_shaders[sh_cfg];
        if (sh_data->shape_solid == NULL) {
-               const char *world_clip_lib_or_empty = (sh_cfg == GPU_SHADER_CFG_CLIPPED) ? datatoc_gpu_shader_cfg_world_clip_lib_glsl : "";
-               const char *world_clip_def_or_empty = (sh_cfg == GPU_SHADER_CFG_CLIPPED) ? "#define USE_WORLD_CLIP_PLANES\n" : "";
+               const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg];
                sh_data->shape_solid = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_armature_shape_solid_vert_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_armature_shape_solid_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_armature_shape_solid_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
        }
 
@@ -841,12 +835,11 @@ DRWShadingGroup *shgroup_instance_bone_stick(DRWPass *pass, eGPUShaderConfig sh_
 {
        COMMON_Shaders *sh_data = &g_shaders[sh_cfg];
        if (sh_data->bone_stick == NULL) {
-               const char *world_clip_lib_or_empty = (sh_cfg == GPU_SHADER_CFG_CLIPPED) ? datatoc_gpu_shader_cfg_world_clip_lib_glsl : "";
-               const char *world_clip_def_or_empty = (sh_cfg == GPU_SHADER_CFG_CLIPPED) ? "#define USE_WORLD_CLIP_PLANES\n" : "";
+               const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg];
                sh_data->bone_stick = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_armature_stick_vert_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_armature_stick_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_armature_stick_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
        }
 
index 0a2a8ed..2289a58 100644 (file)
@@ -38,7 +38,6 @@
  * Not needed for constant color. */
 
 extern char datatoc_common_globals_lib_glsl[];
-extern char datatoc_gpu_shader_cfg_world_clip_lib_glsl[];
 extern char datatoc_edit_curve_overlay_loosevert_vert_glsl[];
 extern char datatoc_edit_curve_overlay_normals_vert_glsl[];
 extern char datatoc_edit_curve_overlay_handle_vert_glsl[];
@@ -108,14 +107,12 @@ static void EDIT_CURVE_engine_init(void *UNUSED(vedata))
 {
        const DRWContextState *draw_ctx = DRW_context_state_get();
        EDIT_CURVE_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
-       const bool is_clip = (draw_ctx->rv3d->rflag & RV3D_CLIPPING) != 0;
 
-       if (is_clip) {
+       if (draw_ctx->sh_cfg == GPU_SHADER_CFG_CLIPPED) {
                DRW_state_clip_planes_set_from_rv3d(draw_ctx->rv3d);
        }
 
-       const char *world_clip_lib_or_empty = is_clip ? datatoc_gpu_shader_cfg_world_clip_lib_glsl : "";
-       const char *world_clip_def_or_empty = is_clip ? "#define USE_WORLD_CLIP_PLANES\n" : "";
+       const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[draw_ctx->sh_cfg];
 
        if (!sh_data->wire_sh) {
                sh_data->wire_sh = GPU_shader_get_builtin_shader_with_config(
@@ -124,26 +121,26 @@ static void EDIT_CURVE_engine_init(void *UNUSED(vedata))
 
        if (!sh_data->wire_normals_sh) {
                sh_data->wire_normals_sh = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_edit_curve_overlay_normals_vert_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_edit_curve_overlay_normals_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_gpu_shader_uniform_color_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
        }
 
        if (!sh_data->overlay_edge_sh) {
                sh_data->overlay_edge_sh = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_edit_curve_overlay_handle_vert_glsl, NULL},
-                       .geom = (const char *[]){world_clip_lib_or_empty, datatoc_common_globals_lib_glsl, datatoc_edit_curve_overlay_handle_geom_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_edit_curve_overlay_handle_vert_glsl, NULL},
+                       .geom = (const char *[]){sh_cfg_data->lib, datatoc_common_globals_lib_glsl, datatoc_edit_curve_overlay_handle_geom_glsl, NULL},
                        .frag = (const char *[]){datatoc_gpu_shader_3D_smooth_color_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
        }
 
        if (!sh_data->overlay_vert_sh) {
                sh_data->overlay_vert_sh = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_common_globals_lib_glsl, datatoc_edit_curve_overlay_loosevert_vert_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_common_globals_lib_glsl, datatoc_edit_curve_overlay_loosevert_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_gpu_shader_point_varying_color_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
 
        }
index 97471ef..7ac24ac 100644 (file)
@@ -29,7 +29,6 @@
 
 #include "draw_common.h"
 
-extern char datatoc_gpu_shader_cfg_world_clip_lib_glsl[];
 extern char datatoc_common_globals_lib_glsl[];
 
 extern char datatoc_edit_lattice_overlay_loosevert_vert_glsl[];
@@ -137,12 +136,10 @@ static void EDIT_LATTICE_engine_init(void *vedata)
 
        const DRWContextState *draw_ctx = DRW_context_state_get();
        EDIT_LATTICE_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
-       const bool is_clip = (draw_ctx->rv3d->rflag & RV3D_CLIPPING) != 0;
-       if (is_clip) {
+       if (draw_ctx->sh_cfg == GPU_SHADER_CFG_CLIPPED) {
                DRW_state_clip_planes_set_from_rv3d(draw_ctx->rv3d);
        }
-       const char *world_clip_lib_or_empty = is_clip ? datatoc_gpu_shader_cfg_world_clip_lib_glsl : "";
-       const char *world_clip_def_or_empty = is_clip ? "#define USE_WORLD_CLIP_PLANES\n" : "";
+       const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[draw_ctx->sh_cfg];
 
        if (!sh_data->wire) {
                sh_data->wire = GPU_shader_get_builtin_shader_with_config(GPU_SHADER_3D_SMOOTH_COLOR, draw_ctx->sh_cfg);
@@ -151,7 +148,7 @@ static void EDIT_LATTICE_engine_init(void *vedata)
        if (!sh_data->overlay_vert) {
                sh_data->overlay_vert = GPU_shader_create_from_arrays({
                        .vert = (const char *[]){
-                           world_clip_lib_or_empty,
+                           sh_cfg_data->lib,
                            datatoc_common_globals_lib_glsl,
                            datatoc_edit_lattice_overlay_loosevert_vert_glsl,
                            NULL},
@@ -159,7 +156,7 @@ static void EDIT_LATTICE_engine_init(void *vedata)
                            datatoc_common_globals_lib_glsl,
                            datatoc_edit_lattice_overlay_frag_glsl,
                            NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
 
        }
index c304e61..420c099 100644 (file)
@@ -42,8 +42,6 @@
 #include "BLI_dynstr.h"
 #include "BLI_string_utils.h"
 
-extern char datatoc_gpu_shader_cfg_world_clip_lib_glsl[];
-
 extern char datatoc_paint_weight_vert_glsl[];
 extern char datatoc_paint_weight_frag_glsl[];
 
@@ -159,7 +157,6 @@ static void EDIT_MESH_engine_init(void *vedata)
 
        const DRWContextState *draw_ctx = DRW_context_state_get();
        EDIT_MESH_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
-       const bool is_clip = (draw_ctx->rv3d->rflag & RV3D_CLIPPING) != 0;
 
        const float *viewport_size = DRW_viewport_size_get();
        const int size[2] = {(int)viewport_size[0], (int)viewport_size[1]};
@@ -174,21 +171,20 @@ static void EDIT_MESH_engine_init(void *vedata)
                GPU_ATTACHMENT_TEXTURE(e_data.occlude_wire_color_tx)
        });
 
-       if (is_clip) {
+       if (draw_ctx->sh_cfg == GPU_SHADER_CFG_CLIPPED) {
                DRW_state_clip_planes_set_from_rv3d(draw_ctx->rv3d);
        }
 
-       const char *world_clip_lib_or_empty = is_clip ? datatoc_gpu_shader_cfg_world_clip_lib_glsl : "";
-       const char *world_clip_def_or_empty = is_clip ? "#define USE_WORLD_CLIP_PLANES\n" : "";
+       const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[draw_ctx->sh_cfg];
 
        if (!sh_data->weight_face) {
                sh_data->weight_face = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_common_globals_lib_glsl, datatoc_paint_weight_vert_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_common_globals_lib_glsl, datatoc_paint_weight_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_common_globals_lib_glsl, datatoc_paint_weight_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
 
-               char *lib = BLI_string_joinN(world_clip_lib_or_empty, datatoc_common_globals_lib_glsl, datatoc_edit_mesh_overlay_common_lib_glsl);
+               char *lib = BLI_string_joinN(sh_cfg_data->lib, datatoc_common_globals_lib_glsl, datatoc_edit_mesh_overlay_common_lib_glsl);
                /* Use geometry shader to draw edge wireframe. This ensure us
                 * the same result accross platforms and more flexibility. But
                 * we pay the cost of running a geometry shader.
@@ -203,58 +199,58 @@ static void EDIT_MESH_engine_init(void *vedata)
                sh_data->overlay_face = GPU_shader_create_from_arrays({
                        .vert = (const char *[]){lib, datatoc_edit_mesh_overlay_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_gpu_shader_3D_smooth_color_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, "#define FACE\n", NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, "#define FACE\n", NULL},
                });
                sh_data->overlay_edge = GPU_shader_create_from_arrays({
                        .vert = (const char *[]){lib, datatoc_edit_mesh_overlay_vert_glsl, NULL},
                        .frag = (const char *[]){lib, datatoc_edit_mesh_overlay_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, use_geom_def, "#define EDGE\n", NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, use_geom_def, "#define EDGE\n", NULL},
                        .geom = (use_geom_shader) ? geom_sh_code : NULL,
                });
                sh_data->overlay_edge_flat = GPU_shader_create_from_arrays({
                        .vert = (const char *[]){lib, datatoc_edit_mesh_overlay_vert_glsl, NULL},
                        .frag = (const char *[]){lib, datatoc_edit_mesh_overlay_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, use_geom_def, "#define EDGE\n", "#define FLAT\n", NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, use_geom_def, "#define EDGE\n", "#define FLAT\n", NULL},
                        .geom = (use_geom_shader) ? geom_sh_code : NULL,
                });
                sh_data->overlay_vert = GPU_shader_create_from_arrays({
                        .vert = (const char *[]){lib, datatoc_edit_mesh_overlay_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_gpu_shader_point_varying_color_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, "#define VERT\n", NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, "#define VERT\n", NULL},
                });
                sh_data->overlay_facedot = GPU_shader_create_from_arrays({
                        .vert = (const char *[]){lib, datatoc_edit_mesh_overlay_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_gpu_shader_point_varying_color_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, "#define FACEDOT\n", NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, "#define FACEDOT\n", NULL},
                });
                sh_data->overlay_facefill = GPU_shader_create_from_arrays({
                        .vert = (const char *[]){lib, datatoc_edit_mesh_overlay_facefill_vert_glsl, NULL},
                        .frag = (const char *[]){lib, datatoc_edit_mesh_overlay_facefill_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
                MEM_freeN(lib);
 
                sh_data->overlay_mix = DRW_shader_create_fullscreen(datatoc_edit_mesh_overlay_mix_frag_glsl, NULL);
 
                sh_data->normals_face = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_edit_normals_vert_glsl, NULL},
-                       .geom = (const char *[]){world_clip_lib_or_empty, datatoc_edit_normals_geom_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_edit_normals_vert_glsl, NULL},
+                       .geom = (const char *[]){sh_cfg_data->lib, datatoc_edit_normals_geom_glsl, NULL},
                        .frag = (const char *[]){datatoc_gpu_shader_uniform_color_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, "#define FACE_NORMALS\n", NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, "#define FACE_NORMALS\n", NULL},
                });
 
                sh_data->normals_loop = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_edit_normals_vert_glsl, NULL},
-                       .geom = (const char *[]){world_clip_lib_or_empty, datatoc_edit_normals_geom_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_edit_normals_vert_glsl, NULL},
+                       .geom = (const char *[]){sh_cfg_data->lib, datatoc_edit_normals_geom_glsl, NULL},
                        .frag = (const char *[]){datatoc_gpu_shader_uniform_color_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, "#define LOOP_NORMALS\n", NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, "#define LOOP_NORMALS\n", NULL},
                });
 
                sh_data->normals = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_edit_normals_vert_glsl, NULL},
-                       .geom = (const char *[]){world_clip_lib_or_empty, datatoc_edit_normals_geom_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_edit_normals_vert_glsl, NULL},
+                       .geom = (const char *[]){sh_cfg_data->lib, datatoc_edit_normals_geom_glsl, NULL},
                        .frag = (const char *[]){datatoc_gpu_shader_uniform_color_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
 
                sh_data->depth = DRW_shader_create_3D_depth_only(draw_ctx->sh_cfg);
index 0af1ab9..4e4e180 100644 (file)
@@ -93,8 +93,7 @@ typedef struct EDIT_METABALL_PrivateData {
 static void EDIT_METABALL_engine_init(void *UNUSED(vedata))
 {
        const DRWContextState *draw_ctx = DRW_context_state_get();
-       const bool is_clip = (draw_ctx->rv3d->rflag & RV3D_CLIPPING) != 0;
-       if (is_clip) {
+       if (draw_ctx->sh_cfg == GPU_SHADER_CFG_CLIPPED) {
                DRW_state_clip_planes_set_from_rv3d(draw_ctx->rv3d);
        }
 }
index 67da81b..415f611 100644 (file)
@@ -68,7 +68,6 @@
 
 #include "DEG_depsgraph_query.h"
 
-extern char datatoc_gpu_shader_cfg_world_clip_lib_glsl[];
 extern char datatoc_object_outline_prepass_vert_glsl[];
 extern char datatoc_object_outline_prepass_geom_glsl[];
 extern char datatoc_object_outline_prepass_frag_glsl[];
@@ -397,22 +396,20 @@ static void OBJECT_engine_init(void *vedata)
        const DRWContextState *draw_ctx = DRW_context_state_get();
        OBJECT_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
 
-       const bool is_clip = (draw_ctx->rv3d->rflag & RV3D_CLIPPING) != 0;
-       const char *world_clip_lib_or_empty = is_clip ? datatoc_gpu_shader_cfg_world_clip_lib_glsl : "";
-       const char *world_clip_def_or_empty = is_clip ? "#define USE_WORLD_CLIP_PLANES\n" : "";
+       const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[draw_ctx->sh_cfg];
 
        if (!sh_data->outline_resolve) {
                /* Outline */
                sh_data->outline_prepass = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_gpu_shader_3D_vert_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_gpu_shader_3D_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_object_outline_prepass_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
                sh_data->outline_prepass_wire = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_object_outline_prepass_vert_glsl, NULL},
-                       .geom = (const char *[]){world_clip_lib_or_empty, datatoc_object_outline_prepass_geom_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_object_outline_prepass_vert_glsl, NULL},
+                       .geom = (const char *[]){sh_cfg_data->lib, datatoc_object_outline_prepass_geom_glsl, NULL},
                        .frag = (const char *[]){datatoc_object_outline_prepass_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
 
                sh_data->outline_resolve = DRW_shader_create_fullscreen(datatoc_object_outline_resolve_frag_glsl, NULL);
@@ -448,14 +445,14 @@ static void OBJECT_engine_init(void *vedata)
                                "#define DEPTH_BACK " STRINGIFY(OB_EMPTY_IMAGE_DEPTH_BACK) "\n");
 
                        sh_data->object_empty_image = GPU_shader_create_from_arrays({
-                               .vert = (const char *[]){world_clip_lib_or_empty, datatoc_object_empty_image_vert_glsl, NULL},
+                               .vert = (const char *[]){sh_cfg_data->lib, datatoc_object_empty_image_vert_glsl, NULL},
                                .frag = (const char *[]){datatoc_object_empty_image_frag_glsl, NULL},
-                               .defs = (const char *[]){world_clip_def_or_empty, empty_image_defs, NULL},
+                               .defs = (const char *[]){sh_cfg_data->def, empty_image_defs, NULL},
                        });
                        sh_data->object_empty_image_wire = GPU_shader_create_from_arrays({
-                               .vert = (const char *[]){world_clip_lib_or_empty, datatoc_object_empty_image_vert_glsl, NULL},
+                               .vert = (const char *[]){sh_cfg_data->lib, datatoc_object_empty_image_vert_glsl, NULL},
                                .frag = (const char *[]){datatoc_object_empty_image_frag_glsl, NULL},
-                               .defs = (const char *[]){world_clip_def_or_empty, "#define USE_WIRE\n", empty_image_defs, NULL},
+                               .defs = (const char *[]){sh_cfg_data->def, "#define USE_WIRE\n", empty_image_defs, NULL},
                        });
                }
 
@@ -482,9 +479,9 @@ static void OBJECT_engine_init(void *vedata)
 
                /* Loose Points */
                sh_data->loose_points = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_gpu_shader_3D_vert_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_gpu_shader_3D_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_object_loose_points_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
        }
 
index a1befa6..407c22b 100644 (file)
@@ -73,8 +73,6 @@ static struct {
        OVERLAY_Shaders sh_data[GPU_SHADER_CFG_LEN];
 } e_data = {NULL};
 
-extern char datatoc_gpu_shader_cfg_world_clip_lib_glsl[];
-
 /* Shaders */
 extern char datatoc_overlay_face_orientation_frag_glsl[];
 extern char datatoc_overlay_face_orientation_vert_glsl[];
@@ -92,9 +90,8 @@ static void overlay_engine_init(void *vedata)
 
        const DRWContextState *draw_ctx = DRW_context_state_get();
        OVERLAY_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
-       const bool is_clip = (draw_ctx->rv3d->rflag & RV3D_CLIPPING) != 0;
 
-       if (is_clip) {
+       if (draw_ctx->sh_cfg == GPU_SHADER_CFG_CLIPPED) {
                DRW_state_clip_planes_set_from_rv3d(draw_ctx->rv3d);
        }
 
@@ -104,35 +101,34 @@ static void overlay_engine_init(void *vedata)
        }
        stl->g_data->ghost_stencil_test = false;
 
-       const char *world_clip_lib_or_empty = is_clip ? datatoc_gpu_shader_cfg_world_clip_lib_glsl : "";
-       const char *world_clip_def_or_empty = is_clip ? "#define USE_WORLD_CLIP_PLANES\n" : "";
+       const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[draw_ctx->sh_cfg];
 
        if (!sh_data->face_orientation) {
                /* Face orientation */
                sh_data->face_orientation = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_overlay_face_orientation_vert_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_overlay_face_orientation_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_overlay_face_orientation_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
        }
 
        if (!sh_data->face_wireframe) {
                sh_data->select_wireframe = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_overlay_face_wireframe_vert_glsl, NULL},
-                       .geom = (const char *[]){world_clip_lib_or_empty, datatoc_overlay_face_wireframe_geom_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_overlay_face_wireframe_vert_glsl, NULL},
+                       .geom = (const char *[]){sh_cfg_data->lib, datatoc_overlay_face_wireframe_geom_glsl, NULL},
                        .frag = (const char *[]){datatoc_gpu_shader_depth_only_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, "#define SELECT_EDGES\n", NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, "#define SELECT_EDGES\n", NULL},
                });
                sh_data->face_wireframe = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_overlay_face_wireframe_vert_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_overlay_face_wireframe_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_overlay_face_wireframe_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
                sh_data->face_wireframe_sculpt = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_overlay_face_wireframe_vert_glsl, NULL},
-                       .geom = (const char *[]){world_clip_lib_or_empty, datatoc_overlay_face_wireframe_geom_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_overlay_face_wireframe_vert_glsl, NULL},
+                       .geom = (const char *[]){sh_cfg_data->lib, datatoc_overlay_face_wireframe_geom_glsl, NULL},
                        .frag = (const char *[]){datatoc_overlay_face_wireframe_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, "#define USE_SCULPT\n", NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, "#define USE_SCULPT\n", NULL},
                });
        }
 }
index ced0883..c11bb1a 100644 (file)
@@ -32,8 +32,6 @@
 
 #include "DEG_depsgraph_query.h"
 
-extern char datatoc_gpu_shader_cfg_world_clip_lib_glsl[];
-
 extern char datatoc_paint_vertex_vert_glsl[];
 extern char datatoc_paint_vertex_frag_glsl[];
 extern char datatoc_paint_wire_vert_glsl[];
@@ -91,35 +89,33 @@ static void PAINT_VERTEX_engine_init(void *UNUSED(vedata))
 {
        const DRWContextState *draw_ctx = DRW_context_state_get();
        PAINT_VERTEX_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
-       const bool is_clip = (draw_ctx->rv3d->rflag & RV3D_CLIPPING) != 0;
 
-       if (is_clip) {
+       if (draw_ctx->sh_cfg) {
                DRW_state_clip_planes_set_from_rv3d(draw_ctx->rv3d);
        }
+       const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[draw_ctx->sh_cfg];
 
        if (!sh_data->vcolor_face) {
-               const char *world_clip_lib_or_empty = is_clip ? datatoc_gpu_shader_cfg_world_clip_lib_glsl : "";
-               const char *world_clip_def_or_empty = is_clip ? "#define USE_WORLD_CLIP_PLANES\n" : "";
 
                sh_data->vcolor_face = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_paint_vertex_vert_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_paint_vertex_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_paint_vertex_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
                sh_data->wire_overlay = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_common_globals_lib_glsl, datatoc_paint_wire_vert_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_common_globals_lib_glsl, datatoc_paint_wire_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_paint_wire_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, "#define VERTEX_MODE\n", NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, "#define VERTEX_MODE\n", NULL},
                });
                sh_data->face_overlay = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_paint_face_vert_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_paint_face_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_gpu_shader_uniform_color_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
                sh_data->vert_overlay = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_common_globals_lib_glsl, datatoc_paint_wire_vert_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_common_globals_lib_glsl, datatoc_paint_wire_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_paint_vert_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
        }
 }
index d52a554..910ffec 100644 (file)
@@ -31,8 +31,6 @@
 
 #include "DEG_depsgraph_query.h"
 
-extern char datatoc_gpu_shader_cfg_world_clip_lib_glsl[];
-
 extern char datatoc_paint_face_vert_glsl[];
 extern char datatoc_paint_weight_vert_glsl[];
 extern char datatoc_paint_weight_frag_glsl[];
@@ -92,38 +90,35 @@ static void PAINT_WEIGHT_engine_init(void *UNUSED(vedata))
 {
        const DRWContextState *draw_ctx = DRW_context_state_get();
        PAINT_WEIGHT_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
-       const bool is_clip = (draw_ctx->rv3d->rflag & RV3D_CLIPPING) != 0;
+       const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[draw_ctx->sh_cfg];
 
-       if (is_clip) {
+       if (draw_ctx->sh_cfg == GPU_SHADER_CFG_CLIPPED) {
                DRW_state_clip_planes_set_from_rv3d(draw_ctx->rv3d);
        }
 
        if (!sh_data->weight_face) {
-               const char *world_clip_lib_or_empty = is_clip ? datatoc_gpu_shader_cfg_world_clip_lib_glsl : "";
-               const char *world_clip_def_or_empty = is_clip ? "#define USE_WORLD_CLIP_PLANES\n" : "";
-
                sh_data->weight_face = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_common_globals_lib_glsl, datatoc_paint_weight_vert_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_common_globals_lib_glsl, datatoc_paint_weight_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_common_globals_lib_glsl, datatoc_paint_weight_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
 
                sh_data->wire_overlay = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_common_globals_lib_glsl, datatoc_paint_wire_vert_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_common_globals_lib_glsl, datatoc_paint_wire_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_paint_wire_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, "#define WEIGHT_MODE\n", NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, "#define WEIGHT_MODE\n", NULL},
                });
 
                sh_data->face_overlay = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_paint_face_vert_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_paint_face_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_gpu_shader_uniform_color_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
 
                sh_data->vert_overlay = GPU_shader_create_from_arrays({
-                       .vert = (const char *[]){world_clip_lib_or_empty, datatoc_common_globals_lib_glsl, datatoc_paint_wire_vert_glsl, NULL},
+                       .vert = (const char *[]){sh_cfg_data->lib, datatoc_common_globals_lib_glsl, datatoc_paint_wire_vert_glsl, NULL},
                        .frag = (const char *[]){datatoc_common_globals_lib_glsl, datatoc_paint_vert_frag_glsl, NULL},
-                       .defs = (const char *[]){world_clip_def_or_empty, NULL},
+                       .defs = (const char *[]){sh_cfg_data->def, NULL},
                });
        }
 }
index bae8c3c..2a00c50 100644 (file)
@@ -365,6 +365,13 @@ typedef enum eGPUShaderConfig {
 } eGPUShaderConfig;
 #define GPU_SHADER_CFG_LEN (GPU_SHADER_CFG_CLIPPED + 1)
 
+typedef struct GPUShaderConfigData {
+       const char *lib;
+       const char *def;
+} GPUShaderConfigData;
+/* shader.c */
+extern const GPUShaderConfigData GPU_shader_cfg_data[GPU_SHADER_CFG_LEN];
+
 /** Keep these in sync with:
  * - `gpu_shader_image_interlace_frag.glsl`
  * - `gpu_shader_image_rect_interlace_frag.glsl`
index 4245adb..66c5aea 100644 (file)
@@ -171,6 +171,17 @@ extern char datatoc_gpu_shader_gpencil_fill_vert_glsl[];
 extern char datatoc_gpu_shader_gpencil_fill_frag_glsl[];
 extern char datatoc_gpu_shader_cfg_world_clip_lib_glsl[];
 
+const struct GPUShaderConfigData GPU_shader_cfg_data[GPU_SHADER_CFG_LEN] = {
+       [GPU_SHADER_CFG_DEFAULT] = {
+               .lib = "",
+               .def = "",
+       },
+       [GPU_SHADER_CFG_CLIPPED] = {
+               .lib = datatoc_gpu_shader_cfg_world_clip_lib_glsl,
+               .def = "#define USE_WORLD_CLIP_PLANES\n",
+       },
+};
+
 /* cache of built-in shaders (each is created on first use) */
 static GPUShader *builtin_shaders[GPU_SHADER_CFG_LEN][GPU_SHADER_BUILTIN_LEN] = {NULL};