[Bf-blender-cvs] [27b73f0c5b8] master: GPencil: Remove legacy `ED_gpencil_draw_view3d` code.

mano-wii noreply at git.blender.org
Wed Mar 27 14:53:39 CET 2019


Commit: 27b73f0c5b8ba23e069abf107716929f106969b8
Author: mano-wii
Date:   Wed Mar 27 10:52:13 2019 -0300
Branches: master
https://developer.blender.org/rB27b73f0c5b8ba23e069abf107716929f106969b8

GPencil: Remove legacy `ED_gpencil_draw_view3d` code.

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

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

M	source/blender/draw/DRW_engine.h
M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/intern/draw_manager.c
M	source/blender/editors/gpencil/drawgpencil.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/include/ED_gpencil.h
M	source/blender/editors/space_view3d/view3d_draw_legacy.c

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

diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h
index c06a7cdc564..49d17e39de2 100644
--- a/source/blender/draw/DRW_engine.h
+++ b/source/blender/draw/DRW_engine.h
@@ -123,6 +123,10 @@ void DRW_draw_depth_loop(
         struct Depsgraph *depsgraph,
         struct ARegion *ar, struct View3D *v3d,
         struct GPUViewport *viewport);
+void DRW_draw_depth_loop_gpencil(
+        struct Depsgraph *depsgraph,
+        struct ARegion *ar, struct View3D *v3d,
+        struct GPUViewport *viewport);
 
 void DRW_framebuffer_select_id_setup(struct ARegion *ar, const bool clear);
 void DRW_framebuffer_select_id_release(struct ARegion *ar);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 3bee7d0d51c..781fbabccb7 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -414,7 +414,8 @@ void GPENCIL_cache_init(void *vedata)
 			bGPdata *gpd_orig = (bGPdata *)DEG_get_original_id(&obact_gpd->id);
 			if (((gpd_orig->runtime.sbuffer_sflag & GP_STROKE_ERASER) == 0) &&
 			    (gpd_orig->runtime.sbuffer_size > 0) &&
-			    ((gpd_orig->flag & GP_DATA_STROKE_POLYGON) == 0))
+			    ((gpd_orig->flag & GP_DATA_STROKE_POLYGON) == 0) &&
+			    !DRW_state_is_depth())
 			{
 				stl->g_data->session_flag |= GP_DRW_PAINT_PAINTING;
 			}
@@ -710,7 +711,7 @@ void GPENCIL_cache_finish(void *vedata)
 	}
 
 	/* create framebuffers (only for normal drawing) */
-	if (!DRW_state_is_select()) {
+	if (!DRW_state_is_select() || !DRW_state_is_depth()) {
 		GPENCIL_create_framebuffers(vedata);
 	}
 }
@@ -864,7 +865,7 @@ void GPENCIL_draw_scene(void *ved)
 	const bool overlay = v3d != NULL ? (bool)((v3d->flag2 & V3D_HIDE_OVERLAYS) == 0) : true;
 
 	/* if the draw is for select, do a basic drawing and return */
