diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-02-08 14:51:37 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-02-08 15:21:22 +0300 |
commit | 813800f143b90480f563d1e1dd6fbb9acd3e5f87 (patch) | |
tree | 43f152dd81ae17d5dd1cb5ee9407e892543808f3 /source/blender/draw/intern | |
parent | d723249dcc20ff6fab55d443dba85203a104a7fc (diff) |
DRW: support clipping for stick & wire bones
Diffstat (limited to 'source/blender/draw/intern')
-rw-r--r-- | source/blender/draw/intern/draw_armature.c | 36 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_common.c | 26 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_common.h | 4 |
3 files changed, 39 insertions, 27 deletions
diff --git a/source/blender/draw/intern/draw_armature.c b/source/blender/draw/intern/draw_armature.c index 12ef62a128b..e062948ccec 100644 --- a/source/blender/draw/intern/draw_armature.c +++ b/source/blender/draw/intern/draw_armature.c @@ -163,10 +163,12 @@ static void drw_shgroup_bone_box( } /* Wire */ -static void drw_shgroup_bone_wire(const float (*bone_mat)[4], const float color[4]) +static void drw_shgroup_bone_wire( + const float (*bone_mat)[4], const float color[4], + const eGPUShaderConfig shader_cfg) { if (g_data.bone_wire == NULL) { - g_data.bone_wire = shgroup_dynlines_flat_color(g_data.passes.bone_wire); + g_data.bone_wire = shgroup_dynlines_flat_color(g_data.passes.bone_wire, shader_cfg); } float head[3], tail[3]; mul_v3_m4v3(head, g_data.ob->obmat, bone_mat[3]); @@ -180,10 +182,11 @@ static void drw_shgroup_bone_wire(const float (*bone_mat)[4], const float color[ /* Stick */ static void drw_shgroup_bone_stick( const float (*bone_mat)[4], - const float col_wire[4], const float col_bone[4], const float col_head[4], const float col_tail[4]) + const float col_wire[4], const float col_bone[4], const float col_head[4], const float col_tail[4], + const eGPUShaderConfig shader_cfg) { if (g_data.bone_stick == NULL) { - g_data.bone_stick = shgroup_instance_bone_stick(g_data.passes.bone_wire); + g_data.bone_stick = shgroup_instance_bone_stick(g_data.passes.bone_wire, shader_cfg); } float final_bonemat[4][4], tail[4]; mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat); @@ -1322,7 +1325,8 @@ static void draw_bone_envelope( static void draw_bone_line( EditBone *eBone, bPoseChannel *pchan, bArmature *arm, - const int boneflag, const short constflag, const int select_id) + const int boneflag, const short constflag, + const eGPUShaderConfig shader_cfg, const int select_id) { const float *col_bone = get_bone_solid_with_consts_color(eBone, pchan, arm, boneflag, constflag); const float *col_wire = get_bone_wire_color(eBone, pchan, arm, boneflag, constflag); @@ -1360,20 +1364,20 @@ static void draw_bone_line( if (select_id == -1) { /* Not in selection mode, draw everything at once. */ - drw_shgroup_bone_stick(BONE_VAR(eBone, pchan, disp_mat), col_wire, col_bone, col_head, col_tail); + drw_shgroup_bone_stick(BONE_VAR(eBone, pchan, disp_mat), col_wire, col_bone, col_head, col_tail, shader_cfg); } else { /* In selection mode, draw bone, root and tip separately. */ DRW_select_load_id(select_id | BONESEL_BONE); - drw_shgroup_bone_stick(BONE_VAR(eBone, pchan, disp_mat), col_wire, col_bone, no_display, no_display); + drw_shgroup_bone_stick(BONE_VAR(eBone, pchan, disp_mat), col_wire, col_bone, no_display, no_display, shader_cfg); if (col_head[3] > 0.0f) { DRW_select_load_id(select_id | BONESEL_ROOT); - drw_shgroup_bone_stick(BONE_VAR(eBone, pchan, disp_mat), col_wire, no_display, col_head, no_display); + drw_shgroup_bone_stick(BONE_VAR(eBone, pchan, disp_mat), col_wire, no_display, col_head, no_display, shader_cfg); } DRW_select_load_id(select_id | BONESEL_TIP); - drw_shgroup_bone_stick(BONE_VAR(eBone, pchan, disp_mat), col_wire, no_display, no_display, col_tail); + drw_shgroup_bone_stick(BONE_VAR(eBone, pchan, disp_mat), col_wire, no_display, no_display, col_tail, shader_cfg); DRW_select_load_id(-1); } @@ -1382,7 +1386,7 @@ static void draw_bone_line( static void draw_bone_wire( EditBone *eBone, bPoseChannel *pchan, bArmature *arm, const int boneflag, const short constflag, - const int select_id) + const eGPUShaderConfig shader_cfg, const int select_id) { const float *col_wire = get_bone_wire_color(eBone, pchan, arm, boneflag, constflag); @@ -1395,12 +1399,12 @@ static void draw_bone_wire( BLI_assert(bbones_mat != NULL); for (int i = pchan->bone->segments; i--; bbones_mat++) { - drw_shgroup_bone_wire(bbones_mat->mat, col_wire); + drw_shgroup_bone_wire(bbones_mat->mat, col_wire, shader_cfg); } } else if (eBone) { for (int i = 0; i < eBone->segments; i++) { - drw_shgroup_bone_wire(eBone->disp_bbone_mat[i], col_wire); + drw_shgroup_bone_wire(eBone->disp_bbone_mat[i], col_wire, shader_cfg); } } @@ -1716,11 +1720,11 @@ static void draw_armature_edit(Object *ob) } else if (arm->drawtype == ARM_LINE) { draw_bone_update_disp_matrix_default(eBone, NULL); - draw_bone_line(eBone, NULL, arm, boneflag, constflag, select_id); + draw_bone_line(eBone, NULL, arm, boneflag, constflag, draw_ctx->shader_cfg, select_id); } else if (arm->drawtype == ARM_WIRE) { draw_bone_update_disp_matrix_bbone(eBone, NULL); - draw_bone_wire(eBone, NULL, arm, boneflag, constflag, select_id); + draw_bone_wire(eBone, NULL, arm, boneflag, constflag, draw_ctx->shader_cfg, select_id); } else if (arm->drawtype == ARM_B_BONE) { draw_bone_update_disp_matrix_bbone(eBone, NULL); @@ -1831,11 +1835,11 @@ static void draw_armature_pose(Object *ob, const float const_color[4]) } else if (arm->drawtype == ARM_LINE) { draw_bone_update_disp_matrix_default(NULL, pchan); - draw_bone_line(NULL, pchan, arm, boneflag, constflag, select_id); + draw_bone_line(NULL, pchan, arm, boneflag, constflag, draw_ctx->shader_cfg, select_id); } else if (arm->drawtype == ARM_WIRE) { draw_bone_update_disp_matrix_bbone(NULL, pchan); - draw_bone_wire(NULL, pchan, arm, boneflag, constflag, select_id); + draw_bone_wire(NULL, pchan, arm, boneflag, constflag, draw_ctx->shader_cfg, select_id); } else if (arm->drawtype == ARM_B_BONE) { draw_bone_update_disp_matrix_bbone(NULL, pchan); diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c index eb932bc4cd4..819e895ed21 100644 --- a/source/blender/draw/intern/draw_common.c +++ b/source/blender/draw/intern/draw_common.c @@ -305,9 +305,9 @@ void DRW_shgroup_world_clip_planes_from_rv3d(DRWShadingGroup *shgrp, const Regio DRW_shgroup_state_enable(shgrp, DRW_STATE_CLIP_PLANES); } -DRWShadingGroup *shgroup_dynlines_flat_color(DRWPass *pass) +DRWShadingGroup *shgroup_dynlines_flat_color(DRWPass *pass, eGPUShaderConfig shader_cfg) { - GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_FLAT_COLOR); + GPUShader *sh = GPU_shader_get_builtin_shader_with_config(GPU_SHADER_3D_FLAT_COLOR, shader_cfg); DRW_shgroup_instance_format(g_formats.dynlines_color, { {"pos", DRW_ATTR_FLOAT, 3}, @@ -315,7 +315,9 @@ DRWShadingGroup *shgroup_dynlines_flat_color(DRWPass *pass) }); DRWShadingGroup *grp = DRW_shgroup_line_batch_create_with_format(sh, pass, g_formats.dynlines_color); - + if (shader_cfg == GPU_SHADER_CFG_CLIPPED) { + DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d); + } return grp; } @@ -835,13 +837,17 @@ DRWShadingGroup *shgroup_instance_bone_sphere_outline(DRWPass *pass) return grp; } -DRWShadingGroup *shgroup_instance_bone_stick(DRWPass *pass) +DRWShadingGroup *shgroup_instance_bone_stick(DRWPass *pass, eGPUShaderConfig shader_cfg) { - COMMON_Shaders *sh_data = &g_shaders[GPU_SHADER_CFG_DEFAULT]; + COMMON_Shaders *sh_data = &g_shaders[shader_cfg]; if (sh_data->bone_stick == NULL) { - sh_data->bone_stick = DRW_shader_create( - datatoc_armature_stick_vert_glsl, NULL, - datatoc_armature_stick_frag_glsl, NULL); + const char *world_clip_lib_or_empty = (shader_cfg == GPU_SHADER_CFG_CLIPPED) ? datatoc_gpu_shader_cfg_world_clip_lib_glsl : ""; + const char *world_clip_def_or_empty = (shader_cfg == GPU_SHADER_CFG_CLIPPED) ? "#define USE_WORLD_CLIP_PLANES\n" : ""; + sh_data->bone_stick = GPU_shader_create_from_arrays({ + .vert = (const char *[]){world_clip_lib_or_empty, datatoc_armature_stick_vert_glsl, NULL}, + .frag = (const char *[]){datatoc_armature_stick_frag_glsl, NULL}, + .defs = (const char *[]){world_clip_def_or_empty, NULL}, + }); } DRW_shgroup_instance_format(g_formats.instance_bone_stick, { @@ -859,7 +865,9 @@ DRWShadingGroup *shgroup_instance_bone_stick(DRWPass *pass) g_formats.instance_bone_stick); DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1); DRW_shgroup_uniform_float_copy(grp, "stickSize", 5.0f * U.pixelsize); - + if (shader_cfg == GPU_SHADER_CFG_CLIPPED) { + DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d); + } return grp; } diff --git a/source/blender/draw/intern/draw_common.h b/source/blender/draw/intern/draw_common.h index 2d8a468b30b..2caf4974482 100644 --- a/source/blender/draw/intern/draw_common.h +++ b/source/blender/draw/intern/draw_common.h @@ -123,7 +123,7 @@ void DRW_globals_free(void); void DRW_shgroup_world_clip_planes_from_rv3d(struct DRWShadingGroup *shgrp, const RegionView3D *rv3d); -struct DRWShadingGroup *shgroup_dynlines_flat_color(struct DRWPass *pass); +struct DRWShadingGroup *shgroup_dynlines_flat_color(struct DRWPass *pass, eGPUShaderConfig shader_cfg); struct DRWShadingGroup *shgroup_dynlines_dashed_uniform_color(struct DRWPass *pass, const float color[4]); struct DRWShadingGroup *shgroup_dynpoints_uniform_color(struct DRWPass *pass, const float color[4], const float *size, eGPUShaderConfig shader_cfg); struct DRWShadingGroup *shgroup_groundlines_uniform_color(struct DRWPass *pass, const float color[4], eGPUShaderConfig shader_cfg); @@ -149,7 +149,7 @@ struct DRWShadingGroup *shgroup_instance_bone_shape_outline(struct DRWPass *pass struct DRWShadingGroup *shgroup_instance_bone_shape_solid(struct DRWPass *pass, struct GPUBatch *geom, bool transp, eGPUShaderConfig shader_cfg); struct DRWShadingGroup *shgroup_instance_bone_sphere_outline(struct DRWPass *pass); struct DRWShadingGroup *shgroup_instance_bone_sphere_solid(struct DRWPass *pass, bool transp); -struct DRWShadingGroup *shgroup_instance_bone_stick(struct DRWPass *pass); +struct DRWShadingGroup *shgroup_instance_bone_stick(struct DRWPass *pass, eGPUShaderConfig shader_cfg); struct DRWShadingGroup *shgroup_instance_bone_dof(struct DRWPass *pass, struct GPUBatch *geom); struct GPUShader *mpath_line_shader_get(void); |