From c233271b0b1f63c730903e580dc1877dfb1d3402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Wed, 13 May 2020 21:20:18 +0200 Subject: Fix T76126 Overlay: Glitch when hiding Nurb vertices --- .../draw/engines/overlay/overlay_edit_curve.c | 5 ++- .../overlay/shaders/edit_curve_handle_geom.glsl | 5 ++- .../overlay/shaders/edit_curve_point_vert.glsl | 10 +++++ source/blender/draw/intern/draw_cache.c | 4 +- source/blender/draw/intern/draw_cache.h | 2 +- source/blender/draw/intern/draw_cache_impl.h | 2 +- source/blender/draw/intern/draw_cache_impl_curve.c | 50 +++++++++------------- 7 files changed, 40 insertions(+), 38 deletions(-) diff --git a/source/blender/draw/engines/overlay/overlay_edit_curve.c b/source/blender/draw/engines/overlay/overlay_edit_curve.c index d9b9fac6b4b..6456d6868a5 100644 --- a/source/blender/draw/engines/overlay/overlay_edit_curve.c +++ b/source/blender/draw/engines/overlay/overlay_edit_curve.c @@ -66,6 +66,7 @@ void OVERLAY_edit_curve_cache_init(OVERLAY_Data *vedata) sh = OVERLAY_shader_edit_curve_point(); pd->edit_curve_points_grp = grp = DRW_shgroup_create(sh, psl->edit_curve_handle_ps); + DRW_shgroup_uniform_bool_copy(grp, "showCurveHandles", pd->edit_curve.show_handles); DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); } } @@ -94,7 +95,7 @@ void OVERLAY_edit_curve_cache_populate(OVERLAY_Data *vedata, Object *ob) DRW_shgroup_call_no_cull(pd->edit_curve_handle_grp, geom, ob); } - geom = DRW_cache_curve_vert_overlay_get(ob, pd->edit_curve.show_handles); + geom = DRW_cache_curve_vert_overlay_get(ob); if (geom) { DRW_shgroup_call_no_cull(pd->edit_curve_points_grp, geom, ob); } @@ -110,7 +111,7 @@ void OVERLAY_edit_surf_cache_populate(OVERLAY_Data *vedata, Object *ob) DRW_shgroup_call_no_cull(pd->edit_curve_handle_grp, geom, ob); } - geom = DRW_cache_curve_vert_overlay_get(ob, false); + geom = DRW_cache_curve_vert_overlay_get(ob); if (geom) { DRW_shgroup_call_no_cull(pd->edit_curve_points_grp, geom, ob); } diff --git a/source/blender/draw/engines/overlay/shaders/edit_curve_handle_geom.glsl b/source/blender/draw/engines/overlay/shaders/edit_curve_handle_geom.glsl index b6576ba7a21..b444b3b0fec 100644 --- a/source/blender/draw/engines/overlay/shaders/edit_curve_handle_geom.glsl +++ b/source/blender/draw/engines/overlay/shaders/edit_curve_handle_geom.glsl @@ -1,7 +1,8 @@ /* Keep the same value of `ACTIVE_NURB` in `draw_cache_imp_curve.c` */ #define ACTIVE_NURB 1 << 2 -#define EVEN_U_BIT 1 << 3 +#define EVEN_U_BIT 1 << 4 +#define COLOR_SHIFT 5 layout(lines) in; layout(triangle_strip, max_vertices = 10) out; @@ -37,7 +38,7 @@ void main() vec4 v2 = gl_in[1].gl_Position; int is_active_nurb = (vertFlag[1] & ACTIVE_NURB); - int color_id = (vertFlag[1] >> 4); + int color_id = (vertFlag[1] >> COLOR_SHIFT); /* Don't output any edges if we don't show handles */ if (!showCurveHandles && (color_id < 5)) { diff --git a/source/blender/draw/engines/overlay/shaders/edit_curve_point_vert.glsl b/source/blender/draw/engines/overlay/shaders/edit_curve_point_vert.glsl index aca40bba171..6fa4576ae71 100644 --- a/source/blender/draw/engines/overlay/shaders/edit_curve_point_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/edit_curve_point_vert.glsl @@ -1,4 +1,9 @@ +/* Keep the same value of `BEZIER_HANDLE` in `draw_cache_imp_curve.c` */ +#define BEZIER_HANDLE 1 << 3 + +uniform bool showCurveHandles; + in vec3 pos; in int data; @@ -26,4 +31,9 @@ void main() #ifdef USE_WORLD_CLIP_PLANES world_clip_planes_calc_clip_distance(world_pos); #endif + + if (!showCurveHandles && ((data & BEZIER_HANDLE) != 0)) { + /* We set the vertex at the camera origin to generate 0 fragments. */ + gl_Position = vec4(0.0, 0.0, -3e36, 0.0); + } } diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c index 4306f9ac4d7..23d0d74534d 100644 --- a/source/blender/draw/intern/draw_cache.c +++ b/source/blender/draw/intern/draw_cache.c @@ -2898,12 +2898,12 @@ GPUBatch *DRW_cache_curve_edge_overlay_get(Object *ob) return DRW_curve_batch_cache_get_edit_edges(cu); } -GPUBatch *DRW_cache_curve_vert_overlay_get(Object *ob, bool handles) +GPUBatch *DRW_cache_curve_vert_overlay_get(Object *ob) { BLI_assert(ELEM(ob->type, OB_CURVE, OB_SURF)); struct Curve *cu = ob->data; - return DRW_curve_batch_cache_get_edit_verts(cu, handles); + return DRW_curve_batch_cache_get_edit_verts(cu); } GPUBatch *DRW_cache_curve_surface_get(Object *ob) diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h index 77c7b6b9307..221fb89612f 100644 --- a/source/blender/draw/intern/draw_cache.h +++ b/source/blender/draw/intern/draw_cache.h @@ -150,7 +150,7 @@ struct GPUBatch *DRW_cache_curve_edge_detection_get(struct Object *ob, bool *r_i /* edit-mode */ struct GPUBatch *DRW_cache_curve_edge_normal_get(struct Object *ob); struct GPUBatch *DRW_cache_curve_edge_overlay_get(struct Object *ob); -struct GPUBatch *DRW_cache_curve_vert_overlay_get(struct Object *ob, bool handles); +struct GPUBatch *DRW_cache_curve_vert_overlay_get(struct Object *ob); /* Font */ struct GPUBatch *DRW_cache_text_surface_get(struct Object *ob); diff --git a/source/blender/draw/intern/draw_cache_impl.h b/source/blender/draw/intern/draw_cache_impl.h index 3ce8a7d4e43..de0cd027ece 100644 --- a/source/blender/draw/intern/draw_cache_impl.h +++ b/source/blender/draw/intern/draw_cache_impl.h @@ -93,7 +93,7 @@ struct GPUBatch *DRW_curve_batch_cache_get_wire_edge(struct Curve *cu); struct GPUBatch *DRW_curve_batch_cache_get_normal_edge(struct Curve *cu); struct GPUBatch *DRW_curve_batch_cache_get_edge_detection(struct Curve *cu, bool *r_is_manifold); struct GPUBatch *DRW_curve_batch_cache_get_edit_edges(struct Curve *cu); -struct GPUBatch *DRW_curve_batch_cache_get_edit_verts(struct Curve *cu, bool handles); +struct GPUBatch *DRW_curve_batch_cache_get_edit_verts(struct Curve *cu); struct GPUBatch *DRW_curve_batch_cache_get_triangles_with_normals(struct Curve *cu); struct GPUBatch **DRW_curve_batch_cache_get_surface_shaded(struct Curve *cu, diff --git a/source/blender/draw/intern/draw_cache_impl_curve.c b/source/blender/draw/intern/draw_cache_impl_curve.c index 4f03ab04862..72ee7fe17c1 100644 --- a/source/blender/draw/intern/draw_cache_impl_curve.c +++ b/source/blender/draw/intern/draw_cache_impl_curve.c @@ -49,7 +49,9 @@ #define SELECT 1 #define ACTIVE_NURB 1 << 2 -#define EVEN_U_BIT 1 << 3 /* Alternate this bit for every U vert. */ +#define BEZIER_HANDLE 1 << 3 +#define EVEN_U_BIT 1 << 4 /* Alternate this bit for every U vert. */ +#define COLOR_SHIFT 5 /* Used as values of `color_id` in `edit_curve_overlay_handle_geom.glsl` */ enum { @@ -376,7 +378,7 @@ typedef struct CurveBatchCache { GPUIndexBuf *curves_lines; GPUIndexBuf *edges_adj_lines; /* Edit mode */ - GPUIndexBuf *edit_verts_points; /* Only control points. Not handles. */ + GPUIndexBuf *edit_verts; GPUIndexBuf *edit_lines; } ibo; @@ -387,7 +389,6 @@ typedef struct CurveBatchCache { /* control handles and vertices */ GPUBatch *edit_edges; GPUBatch *edit_verts; - GPUBatch *edit_handles_verts; GPUBatch *edit_normals; GPUBatch *edge_detection; } batch; @@ -497,7 +498,6 @@ void DRW_curve_batch_cache_dirty_tag(Curve *cu, int mode) GPU_BATCH_DISCARD_SAFE(cache->batch.edit_edges); GPU_BATCH_DISCARD_SAFE(cache->batch.edit_verts); - GPU_BATCH_DISCARD_SAFE(cache->batch.edit_handles_verts); break; default: BLI_assert(0); @@ -686,14 +686,15 @@ static void curve_create_edit_curves_nor(CurveRenderData *rdata, GPUVertBuf *vbo } static char beztriple_vflag_get( - CurveRenderData *rdata, char flag, char col_id, int v_idx, int nu_id) + CurveRenderData *rdata, char flag, char col_id, int v_idx, int nu_id, bool handle_point) { char vflag = 0; SET_FLAG_FROM_TEST(vflag, (flag & SELECT), VFLAG_VERT_SELECTED); SET_FLAG_FROM_TEST(vflag, (v_idx == rdata->actvert && nu_id == rdata->actnu), VFLAG_VERT_ACTIVE); SET_FLAG_FROM_TEST(vflag, (nu_id == rdata->actnu), ACTIVE_NURB); + SET_FLAG_FROM_TEST(vflag, handle_point, BEZIER_HANDLE); /* handle color id */ - vflag |= col_id << 4; /* << 4 because of EVEN_U_BIT */ + vflag |= col_id << COLOR_SHIFT; return vflag; } @@ -704,7 +705,7 @@ static char bpoint_vflag_get(CurveRenderData *rdata, char flag, int v_idx, int n SET_FLAG_FROM_TEST(vflag, (v_idx == rdata->actvert && nu_id == rdata->actnu), VFLAG_VERT_ACTIVE); SET_FLAG_FROM_TEST(vflag, (nu_id == rdata->actnu), ACTIVE_NURB); SET_FLAG_FROM_TEST(vflag, ((u % 2) == 0), EVEN_U_BIT); - vflag |= COLOR_NURB_ULINE_ID << 4; /* << 4 because of EVEN_U_BIT */ + vflag |= COLOR_NURB_ULINE_ID << COLOR_SHIFT; return vflag; } @@ -760,7 +761,9 @@ static void curve_create_edit_data_and_handles(CurveRenderData *rdata, } if (elbp_verts) { + GPU_indexbuf_add_point_vert(elbp_verts, vbo_len_used + 0); GPU_indexbuf_add_point_vert(elbp_verts, vbo_len_used + 1); + GPU_indexbuf_add_point_vert(elbp_verts, vbo_len_used + 2); } if (elbp_lines) { GPU_indexbuf_add_line_verts(elbp_lines, vbo_len_used + 1, vbo_len_used + 0); @@ -768,9 +771,9 @@ static void curve_create_edit_data_and_handles(CurveRenderData *rdata, } if (vbo_data) { const char vflag[3] = { - beztriple_vflag_get(rdata, bezt->f1, bezt->h1, a, nu_id), - beztriple_vflag_get(rdata, bezt->f2, bezt->h1, a, nu_id), - beztriple_vflag_get(rdata, bezt->f3, bezt->h2, a, nu_id), + beztriple_vflag_get(rdata, bezt->f1, bezt->h1, a, nu_id, true), + beztriple_vflag_get(rdata, bezt->f2, bezt->h1, a, nu_id, false), + beztriple_vflag_get(rdata, bezt->f3, bezt->h2, a, nu_id, true), }; for (int j = 0; j < 3; j++) { GPU_vertbuf_attr_set(vbo_data, attr_id.data, vbo_len_used + j, &vflag[j]); @@ -859,15 +862,10 @@ GPUBatch *DRW_curve_batch_cache_get_edit_edges(Curve *cu) return DRW_batch_request(&cache->batch.edit_edges); } -GPUBatch *DRW_curve_batch_cache_get_edit_verts(Curve *cu, bool handles) +GPUBatch *DRW_curve_batch_cache_get_edit_verts(Curve *cu) { CurveBatchCache *cache = curve_batch_cache_get(cu); - if (handles) { - return DRW_batch_request(&cache->batch.edit_handles_verts); - } - else { - return DRW_batch_request(&cache->batch.edit_verts); - } + return DRW_batch_request(&cache->batch.edit_verts); } GPUBatch *DRW_curve_batch_cache_get_triangles_with_normals(struct Curve *cu) @@ -965,14 +963,10 @@ void DRW_curve_batch_cache_create_requested(Object *ob) DRW_vbo_request(cache->batch.edit_edges, &cache->edit.data); } if (DRW_batch_requested(cache->batch.edit_verts, GPU_PRIM_POINTS)) { - DRW_ibo_request(cache->batch.edit_verts, &cache->ibo.edit_verts_points); + DRW_ibo_request(cache->batch.edit_verts, &cache->ibo.edit_verts); DRW_vbo_request(cache->batch.edit_verts, &cache->edit.pos); DRW_vbo_request(cache->batch.edit_verts, &cache->edit.data); } - if (DRW_batch_requested(cache->batch.edit_handles_verts, GPU_PRIM_POINTS)) { - DRW_vbo_request(cache->batch.edit_handles_verts, &cache->edit.pos); - DRW_vbo_request(cache->batch.edit_handles_verts, &cache->edit.data); - } if (DRW_batch_requested(cache->batch.edit_normals, GPU_PRIM_LINES)) { DRW_vbo_request(cache->batch.edit_normals, &cache->edit.curves_nor); } @@ -1012,7 +1006,7 @@ void DRW_curve_batch_cache_create_requested(Object *ob) DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_flag, cache->edit.data, CU_DATATYPE_OVERLAY); DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_flag, cache->edit.curves_nor, CU_DATATYPE_NORMAL); DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_flag, cache->edit.curves_weight, CU_DATATYPE_OVERLAY); - DRW_ADD_FLAG_FROM_IBO_REQUEST(mr_flag, cache->ibo.edit_verts_points, CU_DATATYPE_OVERLAY); + DRW_ADD_FLAG_FROM_IBO_REQUEST(mr_flag, cache->ibo.edit_verts, CU_DATATYPE_OVERLAY); DRW_ADD_FLAG_FROM_IBO_REQUEST(mr_flag, cache->ibo.edit_lines, CU_DATATYPE_OVERLAY); for (int i = 0; i < cache->mat_len; i++) { @@ -1065,13 +1059,9 @@ void DRW_curve_batch_cache_create_requested(Object *ob) } if (DRW_vbo_requested(cache->edit.pos) || DRW_vbo_requested(cache->edit.data) || - DRW_ibo_requested(cache->ibo.edit_verts_points) || - DRW_ibo_requested(cache->ibo.edit_lines)) { - curve_create_edit_data_and_handles(rdata, - cache->edit.pos, - cache->edit.data, - cache->ibo.edit_verts_points, - cache->ibo.edit_lines); + DRW_ibo_requested(cache->ibo.edit_verts) || DRW_ibo_requested(cache->ibo.edit_lines)) { + curve_create_edit_data_and_handles( + rdata, cache->edit.pos, cache->edit.data, cache->ibo.edit_verts, cache->ibo.edit_lines); } if (DRW_vbo_requested(cache->edit.curves_nor)) { curve_create_edit_curves_nor(rdata, cache->edit.curves_nor); -- cgit v1.2.3