Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonioya <blendergit@gmail.com>2018-10-19 21:39:21 +0300
committerAntonioya <blendergit@gmail.com>2018-10-20 10:08:34 +0300
commit541d07045b79cef52bdcf8bd1d90fc60793c9872 (patch)
treec8fcaaf79ce0d3a0cea526338e65d63a6de6048f /source/blender/blenkernel/intern/gpencil.c
parentb634bf9fb64930e0073c17bc115b6c3436b9a8e2 (diff)
GP: Redesign drawing cache to support particles
Full redesign of the cache system used for drawing strokes and handle derived frame data. Before, the cache was saved in bGPdata and a hash was used to manage several objects with the same datablock. Old design made the use of particles very inefficient and prone to bugs and segment faults, and especially when this was mixed with onion skinning and multiple objects using same datablock. Also, there were some conflicts with the depsgrah logic (the old design was done before despgraph was in place) that made the use of hash not working. The new design saves the data in the object runtime struct and avoid the use of any hash to find the right data. This improves the speed and reduce a lot the complexity of the code, memory allocation, hash overload and adds full support for particles and reused datablocks. The particles can reuse the modifiers and shader effects of the original grease pencil object.
Diffstat (limited to 'source/blender/blenkernel/intern/gpencil.c')
-rw-r--r--source/blender/blenkernel/intern/gpencil.c39
1 files changed, 9 insertions, 30 deletions
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 33c2587e800..97aed40e998 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -169,8 +169,6 @@ bool BKE_gpencil_free_frame_runtime_data(bGPDframe *derived_gpf)
}
BLI_listbase_clear(&derived_gpf->strokes);
- MEM_SAFE_FREE(derived_gpf);
-
return true;
}
@@ -216,18 +214,17 @@ void BKE_gpencil_free_layers(ListBase *list)
/* clear all runtime derived data */
static void BKE_gpencil_clear_derived(bGPDlayer *gpl)
{
- GHashIterator gh_iter;
-
- if (gpl->runtime.derived_data == NULL) {
+ if (gpl->runtime.derived_array == NULL) {
return;
}
- GHASH_ITER(gh_iter, gpl->runtime.derived_data) {
- bGPDframe *gpf = (bGPDframe *)BLI_ghashIterator_getValue(&gh_iter);
- if (gpf) {
- BKE_gpencil_free_frame_runtime_data(gpf);
- }
+ for (int i = 0; i < gpl->runtime.len_derived; i++) {
+ bGPDframe *derived_gpf = &gpl->runtime.derived_array[i];
+ BKE_gpencil_free_frame_runtime_data(derived_gpf);
+ derived_gpf = NULL;
}
+ gpl->runtime.len_derived = 0;
+ MEM_SAFE_FREE(gpl->runtime.derived_array);
}
/* Free all of the gp-layers temp data*/
@@ -241,11 +238,6 @@ static void BKE_gpencil_free_layers_temp_data(ListBase *list)
for (bGPDlayer *gpl = list->first; gpl; gpl = gpl_next) {
gpl_next = gpl->next;
BKE_gpencil_clear_derived(gpl);
-
- if (gpl->runtime.derived_data) {
- BLI_ghash_free(gpl->runtime.derived_data, NULL, NULL);
- gpl->runtime.derived_data = NULL;
- }
}
}
@@ -256,11 +248,6 @@ void BKE_gpencil_free_derived_frames(bGPdata *gpd)
if (gpd == NULL) return;
for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
BKE_gpencil_clear_derived(gpl);
-
- if (gpl->runtime.derived_data) {
- BLI_ghash_free(gpl->runtime.derived_data, NULL, NULL);
- gpl->runtime.derived_data = NULL;
- }
}
}
@@ -464,7 +451,6 @@ bGPdata *BKE_gpencil_data_addnew(Main *bmain, const char name[])
ARRAY_SET_ITEMS(gpd->line_color, 0.6f, 0.6f, 0.6f, 0.5f);
gpd->xray_mode = GP_XRAY_3DSPACE;
- gpd->runtime.batch_cache_data = NULL;
gpd->pixfactor = GP_DEFAULT_PIX_FACTOR;
/* grid settings */
@@ -645,7 +631,8 @@ bGPDlayer *BKE_gpencil_layer_duplicate(const bGPDlayer *gpl_src)
/* make a copy of source layer */
gpl_dst = MEM_dupallocN(gpl_src);
gpl_dst->prev = gpl_dst->next = NULL;
- gpl_dst->runtime.derived_data = NULL;
+ gpl_dst->runtime.derived_array = NULL;
+ gpl_dst->runtime.len_derived = 0;
/* copy frames */
BLI_listbase_clear(&gpl_dst->frames);
@@ -673,9 +660,6 @@ bGPDlayer *BKE_gpencil_layer_duplicate(const bGPDlayer *gpl_src)
*/
void BKE_gpencil_copy_data(bGPdata *gpd_dst, const bGPdata *gpd_src, const int UNUSED(flag))
{
- /* cache data is not duplicated */
- gpd_dst->runtime.batch_cache_data = NULL;
-
/* duplicate material array */
if (gpd_src->mat) {
gpd_dst->mat = MEM_dupallocN(gpd_src->mat);
@@ -721,7 +705,6 @@ bGPdata *BKE_gpencil_data_duplicate(Main *bmain, const bGPdata *gpd_src, bool in
else {
BLI_assert(bmain != NULL);
BKE_id_copy_ex(bmain, &gpd_src->id, (ID **)&gpd_dst, 0, false);
- gpd_dst->runtime.batch_cache_data = NULL;
}
/* Copy internal data (layers, etc.) */
@@ -1035,10 +1018,6 @@ void BKE_gpencil_layer_delete(bGPdata *gpd, bGPDlayer *gpl)
/* free derived data */
BKE_gpencil_clear_derived(gpl);
- if (gpl->runtime.derived_data) {
- BLI_ghash_free(gpl->runtime.derived_data, NULL, NULL);
- gpl->runtime.derived_data = NULL;
- }
BLI_freelinkN(&gpd->layers, gpl);
}