[Bf-blender-cvs] [ffda00ee71c] greasepencil-object: Rework in Fast Drawing to avoid lags

Antonio Vazquez noreply at git.blender.org
Wed Sep 13 08:17:31 CEST 2017


Commit: ffda00ee71c6fa1013c1d32a5d9f3bc3e5d06ba7
Author: Antonio Vazquez
Date:   Wed Sep 13 08:17:17 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rBffda00ee71c6fa1013c1d32a5d9f3bc3e5d06ba7

Rework in Fast Drawing to avoid lags

Try to avoid any lag for very short and fast strokes

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

M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h

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

diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 5f4f1c98e63..78c4486a998 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -107,7 +107,6 @@ void BKE_gpencil_move_animdata_to_palettes(struct bContext *C, struct bGPdata *g
 #define GPENCIL_STRENGTH_MIN 0.003f
 
 bool gpencil_layer_is_editable(const struct bGPDlayer *gpl);
-bool BKE_gpencil_check_drawing_sessions(void);
 
 /* How gpencil_layer_getframe() should behave when there
  * is no existing GP-Frame on the frame requested.
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 8c83339c13d..fac61828c37 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1662,22 +1662,6 @@ void BKE_gpencil_batch_cache_alldirty()
 	}
 }
 
-/* check if any datablock is painting now */
-bool BKE_gpencil_check_drawing_sessions()
-{
-	bGPdata *gpd;
-	Main *bmain = G.main;
-
-	/* loop to check if any datablock is painting */
-	for (gpd = bmain->gpencil.first; gpd; gpd = gpd->id.next) {
-		if (((gpd->sbuffer_sflag & GP_STROKE_ERASER) == 0) && (gpd->sbuffer_size > 0)) {
-			return true;
-		}
-	}
-
-	return false;
-}
-
 /* get stroke min max values */
 void static gpencil_minmax(bGPdata *gpd, float min[3], float max[3])
 {
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index c3a50047c0e..78d422bc861 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -184,6 +184,7 @@ static void GPENCIL_cache_init(void *vedata)
 	const DRWContextState *draw_ctx = DRW_context_state_get();
 	Scene *scene = draw_ctx->scene;
 	ToolSettings *ts = scene->toolsettings;
+	Object *obact = draw_ctx->obact;
 
 	if (!stl->g_data) {
 		/* Alloc transient pointers */
@@ -255,15 +256,20 @@ static void GPENCIL_cache_init(void *vedata)
 				}
 			}
 		}
-		/* detect if painting session in any datablock */
-		if (BKE_gpencil_check_drawing_sessions()) {
-			if (stl->g_data->session_flag & GP_DRW_PAINT_IDLE) {
-				stl->g_data->session_flag = GP_DRW_PAINT_DIRTY;
+		/* detect if painting session */
+		if ((obact) && (obact->gpd) && (obact->gpd->flag & GP_DATA_STROKE_PAINTMODE) 
+			&& (stl->storage->playing == 0)) 
+		{
+			if (((obact->gpd->sbuffer_sflag & GP_STROKE_ERASER) == 0) && (obact->gpd->sbuffer_size > 0)) {
+				stl->g_data->session_flag = GP_DRW_PAINT_PAINTING;
+			}
+			else {
+				stl->g_data->session_flag = GP_DRW_PAINT_IDLE;
 			}
 		}
 		else {
-			/* if not drawing, the painting session is idle */
-			stl->g_data->session_flag = GP_DRW_PAINT_IDLE;
+			/* if not drawing mode */
+			stl->g_data->session_flag = GP_DRW_PAINT_HOLD;
 		}
 
 		ob = draw_ctx->obact;
@@ -519,6 +525,24 @@ static void gpencil_vfx_passes(void *vedata, tGPencilObjectCache *cache)
 	}
 }
 
