[Bf-blender-cvs] [0c21773199f] blender2.8: Edit Curve: Fix cannot hide handles

Clément Foucault noreply at git.blender.org
Tue Sep 25 22:52:49 CEST 2018


Commit: 0c21773199f326f976ec763b05b2cb68cac8a109
Author: Clément Foucault
Date:   Tue Sep 25 20:56:22 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB0c21773199f326f976ec763b05b2cb68cac8a109

Edit Curve: Fix cannot hide handles

===================================================================

M	source/blender/draw/intern/draw_cache.c
M	source/blender/draw/intern/draw_cache.h
M	source/blender/draw/intern/draw_cache_impl.h
M	source/blender/draw/intern/draw_cache_impl_curve.c
M	source/blender/draw/modes/edit_curve_mode.c

===================================================================

diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index abc62c7e175..716ad93223a 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -3121,12 +3121,12 @@ GPUBatch *DRW_cache_curve_edge_overlay_get(Object *ob)
 	return DRW_curve_batch_cache_get_overlay_edges(cu);
 }
 
-GPUBatch *DRW_cache_curve_vert_overlay_get(Object *ob)
+GPUBatch *DRW_cache_curve_vert_overlay_get(Object *ob, bool handles)
 {
 	BLI_assert(ob->type == OB_CURVE);
 
 	struct Curve *cu = ob->data;
-	return DRW_curve_batch_cache_get_overlay_verts(cu);
+	return DRW_curve_batch_cache_get_overlay_verts(cu, handles);
 }
 
 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 edd1362bf9b..f97ff34eecf 100644
--- a/source/blender/draw/intern/draw_cache.h
+++ b/source/blender/draw/intern/draw_cache.h
@@ -160,7 +160,7 @@ struct GPUBatch *DRW_cache_curve_edge_wire_get(struct Object *ob);
 /* edit-mode */
 struct GPUBatch *DRW_cache_curve_edge_normal_get(struct Object *ob, float normal_size);
 struct GPUBatch *DRW_cache_curve_edge_overlay_get(struct Object *ob);
-struct GPUBatch *DRW_cache_curve_vert_overlay_get(struct Object *ob);
+struct GPUBatch *DRW_cache_curve_vert_overlay_get(struct Object *ob, bool handles);
 
 /* Font */
 struct GPUBatch *DRW_cache_text_edge_wire_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 444d5aeb12d..372ec6cdf6c 100644
