[Bf-blender-cvs] [deb3b8301ab] master: DrawManager: Add Edge Detection To DisplayLists

Jeroen Bakker noreply at git.blender.org
Thu Mar 28 14:52:59 CET 2019


Commit: deb3b8301ab3e94b34b990a434332501e39ae77a
Author: Jeroen Bakker
Date:   Thu Mar 28 14:51:29 2019 +0100
Branches: master
https://developer.blender.org/rBdeb3b8301ab3e94b34b990a434332501e39ae77a

DrawManager: Add Edge Detection To DisplayLists

Objects that internally uses DispList do not cast shadow in the workbench.
Their outline is also not visible in object mode. The reason for this is
that edge detection was not implemented for Display Lists. This patch will
implement the edge detection.

Reviewed By: fclem

Maniphest Tasks: T62479

Differential Revision: https://developer.blender.org/D4605

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

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/intern/draw_cache_impl_displist.c
M	source/blender/draw/intern/draw_cache_impl_metaball.c

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

diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index 482cc047bbc..cdbbcf9ec2b 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -705,8 +705,14 @@ GPUBatch *DRW_cache_object_edge_detection_get(Object *ob, bool *r_is_manifold)
 	switch (ob->type) {
 		case OB_MESH:
 			return DRW_cache_mesh_edge_detection_get(ob, r_is_manifold);
-
-		/* TODO, should match 'DRW_cache_object_surface_get' */
+		case OB_CURVE:
+			return DRW_cache_curve_edge_detection_get(ob, r_is_manifold);
+		case OB_SURF:
+			return DRW_cache_surf_edge_detection_get(ob, r_is_manifold);
+		case OB_FONT:
+			return DRW_cache_text_edge_detection_get(ob, r_is_manifold);
+		case OB_MBALL:
+			return DRW_cache_mball_edge_detection_get(ob, r_is_manifold);
 		default:
 			return NULL;
 	}
@@ -3179,6 +3185,19 @@ GPUBatch *DRW_cache_curve_face_wireframe_get(Object *ob)
 	}
 }
 
+GPUBatch *DRW_cache_curve_edge_detection_get(Object *ob, bool *r_is_manifold)
+{
+	BLI_assert(ob->type == OB_CURVE);
+	struct Curve *cu = ob->data;
+	struct Mesh *mesh_eval = ob->runtime.mesh_eval;
+	if (mesh_eval != NULL) {
+		return DRW_mesh_batch_cache_get_edge_detection(mesh_eval, r_is_manifold);
+	}
+	else {
+		return DRW_curve_batch_cache_get_edge_detection(cu, r_is_manifold);
+	}
+}
+
 /* Return list of batches */
 GPUBatch **DRW_cache_curve_surface_shaded_get(
         Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len)
@@ -3207,6 +3226,11 @@ GPUBatch *DRW_cache_mball_surface_get(Object *ob)
 	return DRW_metaball_batch_cache_get_triangles_with_normals(ob);
 }
 
+GPUBatch *DRW_cache_mball_edge_detection_get(Object *ob, bool *r_is_manifold) {
+	BLI_assert(ob->type == OB_MBALL);
+	return DRW_metaball_batch_cache_get_edge_detection(ob, r_is_manifold);
+}
+
 GPUBatch *DRW_cache_mball_face_wireframe_get(Object *ob)
 {
 	BLI_assert(ob->type == OB_MBALL);
@@ -3251,6 +3275,22 @@ GPUBatch *DRW_cache_text_surface_get(Object *ob)
 	}
 }
 
+GPUBatch *DRW_cache_text_edge_detection_get(Object *ob, bool *r_is_manifold)
+{
+	BLI_assert(ob->type == OB_FONT);
+	struct Curve *cu = ob->data;
+	struct Mesh *mesh_eval = ob->runtime.mesh_eval;
+	if (cu->editfont && (cu->flag & CU_FAST)) {
+		return NULL;
+	}
+	if (mesh_eval != NULL) {
+		return DRW_mesh_batch_cache_get_edge_detection(mesh_eval, r_is_manifold);
+	}
+	else {
+		return DRW_curve_batch_cache_get_edge_detection(cu, r_is_manifold);
+	}
+}
+
 GPUBatch *DRW_cache_text_loose_edges_get(Object *ob)
 {
 	BLI_assert(ob->type == OB_FONT);
@@ -3343,6 +3383,19 @@ GPUBatch *DRW_cache_surf_face_wireframe_get(Object *ob)
 	}
 }
 