+/* prepare a texture with full viewport for fast drawing */
+static void gpencil_prepare_fast_drawing(GPENCIL_StorageList *stl, DefaultFramebufferList *dfbl, GPENCIL_FramebufferList *fbl, DRWPass *pass, float clearcol[4])
+{
+	if (stl->g_data->session_flag & (GP_DRW_PAINT_IDLE | GP_DRW_PAINT_FILLING)) {
+		DRW_framebuffer_bind(fbl->painting_fb);
+		/* clean only in first loop cycle */
+		if (stl->g_data->session_flag & GP_DRW_PAINT_IDLE) {
+			DRW_framebuffer_clear(true, true, false, clearcol, 1.0f);
+			stl->g_data->session_flag = GP_DRW_PAINT_FILLING;
+		}
+		/* repeat pass to fill temp texture */
+		DRW_draw_pass(pass);
+		/* set default framebuffer again */
+		DRW_framebuffer_bind(dfbl->default_fb);
+	}
+}
+
+/* draw scene */
 static void GPENCIL_draw_scene(void *vedata)
 {
 	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
@@ -549,7 +573,7 @@ static void GPENCIL_draw_scene(void *vedata)
 	DRW_framebuffer_texture_attach(fbl->painting_fb, e_data.painting_color_tx, 0, 0);
 
 	/* if we have a painting session, we use fast viewport drawing method */
-	if (stl->g_data->session_flag & GP_DRW_PAINT_READY) {
+	if (stl->g_data->session_flag & GP_DRW_PAINT_PAINTING) {
 		DRW_framebuffer_bind(dfbl->default_fb);
 		DRW_draw_pass(psl->painting_pass);
 		DRW_draw_pass(psl->drawing_pass);
@@ -598,25 +622,16 @@ static void GPENCIL_draw_scene(void *vedata)
 					DRW_framebuffer_bind(dfbl->default_fb);
 					/* Mix VFX Pass */
 					DRW_draw_pass(psl->mix_vfx_pass);
+					/* prepare for fast drawing */	
+					gpencil_prepare_fast_drawing(stl, dfbl, fbl, psl->mix_vfx_pass, clearcol);
 				}
 				else {
 					/* Combine with scene buffer without more passes */
 					DRW_framebuffer_bind(dfbl->default_fb);
 					/* Mix Pass: DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS */
 					DRW_draw_pass(psl->mix_pass);
-					if (stl->g_data->session_flag & (GP_DRW_PAINT_DIRTY | GP_DRW_PAINT_FILLING)) {
-						DRW_framebuffer_bind(fbl->painting_fb);
-						/* clean only in first loop cycle */
-						if (stl->g_data->session_flag & GP_DRW_PAINT_DIRTY) {
-							DRW_framebuffer_clear(true, true, false, clearcol, 1.0f);
-							stl->g_data->session_flag = GP_DRW_PAINT_FILLING;
-						}
-						/* repeat pass to fill temp texture */
-						DRW_draw_pass(psl->mix_pass);
-						/* set default framebuffer again */
-						DRW_framebuffer_bind(dfbl->default_fb);
-					}
-
+					/* prepare for fast drawing */
+					gpencil_prepare_fast_drawing(stl, dfbl, fbl, psl->mix_pass, clearcol);
 				}
 			}
 			/* edit points */
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 0dca927b77b..56fa0680983 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -197,10 +197,11 @@ typedef struct g_data {
 } g_data; /* Transient data */
 
 typedef enum eGPsession_Flag {
-	GP_DRW_PAINT_IDLE    = (1 << 0),
-	GP_DRW_PAINT_DIRTY   = (1 << 1),
-	GP_DRW_PAINT_FILLING = (1 << 2),
-	GP_DRW_PAINT_READY   = (1 << 3),
+	GP_DRW_PAINT_HOLD     = (1 << 0),
+	GP_DRW_PAINT_IDLE     = (1 << 1),
+	GP_DRW_PAINT_FILLING  = (1 << 2),
+	GP_DRW_PAINT_READY    = (1 << 3),
+	GP_DRW_PAINT_PAINTING = (1 << 4),
 } eGPsession_Flag;
 
 typedef struct GPENCIL_e_data {



More information about the Bf-blender-cvs mailing list