-	if (DRW_state_is_select()) {
+	if (DRW_state_is_select() || DRW_state_is_depth()) {
 		drw_gpencil_select_render(stl, psl);
 		/* free memory */
 		gpencil_free_obj_runtime(stl);
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index c8d53480d4f..3e5adc8f26b 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -2329,48 +2329,19 @@ static void draw_depth_texture_to_screen(GPUTexture *texture)
 	immUnbindProgram();
 }
 
+
 /**
  * object mode select-loop, see: ED_view3d_draw_depth_loop (legacy drawing).
  */
-void DRW_draw_depth_loop(
-        struct Depsgraph *depsgraph,
-        ARegion *ar, View3D *v3d,
-        GPUViewport *viewport)
+static void drw_draw_depth_loop_imp(void)
 {
-	Scene *scene = DEG_get_evaluated_scene(depsgraph);
-	RenderEngineType *engine_type = ED_view3d_engine_type(scene, v3d->shading.type);
-	ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
-	RegionView3D *rv3d = ar->regiondata;
-
 	DRW_opengl_context_enable();
 
-	/* Reset before using it. */
-	drw_state_prepare_clean_for_draw(&DST);
-
-	DST.viewport = viewport;
-	DST.options.is_depth = true;
-
-	/* Instead of 'DRW_context_state_init(C, &DST.draw_ctx)', assign from args */
-	DST.draw_ctx = (DRWContextState){
-		.ar = ar, .rv3d = rv3d, .v3d = v3d,
-		.scene = scene, .view_layer = view_layer, .obact = OBACT(view_layer),
-		.engine_type = engine_type,
-		.depsgraph = depsgraph,
-	};
-
 	/* Setup framebuffer */
-	DefaultFramebufferList *fbl = (DefaultFramebufferList *)GPU_viewport_framebuffer_list_get(viewport);
+	DefaultFramebufferList *fbl = (DefaultFramebufferList *)GPU_viewport_framebuffer_list_get(DST.viewport);
 	GPU_framebuffer_bind(fbl->depth_only_fb);
 	GPU_framebuffer_clear_depth(fbl->depth_only_fb, 1.0f);
 
-	/* Get list of enabled engines */
-	{
-		drw_engines_enable_basic();
-		if (DRW_state_draw_support()) {
-			drw_engines_enable_from_object_mode();
-		}
-	}
-
 	/* Setup viewport */
 	drw_context_state_init();
 	drw_viewport_var_init();
@@ -2384,10 +2355,11 @@ void DRW_draw_depth_loop(
 
 	{
 		drw_engines_cache_init();
-		drw_engines_world_update(scene);
+		drw_engines_world_update(DST.draw_ctx.scene);
 
+		View3D *v3d = DST.draw_ctx.v3d;
 		const int object_type_exclude_viewport = v3d->object_type_exclude_viewport;
-		DEG_OBJECT_ITER_BEGIN(depsgraph, ob,
+		DEG_OBJECT_ITER_BEGIN(DST.draw_ctx.depsgraph, ob,
 		        DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |
 		        DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET |
 		        DEG_ITER_OBJECT_FLAG_VISIBLE |
@@ -2422,12 +2394,6 @@ void DRW_draw_depth_loop(
 	DRW_draw_callbacks_post_scene();
 
 	DRW_state_reset();
-	drw_engines_disable();
-
-#ifdef DEBUG
-	/* Avoid accidental reuse. */
-	drw_state_ensure_not_reused(&DST);
-#endif
 
 	/* TODO: Reading depth for operators should be done here. */
 
@@ -2435,16 +2401,56 @@ void DRW_draw_depth_loop(
 
 	/* Changin context */
 	DRW_opengl_context_disable();
+}
+
+/**
+ * object mode select-loop, see: ED_view3d_draw_depth_loop (legacy drawing).
+ */
+void DRW_draw_depth_loop(
+        struct Depsgraph *depsgraph,
+        ARegion *ar, View3D *v3d,
+        GPUViewport *viewport)
+{
+	Scene *scene = DEG_get_evaluated_scene(depsgraph);
+	RenderEngineType *engine_type = ED_view3d_engine_type(scene, v3d->shading.type);
+	ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
+	RegionView3D *rv3d = ar->regiondata;
+
+	/* Reset before using it. */
+	drw_state_prepare_clean_for_draw(&DST);
+
+	DST.viewport = viewport;
+	DST.options.is_depth = true;
+
+	/* Instead of 'DRW_context_state_init(C, &DST.draw_ctx)', assign from args */
+	DST.draw_ctx = (DRWContextState){
+		.ar = ar, .rv3d = rv3d, .v3d = v3d,
+		.scene = scene, .view_layer = view_layer, .obact = OBACT(view_layer),
+		.engine_type = engine_type,
+		.depsgraph = depsgraph,
+	};
+
+	/* Get list of enabled engines */
+	{
+		drw_engines_enable_basic();
+		if (DRW_state_draw_support()) {
+			drw_engines_enable_from_object_mode();
+		}
+	}
+
+	drw_draw_depth_loop_imp();
+
+	drw_engines_disable();
 
 	/* XXX Drawing the resulting buffer to the BACK_BUFFER */
 	GPU_matrix_push();
 	GPU_matrix_push_projection();
-	wmOrtho2_region_pixelspace(ar);
+	wmOrtho2_region_pixelspace(DST.draw_ctx.ar);
 	GPU_matrix_identity_set();
 
 	glEnable(GL_DEPTH_TEST); /* Cannot write to depth buffer without testing */
 	glDepthFunc(GL_ALWAYS);
-	DefaultTextureList *dtxl = (DefaultTextureList *)GPU_viewport_texture_list_get(viewport);
+	DefaultTextureList *dtxl = (DefaultTextureList *)GPU_viewport_texture_list_get(DST.viewport);
 	draw_depth_texture_to_screen(dtxl->depth);
 	glDepthFunc(GL_LEQUAL);
 
@@ -2452,6 +2458,41 @@ void DRW_draw_depth_loop(
 	GPU_matrix_pop_projection();
 }
 
+/**
+ * Converted from ED_view3d_draw_depth_gpencil (legacy drawing).
+ */
+void DRW_draw_depth_loop_gpencil(
+        struct Depsgraph *depsgraph,
+        ARegion *ar, View3D *v3d,
+        GPUViewport *viewport)
+{
+	Scene *scene = DEG_get_evaluated_scene(depsgraph);
+	ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
+	RegionView3D *rv3d = ar->regiondata;
+
+	/* Reset before using it. */
+	drw_state_prepare_clean_for_draw(&DST);
+
+	DST.viewport = viewport;
+	DST.options.is_depth = true;
+
+	/* Instead of 'DRW_context_state_init(C, &DST.draw_ctx)', assign from args */
+	DST.draw_ctx = (DRWContextState){
+		.ar = ar, .rv3d = rv3d, .v3d = v3d,
+		.scene = scene, .view_layer = view_layer, .obact = OBACT(view_layer),
+		.depsgraph = depsgraph,
+	};
+
+	use_drw_engine(&draw_engine_gpencil_type);
+	drw_draw_depth_loop_imp();
+	drw_engines_disable();
+
+#ifdef DEBUG
+	/* Avoid accidental reuse. */
+	drw_state_ensure_not_reused(&DST);
+#endif
+}
+
 
 /* Set an opengl context to be used with shaders that draw on U32 colors. */
 void DRW_framebuffer_select_id_setup(ARegion *ar, const bool clear)
@@ -2496,6 +2537,11 @@ void DRW_framebuffer_select_id_release(ARegion *ar)
 	glEnable(GL_DITHER);
 
 	DRW_opengl_context_disable();
+
+#ifdef DEBUG
+	/* Avoid accidental reuse. */
+	drw_state_ensure_not_reused(&DST);
+#endif
 }
 
 
diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index 45498882160..711962400ff 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -117,13 +117,6 @@ typedef enum eDrawStrokeFlags {
 /* ----- Tool Buffer Drawing ------ */
 /* helper functions to set color of buffer point */
 
-static void gp_set_tpoint_varying_color(const tGPspoint *pt, const float ink[4], uint attr_id)
-{
-	float alpha = ink[3] * pt->strength;
-	CLAMP(alpha, GPENCIL_STRENGTH_MIN, 1.0f);
-	immAttr4ub(attr_id, F2UB(ink[0]), F2UB(ink[1]), F2UB(ink[2]), F2UB(alpha));
-}
-
 static void gp_set_point_uniform_color(const bGPDspoint *pt, const float ink[4])
 {
 	float alpha = ink[3] * pt->strength;
@@ -138,161 +131,6 @@ static void gp_set_point_varying_color(const bGPDspoint *pt, const float ink[4],
 	immAttr4ub(attr_id, F2UB(ink[0]), F2UB(ink[1]), F2UB(ink[2]), F2UB(alpha));
 }
 
-/* draw fills for buffer stroke */
-static void gp_draw_stroke_buffer_fill(const tGPspoint *points, int totpoints, float ink[4])
-{
-	if (totpoints < 3) {
-		return;
-	}
-	int tot_triangles = totpoints - 2;
-	/* allocate memory for temporary areas */
-	uint(*tmp_triangles)[3] = MEM_mallocN(sizeof(*tmp_triangles) * tot_triangles, "GP Stroke buffer temp triangulation");
-	float(*points2d)[2] = MEM_mallocN(sizeof(*points2d) * totpoints, "GP Stroke buffer temp 2d points");
-
-	/* Convert points to array and triangulate
-	 * Here a cache is not used because while drawing the information changes all the time, so the cache
-	 * would be recalculated constantly, so it is better to do direct calculation for each function call
-	 */
-	for (int i = 0; i < totpoints; i++) {
-		const tGPspoint *pt = &points[i];
-		points2d[i][0] = pt->x;
-		points2d[i][1] = pt->y;
-	}
-	BLI_polyfill_calc((const float(*)[2])points2d, (uint)totpoints, 0, (uint(*)[3])tmp_triangles);
-
-	/* draw triangulation data */
-	if (tot_triangles > 0) {
-		GPUVertFormat *format = immVertexFormat();
-		uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
-		uint color = GPU_vertformat_attr_add(format, "color", GPU_COMP_U8, 4, 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list