+GPUBatch *DRW_cache_surf_edge_detection_get(Object *ob, bool *r_is_manifold)
+{
+	BLI_assert(ob->type == OB_SURF);
+	struct Curve *cu = ob->data;
+	struct Mesh *mesh_eval = ob->runtime.mesh_eval;
+	if (mesh_eval != NULL) {
+		return DRW_mesh_batch_cache_get_edge_detection(mesh_eval, r_is_manifold);
+	}
+	else {
+		return DRW_curve_batch_cache_get_edge_detection(cu, r_is_manifold);
+	}
+}
+
 GPUBatch *DRW_cache_surf_loose_edges_get(Object *ob)
 {
 	BLI_assert(ob->type == OB_SURF);
diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h
index 287d970e298..2940a2c89f8 100644
--- a/source/blender/draw/intern/draw_cache.h
+++ b/source/blender/draw/intern/draw_cache.h
@@ -145,6 +145,7 @@ struct GPUBatch **DRW_cache_curve_surface_shaded_get(
 struct GPUBatch *DRW_cache_curve_loose_edges_get(struct Object *ob);
 struct GPUBatch *DRW_cache_curve_edge_wire_get(struct Object *ob);
 struct GPUBatch *DRW_cache_curve_face_wireframe_get(Object *ob);
+struct GPUBatch *DRW_cache_curve_edge_detection_get(struct Object *ob, bool *r_is_manifold);
 /* edit-mode */
 struct GPUBatch *DRW_cache_curve_edge_normal_get(struct Object *ob);
 struct GPUBatch *DRW_cache_curve_edge_overlay_get(struct Object *ob);
@@ -152,6 +153,7 @@ struct GPUBatch *DRW_cache_curve_vert_overlay_get(struct Object *ob, bool handle
 
 /* Font */
 struct GPUBatch *DRW_cache_text_surface_get(struct Object *ob);
+struct GPUBatch *DRW_cache_text_edge_detection_get(Object *ob, bool *r_is_manifold);
 struct GPUBatch *DRW_cache_text_loose_edges_get(struct Object *ob);
 struct GPUBatch *DRW_cache_text_edge_wire_get(struct Object *ob);
 struct GPUBatch **DRW_cache_text_surface_shaded_get(
@@ -165,6 +167,7 @@ struct GPUBatch *DRW_cache_surf_loose_edges_get(struct Object *ob);
 struct GPUBatch **DRW_cache_surf_surface_shaded_get(
         struct Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len);
 struct GPUBatch *DRW_cache_surf_face_wireframe_get(Object *ob);
+struct GPUBatch *DRW_cache_surf_edge_detection_get(struct Object *ob, bool *r_is_manifold);
 
 /* Lattice */
 struct GPUBatch *DRW_cache_lattice_verts_get(struct Object *ob);
@@ -188,5 +191,6 @@ struct GPUBatch *DRW_cache_particles_get_prim(int type);
 struct GPUBatch *DRW_cache_mball_surface_get(struct Object *ob);
 struct GPUBatch **DRW_cache_mball_surface_shaded_get(struct Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len);
 struct GPUBatch *DRW_cache_mball_face_wireframe_get(Object *ob);
+struct GPUBatch *DRW_cache_mball_edge_detection_get(struct Object *ob, bool *r_is_manifold);
 
 #endif /* __DRAW_CACHE_H__ */
diff --git a/source/blender/draw/intern/draw_cache_impl.h b/source/blender/draw/intern/draw_cache_impl.h
index 7a8cea23655..4e014711245 100644
--- a/source/blender/draw/intern/draw_cache_impl.h
+++ b/source/blender/draw/intern/draw_cache_impl.h
@@ -66,6 +66,7 @@ void DRW_curve_batch_cache_create_requested(struct Object *ob);
 
 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);
 
@@ -73,12 +74,12 @@ struct GPUBatch *DRW_curve_batch_cache_get_triangles_with_normals(struct Curve *
 struct GPUBatch **DRW_curve_batch_cache_get_surface_shaded(
         struct Curve *cu, struct GPUMaterial **gpumat_array, uint gpumat_array_len);
 struct GPUBatch *DRW_curve_batch_cache_get_wireframes_face(struct Curve *cu);
-
 /* Metaball */
 struct GPUBatch *DRW_metaball_batch_cache_get_triangles_with_normals(struct Object *ob);
 struct GPUBatch **DRW_metaball_batch_cache_get_surface_shaded(
         struct Object *ob, struct MetaBall *mb, struct GPUMaterial **gpumat_array, uint gpumat_array_len);
 struct GPUBatch *DRW_metaball_batch_cache_get_wireframes_face(struct Object *ob);
+struct GPUBatch *DRW_metaball_batch_cache_get_edge_detection(struct Object *ob, bool *r_is_manifold);
 
 /* DispList */
 void DRW_displist_vertbuf_create_pos_and_nor(struct ListBase *lb, struct GPUVertBuf *vbo);
@@ -89,6 +90,7 @@ void DRW_displist_indexbuf_create_lines_in_order(struct ListBase *lb, struct GPU
 void DRW_displist_indexbuf_create_triangles_in_order(struct ListBase *lb, struct GPUIndexBuf *ibo);
 void DRW_displist_indexbuf_create_triangles_loop_split_by_material(
         struct ListBase *lb, struct GPUIndexBuf **ibo_mat, uint mat_len);
+void DRW_displist_indexbuf_create_edges_adjacency_lines(struct ListBase *lb, struct GPUIndexBuf *ibo, bool *r_is_manifold);
 
 /* Lattice */
 struct GPUBatch *DRW_lattice_batch_cache_get_all_edges(struct Lattice *lt, bool use_weight, const int actdef);
diff --git a/source/blender/draw/intern/draw_cache_impl_curve.c b/source/blender/draw/intern/draw_cache_impl_curve.c
index ebffedf9454..eecb6c3dd6a 100644
--- a/source/blender/draw/intern/draw_cache_impl_curve.c
+++ b/source/blender/draw/intern/draw_cache_impl_curve.c
@@ -366,6 +366,7 @@ typedef struct CurveBatchCache {
 		GPUIndexBuf *surfaces_tris;
 		GPUIndexBuf *surfaces_lines;
 		GPUIndexBuf *curves_lines;
+		GPUIndexBuf *edges_adj_lines;
 		/* Edit mode */
 		GPUIndexBuf *edit_verts_points; /* Only control points. Not handles. */
 		GPUIndexBuf *edit_lines;
@@ -380,6 +381,7 @@ typedef struct CurveBatchCache {
 		GPUBatch *edit_verts;
 		GPUBatch *edit_handles_verts;
 		GPUBatch *edit_normals;
+		GPUBatch *edge_detection;
 	} batch;
 
 	GPUIndexBuf **surf_per_mat_tris;
@@ -390,6 +392,9 @@ typedef struct CurveBatchCache {
 	/* settings to determine if cache is invalid */
 	bool is_dirty;
 	bool is_editmode;
+
+	/* Valid only if edge_detection is up to date. */
+	bool is_manifold;
 } CurveBatchCache;
 
 /* GPUBatch cache management. */
@@ -880,6 +885,17 @@ GPUBatch *DRW_curve_batch_cache_get_wireframes_face(Curve *cu)
 	return DRW_batch_request(&cache->batch.surfaces_edges);
 }
 
+GPUBatch *DRW_curve_batch_cache_get_edge_detection(Curve *cu, bool *r_is_manifold)
+{
+	CurveBatchCache *cache = curve_batch_cache_get(cu);
+	/* Even if is_manifold is not correct (not updated),
+	 * the default (not manifold) is just the worst case. */
+	if (r_is_manifold) {
+		*r_is_manifold = cache->is_manifold;
+	}
+	return DRW_batch_request(&cache->batch.edge_detection);
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
@@ -922,6 +938,10 @@ void DRW_curve_batch_cache_create_requested(Object *ob)
 		DRW_ibo_request(cache->batch.curves, &cache->ibo.curves_lines);
 		DRW_vbo_request(cache->batch.curves, &cache->ordered.curves_pos);
 	}
+	if (DRW_batch_requested(cache->batch.edge_detection, GPU_PRIM_LINES_ADJ)) {
+		DRW_ibo_request(cache->batch.edge_detection, &cache->ibo.edges_adj_lines);
+		DRW_vbo_request(cache->batch.edge_detection, &cache->ordered.pos_nor);
+	}
 
 	/* Edit mode */
 	if (DRW_batch_requested(cache->batch.edit_edges, GPU_PRIM_LINES)) {
@@ -963,6 +983,7 @@ void DRW_curve_batch_cache_create_requested(Object *ob)
 	DRW_ADD_FLAG_FROM_IBO_REQUEST(mr_flag, cache->ibo.surfaces_tris, CU_DATATYPE_SURFACE);
 	DRW_ADD_FLAG_FROM_IBO_REQUEST(mr_flag, cache->ibo.surfaces_lines, CU_DATATYPE_SURFACE);
 	DRW_ADD_FLAG_FROM_IBO_REQUEST(mr_flag, cache->ibo.curves_lines, CU_DATATYPE_WIRE);
+	DRW_ADD_FLAG_FROM_IBO_REQUEST(mr_flag, cache->ibo.edges_adj_lines, CU_DATATYPE_SURFACE);
 
 	DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_flag, cache->edit.pos, CU

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list