--- a/source/blender/draw/intern/draw_cache_impl.h
+++ b/source/blender/draw/intern/draw_cache_impl.h
@@ -67,7 +67,7 @@ struct GPUBatch *DRW_curve_batch_cache_get_wire_edge(struct Curve *cu, struct Cu
 struct GPUBatch *DRW_curve_batch_cache_get_normal_edge(
         struct Curve *cu, struct CurveCache *ob_curve_cache, float normal_size);
 struct GPUBatch *DRW_curve_batch_cache_get_overlay_edges(struct Curve *cu);
-struct GPUBatch *DRW_curve_batch_cache_get_overlay_verts(struct Curve *cu);
+struct GPUBatch *DRW_curve_batch_cache_get_overlay_verts(struct Curve *cu, bool handles);
 
 struct GPUBatch *DRW_curve_batch_cache_get_triangles_with_normals(
         struct Curve *cu, struct CurveCache *ob_curve_cache);
diff --git a/source/blender/draw/intern/draw_cache_impl_curve.c b/source/blender/draw/intern/draw_cache_impl_curve.c
index 1f20babdcae..f2b303207fd 100644
--- a/source/blender/draw/intern/draw_cache_impl_curve.c
+++ b/source/blender/draw/intern/draw_cache_impl_curve.c
@@ -70,15 +70,14 @@ static void curve_batch_cache_clear(Curve *cu);
 /* Curve Interface, direct access to basic data. */
 
 static void curve_render_overlay_verts_edges_len_get(
-        ListBase *lb, bool hide_handles,
-        int *r_vert_len, int *r_edge_len)
+        ListBase *lb, int *r_vert_len, int *r_edge_len)
 {
 	BLI_assert(r_vert_len || r_edge_len);
 	int vert_len = 0;
 	int edge_len = 0;
 	for (Nurb *nu = lb->first; nu; nu = nu->next) {
 		if (nu->bezt) {
-			vert_len += hide_handles ? nu->pntsu : (nu->pntsu * 3);
+			vert_len += nu->pntsu * 3;
 			/* 2x handles per point*/
 			edge_len += 2 * nu->pntsu;
 		}
@@ -231,9 +230,9 @@ static CurveRenderData *curve_render_data_create(Curve *cu, CurveCache *ob_curve
 
 		if (types & CU_DATATYPE_OVERLAY) {
 			curve_render_overlay_verts_edges_len_get(
-			        nurbs, rdata->hide_handles,
+			        nurbs,
 			        &rdata->overlay.vert_len,
-			        rdata->hide_handles ? NULL : &rdata->overlay.edge_len);
+			        &rdata->overlay.edge_len);
 
 			rdata->actnu = cu->actnu;
 			rdata->actvert = cu->actvert;
@@ -318,6 +317,7 @@ typedef struct CurveBatchCache {
 	struct {
 		GPUBatch *edges;
 		GPUBatch *verts;
+		GPUBatch *verts_no_handles;
 	} overlay;
 
 	struct {
@@ -337,9 +337,6 @@ typedef struct CurveBatchCache {
 	/* settings to determine if cache is invalid */
 	bool is_dirty;
 
-	bool hide_handles;
-	bool hide_normals;
-
 	float normal_size;
 
 	bool is_editmode;
@@ -364,15 +361,7 @@ static bool curve_batch_cache_valid(Curve *cu)
 	}
 
 	if (cache->is_editmode) {
-		if (cu->editnurb) {
-			if (cache->hide_handles != false) {
-				return false;
-			}
-			else if (cache->hide_normals != false) {
-				return false;
-			}
-		}
-		else if (cu->editfont) {
+		if (cu->editfont) {
 			/* TODO */
 		}
 	}
@@ -391,9 +380,6 @@ static void curve_batch_cache_init(Curve *cu)
 		memset(cache, 0, sizeof(*cache));
 	}
 
-	cache->hide_handles = false;
-	cache->hide_normals = false;
-
 #if 0
 	ListBase *nurbs;
 	if (cu->editnurb) {
@@ -431,6 +417,7 @@ void DRW_curve_batch_cache_dirty_tag(Curve *cu, int mode)
 			break;
 		case BKE_CURVE_BATCH_DIRTY_SELECT:
 			/* editnurb */
+			GPU_BATCH_DISCARD_SAFE(cache->overlay.verts_no_handles);
 			GPU_BATCH_DISCARD_SAFE(cache->overlay.verts);
 			GPU_BATCH_DISCARD_SAFE(cache->overlay.edges);
 
@@ -450,6 +437,7 @@ static void curve_batch_cache_clear(Curve *cu)
 		return;
 	}
 
+	GPU_BATCH_DISCARD_SAFE(cache->overlay.verts_no_handles);
 	GPU_BATCH_DISCARD_SAFE(cache->overlay.verts);
 	GPU_BATCH_DISCARD_SAFE(cache->overlay.edges);
 
@@ -676,33 +664,28 @@ static void curve_batch_cache_create_overlay_batches(Curve *cu)
 
 		GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format);
 		const int vbo_len_capacity = curve_render_data_overlay_verts_len_get(rdata);
+		GPUIndexBufBuilder elb;
+		GPU_indexbuf_init(&elb, GPU_PRIM_POINTS, vbo_len_capacity, vbo_len_capacity);
 		int vbo_len_used = 0;
 		GPU_vertbuf_data_alloc(vbo, vbo_len_capacity);
-		int i = 0;
-		for (Nurb *nu = rdata->nurbs->first; nu; nu = nu->next) {
+		int i = 0, nu_id = 0;
+		for (Nurb *nu = rdata->nurbs->first; nu; nu = nu->next, nu_id++) {
+			const bool is_active_nurb = (nu_id == cu->actnu);
 			if (nu->bezt) {
 				int a = 0;
 				for (const BezTriple *bezt = nu->bezt; a < nu->pntsu; a++, bezt++) {
 					if (bezt->hide == false) {
 						const bool is_active = (i == rdata->actvert);
-						char vflag;
-
-						if (rdata->hide_handles) {
-							vflag = (bezt->f2 & SELECT) ?
-							        (is_active ? VFLAG_VERTEX_ACTIVE : VFLAG_VERTEX_SELECTED) : 0;
-							GPU_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used, bezt->vec[1]);
+						GPU_indexbuf_add_point_vert(&elb, vbo_len_used + 1);
+						for (int j = 0; j < 3; j++) {
+							char vflag = ((&bezt->f1)[j] & SELECT)
+							              ? (is_active ? VFLAG_VERTEX_ACTIVE : VFLAG_VERTEX_SELECTED)
+							              : 0;
+							vflag |= (is_active_nurb) ? ACTIVE_NURB : 0;
+							GPU_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used, bezt->vec[j]);
 							GPU_vertbuf_attr_set(vbo, attr_id.data, vbo_len_used, &vflag);
 							vbo_len_used += 1;
 						}
-						else {
-							for (int j = 0; j < 3; j++) {
-								vflag = ((&bezt->f1)[j] & SELECT) ?
-								        (is_active ? VFLAG_VERTEX_ACTIVE : VFLAG_VERTEX_SELECTED) : 0;
-								GPU_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used, bezt->vec[j]);
-								GPU_vertbuf_attr_set(vbo, attr_id.data, vbo_len_used, &vflag);
-								vbo_len_used += 1;
-							}
-						}
 					}
 					i += 1;
 				}
@@ -712,8 +695,11 @@ static void curve_batch_cache_create_overlay_batches(Curve *cu)
 				for (const BPoint *bp = nu->bp; a < nu->pntsu; a++, bp++) {
 					if (bp->hide == false) {
 						const bool is_active = (i == rdata->actvert);
-						char vflag;
-						vflag = (bp->f1 & SELECT) ? (is_active ? VFLAG_VERTEX_ACTIVE : VFLAG_VERTEX_SELECTED) : 0;
+						char vflag = (bp->f1 & SELECT)
+						              ? (is_active ? VFLAG_VERTEX_ACTIVE : VFLAG_VERTEX_SELECTED)
+						              : 0;
+						vflag |= (is_active_nurb) ? ACTIVE_NURB : 0;
+						GPU_indexbuf_add_point_vert(&elb, vbo_len_used);
 						GPU_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used, bp->vec);
 						GPU_vertbuf_attr_set(vbo, attr_id.data, vbo_len_used, &vflag);
 						vbo_len_used += 1;
@@ -727,7 +713,10 @@ static void curve_batch_cache_create_overlay_batches(Curve *cu)
 			GPU_vertbuf_data_resize(vbo, vbo_len_used);
 		}
 
+		GPUIndexBuf *ibo = GPU_indexbuf_build(&elb);
+
 		cache->overlay.verts = GPU_batch_create_ex(GPU_PRIM_POINTS, vbo, NULL, GPU_BATCH_OWNS_VBO);
+		cache->overlay.verts_no_handles = GPU_batch_create_ex(GPU_PRIM_POINTS, vbo, ibo, GPU_BATCH_OWNS_INDEX);
 	}
 
 
@@ -996,15 +985,15 @@ GPUBatch *DRW_curve_batch_cache_get_overlay_edges(Curve *cu)
 	return cache->overlay.edges;
 }
 
-GPUBatch *DRW_curve_batch_cache_get_overlay_verts(Curve *cu)
+GPUBatch *DRW_curve_batch_cache_get_overlay_verts(Curve *cu, bool handles)
 {
 	CurveBatchCache *cache = curve_batch_cache_get(cu);
 
-	if (cache->overlay.verts == NULL) {
+	if (cache->overlay.verts == NULL || cache->overlay.verts_no_handles == NULL) {
 		curve_batch_cache_create_overlay_batches(cu);
 	}
 
-	return cache->overlay.verts;
+	return (handles) ? cache->overlay.verts : cache->overlay.verts_no_handles;
 }
 
 GPUBatch *DRW_curve_batch_cache_get_triangles_with_normals(
diff --git a/source/blender/draw/modes/edit_curve_mode.c b/source/blender/draw/modes/edit_curve_mode.c
index fb3f67e6d9f..fd5f5907d24 100644
--- a/source/blender/draw/modes/edit_curve_mode.c
+++ b/source/blender/draw/modes/edit_curve_mode.c
@@ -254,13 +254,16 @@ static void EDIT_CURVE_cache_populate(void *vedata, Object *ob)
 				DRW_shgroup_call_add(stl->g_data->wire_shgrp, geom, ob->obmat);
 			}
 
-			/* Add geom to a shading group */
-			geom = DRW_cache_curve_edge_overlay_get(ob);
-			if (geom) {
-				DRW_shgroup_call_add(stl->g_data->overlay_edge_shgrp, geom, ob->obmat);
+			bool show_handles = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_CU_HANDLES) != 0;
+
+			if (show_handles) {
+				geom = DRW_cache_curve_edge_overlay_get(ob);
+				if (geom) {
+					DRW_shgroup_call_add(stl->g_data->overlay_edge_shgrp, geom, ob->obmat);
+				}
 			}
 
-			geom = DRW_cache_curve_vert_overlay_get(ob);
+			geom = DRW_cache_curve_vert_overlay_get(ob, show_handles);
 			DRW_shgroup_call_add(stl->g_data->overlay_vert_shgrp, geom, ob->obmat);
 		}
 	}



More information about the Bf-blender-cvs mailing list