[Bf-blender-cvs] [6155faf5bda] master: GP: Check if Instance loop is needed

Antonioya noreply at git.blender.org
Wed Feb 27 08:41:30 CET 2019


Commit: 6155faf5bda861c929dbebaf022199580c64d2fe
Author: Antonioya
Date:   Wed Feb 27 08:41:13 2019 +0100
Branches: master
https://developer.blender.org/rB6155faf5bda861c929dbebaf022199580c64d2fe

GP: Check if Instance loop is needed

This reduces the loop time if the scene is not using instances.

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

M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 6df1ae4b873..49c0d5fe8b4 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -330,6 +330,7 @@ void GPENCIL_cache_init(void *vedata)
 	stl->g_data->gp_cache_used = 0;
 	stl->g_data->gp_cache_size = 0;
 	stl->g_data->gp_object_cache = NULL;
+	stl->g_data->do_instances = false;
 
 	{
 		/* Stroke pass 2D */
@@ -594,6 +595,11 @@ void GPENCIL_cache_populate(void *vedata, Object *ob)
 				stl->g_data->gp_object_cache, ob,
 				&stl->g_data->gp_cache_size, &stl->g_data->gp_cache_used);
 
+			/* enable instance loop */
+			if (!stl->g_data->do_instances) {
+				stl->g_data->do_instances = ob->base_flag & BASE_FROM_DUPLI;
+			}
+
 			/* load drawing data */
 			gpencil_add_draw_data(vedata, ob);
 		}
@@ -642,21 +648,24 @@ void GPENCIL_cache_finish(void *vedata)
 	tGPencilObjectCache *cache_ob = NULL;
 	Object *ob = NULL;
 
-	GHash *gh_objects = BLI_ghash_str_new(__func__);
-	/* create hash of real object (non duplicated) */
-	for (int i = 0; i < stl->g_data->gp_cache_used; i++) {
-		cache_ob = &stl->g_data->gp_object_cache[i];
-		if (!cache_ob->is_dup_ob) {
-			ob = cache_ob->ob;
-			BLI_ghash_insert(gh_objects, ob->id.name, cache_ob->ob);
+	/* create data for instances */
+	if (stl->g_data->do_instances) {
+		GHash *gh_objects = BLI_ghash_str_new(__func__);
+		/* create hash of real object (non duplicated) */
+		for (int i = 0; i < stl->g_data->gp_cache_used; i++) {
+			cache_ob = &stl->g_data->gp_object_cache[i];
+			if (!cache_ob->is_dup_ob) {
+				ob = cache_ob->ob;
+				BLI_ghash_insert(gh_objects, ob->id.name, cache_ob->ob);
+			}
 		}
-	}
 
-	/* draw particles */
-	DRW_gpencil_populate_particles(&e_data, gh_objects, vedata);
+		/* draw particles */
+		DRW_gpencil_populate_particles(&e_data, gh_objects, vedata);
 
-	/* free hash */
-	BLI_ghash_free(gh_objects, NULL, NULL);
+		/* free hash */
+		BLI_ghash_free(gh_objects, NULL, NULL);
+	}
 
 	if (stl->g_data->session_flag & (GP_DRW_PAINT_IDLE | GP_DRW_PAINT_FILLING)) {
 		stl->storage->framebuffer_flag |= GP_FRAMEBUFFER_DRAW;
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 7032c816c5f..2922f51e8cb 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -246,6 +246,7 @@ typedef struct g_data {
 	struct tGPencilObjectCache *gp_object_cache;
 
 	int session_flag;
+	bool do_instances;
 
 } g_data; /* Transient data */



More information about the Bf-blender-cvs mailing list