[Bf-blender-cvs] [9ab99ff26b5] master: Sculpt Draw: Add support for wireframe geometry

Clément Foucault noreply at git.blender.org
Mon Feb 18 14:18:28 CET 2019


Commit: 9ab99ff26b57b2f0c898356d365636697d67e345
Author: Clément Foucault
Date:   Thu Feb 14 20:24:13 2019 +0100
Branches: master
https://developer.blender.org/rB9ab99ff26b57b2f0c898356d365636697d67e345

Sculpt Draw: Add support for wireframe geometry

This introduce the wireframe batches. Creating the indices buffer does
not seems to slow down the sculpt in my testing (but it is kind of hard to
test reliably)

This includes a bit of cleanup in gpu_buffers.c.

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

M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/draw/intern/DRW_render.h
M	source/blender/draw/intern/draw_manager_data.c
M	source/blender/draw/modes/overlay_mode.c
M	source/blender/draw/modes/sculpt_mode.c
M	source/blender/draw/modes/shaders/overlay_face_wireframe_vert.glsl
M	source/blender/gpu/GPU_buffers.h
M	source/blender/gpu/intern/gpu_buffers.c

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

diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 8127d682133..87d1a6c6915 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -125,7 +125,7 @@ bool BKE_pbvh_node_find_nearest_to_ray(
 /* Drawing */
 
 void BKE_pbvh_draw_cb(
-        PBVH *bvh, float (*planes)[4], float (*fnors)[3], bool fast, bool only_mask,
+        PBVH *bvh, float (*planes)[4], float (*fnors)[3], bool fast, bool wires, bool only_mask,
         void (*draw_fn)(void *user_data, struct GPUBatch *batch), void *user_data);
 
 /* PBVH Access */
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 45a0872bdc5..69617a354a9 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -2049,6 +2049,7 @@ struct PBVHNodeDrawCallbackData {
 	void *user_data;
 	bool fast;
 	bool only_mask; /* Only draw nodes that have mask data. */
+	bool wires;
 };
 
 static void pbvh_node_draw_cb(PBVHNode *node, void *data_v)
@@ -2056,11 +2057,11 @@ static void pbvh_node_draw_cb(PBVHNode *node, void *data_v)
 	struct PBVHNodeDrawCallbackData *data = data_v;
 
 	if (!(node->flag & PBVH_FullyHidden)) {
-		GPUBatch *triangles = GPU_pbvh_buffers_batch_get(node->draw_buffers, data->fast);
+		GPUBatch *batch = GPU_pbvh_buffers_batch_get(node->draw_buffers, data->fast, data->wires);
 		bool show_mask = GPU_pbvh_buffers_has_mask(node->draw_buffers);
 		if (!data->only_mask || show_mask) {
-			if (triangles != NULL) {
-				data->draw_fn(data->user_data, triangles);
+			if (batch != NULL) {
+				data->draw_fn(data->user_data, batch);
 			}
 		}
 	}
@@ -2070,12 +2071,13 @@ static void pbvh_node_draw_cb(PBVHNode *node, void *data_v)
  * Version of #BKE_pbvh_draw that runs a callback.
  */
 void BKE_pbvh_draw_cb(
-        PBVH *bvh, float (*planes)[4], float (*fnors)[3], bool fast, bool only_mask,
+        PBVH *bvh, float (*planes)[4], float (*fnors)[3], bool fast, bool wires, bool only_mask,
         void (*draw_fn)(void *user_data, GPUBatch *batch), void *user_data)
 {
 	struct PBVHNodeDrawCallbackData draw_data = {
 		.only_mask = only_mask,
 		.fast = fast,
+		.wires = wires,
 		.draw_fn = draw_fn,
 		.user_data = user_data,
 	};
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h
index 8f78953cb52..259605b4707 100644
--- a/source/blender/draw/intern/DRW_render.h
+++ b/source/blender/draw/intern/DRW_render.h
@@ -378,6 +378,7 @@ void DRW_shgroup_call_instances_add(
 void DRW_shgroup_call_object_instances_add(
         DRWShadingGroup *shgroup, struct GPUBatch *geom, struct Object *ob, uint *count);
 void DRW_shgroup_call_sculpt_add(DRWShadingGroup *shgroup, struct Object *ob, float (*obmat)[4]);
+void DRW_shgroup_call_sculpt_wires_add(DRWShadingGroup *shgroup, struct Object *ob, float (*obmat)[4]);
 void DRW_shgroup_call_generate_add(
         DRWShadingGroup *shgroup, DRWCallGenerateFn *geometry_fn, void *user_data, float (*obmat)[4]);
 void DRW_shgroup_call_dynamic_add_array(DRWShadingGroup *shgroup, const void *attr[], uint attr_len);
diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
index 73825c700d5..54456d43ef7 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -581,7 +581,34 @@ static void sculpt_draw_cb(
 
 	if (pbvh) {
 		BKE_pbvh_draw_cb(
-		        pbvh, NULL, NULL, fast_mode, false,
+		        pbvh, NULL, NULL, fast_mode, false, false,
+		        (void (*)(void *, GPUBatch *))draw_fn, shgroup);
+	}
+}
+
+static void sculpt_draw_wires_cb(
+        DRWShadingGroup *shgroup,
+        void (*draw_fn)(DRWShadingGroup *shgroup, GPUBatch *geom),
+        void *user_data)
+{
+	Object *ob = user_data;
+
+	/* XXX should be ensured before but sometime it's not... go figure (see T57040). */
+	PBVH *pbvh = BKE_sculpt_object_pbvh_ensure(DST.draw_ctx.depsgraph, ob);
+
+	const DRWContextState *drwctx = DRW_context_state_get();
+	int fast_mode = 0;
+
+	if (drwctx->evil_C != NULL) {
+		Paint *p = BKE_paint_get_active_from_context(drwctx->evil_C);
+		if (p && (p->flags & PAINT_FAST_NAVIGATE)) {
+			fast_mode = drwctx->rv3d->rflag & RV3D_NAVIGATING;
+		}
+	}
+
+	if (pbvh) {
+		BKE_pbvh_draw_cb(
+		        pbvh, NULL, NULL, fast_mode, true, false,
 		        (void (*)(void *, GPUBatch *))draw_fn, shgroup);
 	}
 }
@@ -591,6 +618,11 @@ void DRW_shgroup_call_sculpt_add(DRWShadingGroup *shgroup, Object *ob, float (*o
 	DRW_shgroup_call_generate_add(shgroup, sculpt_draw_cb, ob, obmat);
 }
 
+void DRW_shgroup_call_sculpt_wires_add(DRWShadingGroup *shgroup, Object *ob, float (*obmat)[4])
+{
+	DRW_shgroup_call_generate_add(shgroup, sculpt_draw_wires_cb, ob, obmat);
+}
+
 void DRW_shgroup_call_dynamic_add_array(DRWShadingGroup *shgroup, const void *attr[], uint attr_len)
 {
 #ifdef USE_GPU_SELECT
diff --git a/source/blender/draw/modes/overlay_mode.c b/source/blender/draw/modes/overlay_mode.c
index ea502e176f1..9929e4ca6e4 100644
--- a/source/blender/draw/modes/overlay_mode.c
+++ b/source/blender/draw/modes/overlay_mode.c
@@ -319,11 +319,11 @@ static void overlay_cache_populate(void *vedata, Object *ob)
 			if (geom || is_sculpt_mode) {
 				shgrp = DRW_shgroup_create_sub(pd->face_wires_shgrp);
 
-				static float all_wires_param = 10.0f;
-				DRW_shgroup_uniform_float(
-				        shgrp, "wireStepParam",
-				        (all_wires || is_sculpt_mode) ? &all_wires_param : &pd->wire_step_param,
-				        1);
+				float wire_step_param = 10.0f;
+				if (!is_sculpt_mode) {
+					wire_step_param = (all_wires) ? 1.0f : pd->wire_step_param;
+				}
+				DRW_shgroup_uniform_float_copy(shgrp, "wireStepParam", wire_step_param);
 
 				if (!(DRW_state_is_select() || DRW_state_is_depth())) {
 					DRW_shgroup_stencil_mask(shgrp, stencil_mask);
@@ -332,7 +332,7 @@ static void overlay_cache_populate(void *vedata, Object *ob)
 				}
 
 				if (is_sculpt_mode) {
-					DRW_shgroup_call_sculpt_add(shgrp, ob, ob->obmat);
+					DRW_shgroup_call_sculpt_wires_add(shgrp, ob, ob->obmat);
 				}
 				else {
 					DRW_shgroup_call_add(shgrp, geom, ob->obmat);
diff --git a/source/blender/draw/modes/sculpt_mode.c b/source/blender/draw/modes/sculpt_mode.c
index 76312942613..546270f8a18 100644
--- a/source/blender/draw/modes/sculpt_mode.c
+++ b/source/blender/draw/modes/sculpt_mode.c
@@ -177,7 +177,7 @@ static void sculpt_draw_mask_cb(
 
 	if (pbvh) {
 		BKE_pbvh_draw_cb(
-		        pbvh, NULL, NULL, false, true,
+		        pbvh, NULL, NULL, false, false, true,
 		        (void (*)(void *, struct GPUBatch *))draw_fn, shgroup);
 	}
 }
diff --git a/source/blender/draw/modes/shaders/overlay_face_wireframe_vert.glsl b/source/blender/draw/modes/shaders/overlay_face_wireframe_vert.glsl
index 2a328a71366..8cb4db23b7e 100644
--- a/source/blender/draw/modes/shaders/overlay_face_wireframe_vert.glsl
+++ b/source/blender/draw/modes/shaders/overlay_face_wireframe_vert.glsl
@@ -10,7 +10,7 @@ uniform float ofs;
 #ifndef USE_SCULPT
 float get_edge_sharpness(float wd)
 {
-	return (wd == 1.0) ? 1.0 : ((wd == 0.0) ? -1.0 : (wd + wireStepParam));
+	return ((wd == 1.0) ? 1.0 : ((wd == 0.0) ? -1.5 : wd)) + wireStepParam;
 }
 #else
 float get_edge_sharpness(float wd) { return 1.0; }
diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h
index 6e3b8f20b5c..dc634b91284 100644
--- a/source/blender/gpu/GPU_buffers.h
+++ b/source/blender/gpu/GPU_buffers.h
@@ -80,7 +80,7 @@ void GPU_pbvh_grid_buffers_update(
         const int update_flags);
 
 /* draw */
-struct GPUBatch *GPU_pbvh_buffers_batch_get(GPU_PBVH_Buffers *buffers, bool fast);
+struct GPUBatch *GPU_pbvh_buffers_batch_get(GPU_PBVH_Buffers *buffers, bool fast, bool wires);
 
 bool GPU_pbvh_buffers_has_mask(GPU_PBVH_Buffers *buffers);
 
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 9004ad5f4c9..71c55da690a 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -54,8 +54,11 @@
 
 struct GPU_PBVH_Buffers {
 	GPUIndexBuf *index_buf, *index_buf_fast;
+	GPUIndexBuf *index_lines_buf, *index_lines_buf_fast;
 	GPUVertBuf *vert_buf;
 
+	GPUBatch *lines;
+	GPUBatch *lines_fast;
 	GPUBatch *triangles;
 	GPUBatch *triangles_fast;
 
@@ -75,8 +78,6 @@ struct GPU_PBVH_Buffers {
 	BLI_bitmap * const *grid_hidden;
 	const int *grid_indices;
 	int totgrid;
-	bool has_hidden;
-	bool is_index_buf_global;  /* Means index_buf uses global bvh's grid_common_gpu_buffer, **DO NOT** free it! */
 
 	bool use_bmesh;
 
@@ -93,6 +94,12 @@ static struct {
 	uint pos, nor, msk;
 } g_vbo_id = {0};
 
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name PBVH Utils
+ * \{ */
+
 /* Allocates a non-initialized buffer to be sent to GPU.
  * Return is false it indicates that the memory map failed. */
 static bool gpu_pbvh_vert_buf_data_set(GPU_PBVH_Buffers *buffers, uint vert_len)
@@ -141,8 +148,27 @@ static void gpu_pbvh_batch_init(GPU_PBVH_Buffers *buffers, GPUPrimType prim)
 		        prim, buffers->vert_buf,
 		        buffers->index_buf_fast);
 	}
+
+	if (buffers->lines == NULL) {
+		BLI_assert(buffers->index_lines_buf != NULL);
+		buffers->lines = GPU_batch_create(
+		        GPU_PRIM_LINES, buffers->vert_buf,
+		        buffers->index_lines_buf);
+	}
+
+	if ((buffers->lines_fast == NULL) && buffers->index_lines_buf_fast) {
+		buffers->lines_fast = GPU_batch_create(
+		        GPU_PRIM_LINES, buffers->vert_buf,
+		        buffers->index_lines_buf_fast);
+	}
 }
 
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Mesh PBVH
+ * \{ */
+
 void GPU_pbvh_mesh_buffers_update(
         GPU_PBVH_Buffers *buffers, const MVert *mvert,
         const int *vert_indices, int totvert, const float *vmask,
@@ -246,12 +272,7 @@ GPU_PBVH_Buffers *GPU_pbvh_mesh_buffers_build(
 	buffers = MEM_callocN(sizeof(GPU_PBVH_Buffers), "GPU_Buffers");
 
 	/* smooth or flat for all */
-#if 0
 	buffers->smooth = mpoly[looptri[face_indices[0]].poly].flag & ME_SMOOTH;
-#else
-	/* for DrawManager we dont support mixed smooth/flat */
-	buffer

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list