From 0b6dbbc306b0a7e60abe36968d154241bb90c1df Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 10 Feb 2019 11:06:22 +1100 Subject: Cleanup: move clipping shader lib & define into struct Also compare clipping with the draw context instead of accessing the RegionView3D, currently they're matching but this might not always be the case. --- source/blender/draw/modes/edit_curve_mode.c | 21 ++++++------ source/blender/draw/modes/edit_lattice_mode.c | 11 +++---- source/blender/draw/modes/edit_mesh_mode.c | 44 ++++++++++++-------------- source/blender/draw/modes/edit_metaball_mode.c | 3 +- source/blender/draw/modes/object_mode.c | 27 +++++++--------- source/blender/draw/modes/overlay_mode.c | 28 +++++++--------- source/blender/draw/modes/paint_vertex_mode.c | 24 ++++++-------- source/blender/draw/modes/paint_weight_mode.c | 25 ++++++--------- 8 files changed, 78 insertions(+), 105 deletions(-) (limited to 'source/blender/draw/modes') diff --git a/source/blender/draw/modes/edit_curve_mode.c b/source/blender/draw/modes/edit_curve_mode.c index 0a2a8ede1d9..2289a583885 100644 --- a/source/blender/draw/modes/edit_curve_mode.c +++ b/source/blender/draw/modes/edit_curve_mode.c @@ -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}, }); } diff --git a/source/blender/draw/modes/edit_lattice_mode.c b/source/blender/draw/modes/edit_lattice_mode.c index 97471ef39e1..7ac24ac8e77 100644 --- a/source/blender/draw/modes/edit_lattice_mode.c +++ b/source/blender/draw/modes/edit_lattice_mode.c @@ -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}, }); } diff --git a/source/blender/draw/modes/edit_mesh_mode.c b/source/blender/draw/modes/edit_mesh_mode.c index c304e610548..420c099ee09 100644 --- a/source/blender/draw/modes/edit_mesh_mode.c +++ b/source/blender/draw/modes/edit_mesh_mode.c @@ -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); diff --git a/source/blender/draw/modes/edit_metaball_mode.c b/source/blender/draw/modes/edit_metaball_mode.c index 0af1ab9ecd8..4e4e1806ae2 100644 --- a/source/blender/draw/modes/edit_metaball_mode.c +++ b/source/blender/draw/modes/edit_metaball_mode.c @@ -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); } } diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c index 67da81b91ff..415f6113617 100644 --- a/source/blender/draw/modes/object_mode.c +++ b/source/blender/draw/modes/object_mode.c @@ -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}, }); } diff --git a/source/blender/draw/modes/overlay_mode.c b/source/blender/draw/modes/overlay_mode.c index a1befa679f0..407c22bf581 100644 --- a/source/blender/draw/modes/overlay_mode.c +++ b/source/blender/draw/modes/overlay_mode.c @@ -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}, }); } } diff --git a/source/blender/draw/modes/paint_vertex_mode.c b/source/blender/draw/modes/paint_vertex_mode.c index ced0883b9b6..c11bb1a1064 100644 --- a/source/blender/draw/modes/paint_vertex_mode.c +++ b/source/blender/draw/modes/paint_vertex_mode.c @@ -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}, }); } } diff --git a/source/blender/draw/modes/paint_weight_mode.c b/source/blender/draw/modes/paint_weight_mode.c index d52a5540ee6..910ffecd9ba 100644 --- a/source/blender/draw/modes/paint_weight_mode.c +++ b/source/blender/draw/modes/paint_weight_mode.c @@ -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}, }); } } -- cgit v1.2.3