[Bf-blender-cvs] [dd65302175b] greasepencil-experimental: GPencil: Move modifiers evaluation to Depsgraph (wip)
Antonioya
noreply at git.blender.org
Wed May 8 20:26:29 CEST 2019
Commit: dd65302175b5522caa8f3d3d6570bc294533b7d9
Author: Antonioya
Date: Wed May 8 17:14:36 2019 +0200
Branches: greasepencil-experimental
https://developer.blender.org/rBdd65302175b5522caa8f3d3d6570bc294533b7d9
GPencil: Move modifiers evaluation to Depsgraph (wip)
This changes move the evaluation functions from Draw Manager to Depsgraph evaluation.
===================================================================
M source/blender/blenkernel/BKE_gpencil.h
M source/blender/blenkernel/BKE_gpencil_modifier.h
M source/blender/blenkernel/intern/gpencil.c
M source/blender/blenkernel/intern/gpencil_modifier.c
M source/blender/blenkernel/intern/object_update.c
M source/blender/draw/engines/gpencil/gpencil_cache_utils.c
M source/blender/draw/engines/gpencil/gpencil_draw_utils.c
M source/blender/draw/engines/gpencil/gpencil_engine.h
M source/blender/editors/gpencil/gpencil_intern.h
M source/blender/makesdna/DNA_object_types.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 7d1d30cf07f..3c84c991019 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -54,6 +54,23 @@ struct GPUVertBuf;
struct GPUVertFormat;
struct GpencilBatchGroup;
+#define GP_SIMPLIFY(scene) ((scene->r.simplify_gpencil & SIMPLIFY_GPENCIL_ENABLE))
+#define GP_SIMPLIFY_ONPLAY(playing) \
+ (((playing == true) && (scene->r.simplify_gpencil & SIMPLIFY_GPENCIL_ON_PLAY)) || \
+ ((scene->r.simplify_gpencil & SIMPLIFY_GPENCIL_ON_PLAY) == 0))
+#define GP_SIMPLIFY_FILL(scene, playing) \
+ ((GP_SIMPLIFY_ONPLAY(playing) && (GP_SIMPLIFY(scene)) && \
+ (scene->r.simplify_gpencil & SIMPLIFY_GPENCIL_FILL)))
+#define GP_SIMPLIFY_MODIF(scene, playing) \
+ ((GP_SIMPLIFY_ONPLAY(playing) && (GP_SIMPLIFY(scene)) && \
+ (scene->r.simplify_gpencil & SIMPLIFY_GPENCIL_MODIFIER)))
+#define GP_SIMPLIFY_FX(scene, playing) \
+ ((GP_SIMPLIFY_ONPLAY(playing) && (GP_SIMPLIFY(scene)) && \
+ (scene->r.simplify_gpencil & SIMPLIFY_GPENCIL_FX)))
+#define GP_SIMPLIFY_BLEND(scene, playing) \
+ ((GP_SIMPLIFY_ONPLAY(playing) && (GP_SIMPLIFY(scene)) && \
+ (scene->r.simplify_gpencil & SIMPLIFY_GPENCIL_BLEND)))
+
/* GPUBatch Cache Element */
typedef struct GpencilBatchCacheElem {
struct GPUBatch *batch;
@@ -106,9 +123,6 @@ typedef struct GpencilBatchCache {
int grp_used; /* total groups in arrays */
int grp_size; /* max size of the array */
struct GpencilBatchGroup *grp_cache; /* array of elements */
-
- int tot_layers;
- struct bGPDframe *derived_array; /* runtime data created by modifiers */
} GpencilBatchCache;
/* ------------ Grease-Pencil API ------------------ */
@@ -285,9 +299,4 @@ float BKE_gpencil_multiframe_falloff_calc(
extern void (*BKE_gpencil_batch_cache_dirty_tag_cb)(struct bGPdata *gpd);
extern void (*BKE_gpencil_batch_cache_free_cb)(struct bGPdata *gpd);
-/* derived data functions */
-struct bGPDframe *BKE_gpencil_derivedframe_get(struct Object *ob,
- struct bGPDlayer *gpl,
- struct bGPDframe *gpf);
-
#endif /* __BKE_GPENCIL_H__ */
diff --git a/source/blender/blenkernel/BKE_gpencil_modifier.h b/source/blender/blenkernel/BKE_gpencil_modifier.h
index 4655abf6e02..63b1f259049 100644
--- a/source/blender/blenkernel/BKE_gpencil_modifier.h
+++ b/source/blender/blenkernel/BKE_gpencil_modifier.h
@@ -325,4 +325,8 @@ int BKE_gpencil_time_modifier(struct Depsgraph *depsgraph,
void BKE_gpencil_lattice_init(struct Object *ob);
void BKE_gpencil_lattice_clear(struct Object *ob);
+void BKE_gpencil_modifiers_calc(struct Depsgraph *depsgraph,
+ struct Scene *scene,
+ struct Object *ob);
+
#endif /* __BKE_GPENCIL_MODIFIER_H__ */
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 68173f34a2e..439005ca1b4 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1971,23 +1971,3 @@ bool BKE_gpencil_trim_stroke(bGPDstroke *gps)
}
return intersect;
}
-
-/** Get derived frame with modifiers applied */
-bGPDframe *BKE_gpencil_derivedframe_get(Object *ob, bGPDlayer *gpl, bGPDframe *gpf)
-{
- GpencilBatchCache *cache = ob->runtime.gpencil_cache;
- bGPdata *gpd = (bGPdata *)ob->data;
- if (cache == NULL) {
- return gpf;
- }
- int derived_idx = BLI_findindex(&gpd->layers, gpl);
-
- /* if not derived data return original data */
- if (derived_idx < 0) {
- return gpf;
- }
-
- bGPDframe *derived_gpf = &cache->derived_array[derived_idx];
-
- return derived_gpf;
-}
diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c b/source/blender/blenkernel/intern/gpencil_modifier.c
index c8a45a92758..07e6d274c7f 100644
--- a/source/blender/blenkernel/intern/gpencil_modifier.c
+++ b/source/blender/blenkernel/intern/gpencil_modifier.c
@@ -848,3 +848,126 @@ void BKE_gpencil_subdivide(bGPDstroke *gps, int level, int flag)
}
}
}
+
+/* Copy frame but do not assign new memory */
+static void gpencil_copy_frame(bGPDframe *gpf, bGPDframe *derived_gpf)
+{
+ derived_gpf->prev = gpf->prev;
+ derived_gpf->next = gpf->next;
+ derived_gpf->framenum = gpf->framenum;
+ derived_gpf->flag = gpf->flag;
+ derived_gpf->key_type = gpf->key_type;
+ derived_gpf->runtime = gpf->runtime;
+ copy_m4_m4(derived_gpf->runtime.viewmatrix, gpf->runtime.viewmatrix);
+
+ /* copy strokes */
+ BLI_listbase_clear(&derived_gpf->strokes);
+ for (bGPDstroke *gps_src = gpf->strokes.first; gps_src; gps_src = gps_src->next) {
+ /* make copy of source stroke */
+ bGPDstroke *gps_dst = BKE_gpencil_stroke_duplicate(gps_src);
+
+ /* Save original pointers for using in edit and select operators. */
+ gps_dst->runtime.gps_orig = gps_src;
+ bGPDspoint *pt_src = gps_src->points;
+ bGPDspoint *pt_dst = gps_dst->points;
+ for (int i = 0; i < gps_src->totpoints; i++, pt_dst++, pt_src++) {
+ pt_dst->runtime.pt_orig = pt_src;
+ }
+
+ BLI_addtail(&derived_gpf->strokes, gps_dst);
+ }
+}
+
+/* Ensure there is a derived frame */
+static void gpencil_ensure_derived_frame(
+ int idx, Object *ob, bGPDlayer *gpl, bGPDframe *gpf, bGPDframe **derived_gpf)
+{
+ /* create derived frames array data or expand */
+ bGPDframe *derived_frames = ob->runtime.derived_frames;
+ *derived_gpf = &derived_frames[idx];
+
+ /* if derived frame create a new one */
+ if (*derived_gpf != NULL) {
+ /* first clear temp data */
+ BKE_gpencil_free_frame_runtime_data(*derived_gpf);
+ }
+ /* copy data (do not assign new memory)*/
+ gpencil_copy_frame(gpf, *derived_gpf);
+}
+
+/* Calculate gpencil modifiers */
+void BKE_gpencil_modifiers_calc(Depsgraph *depsgraph, Scene *scene, Object *ob)
+{
+ /* use original data to set reference pointers to original data */
+ Object *ob_orig = DEG_get_original_object(ob);
+ bGPdata *gpd = (bGPdata *)ob_orig->data;
+ const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
+ const bool simplify_modif = GP_SIMPLIFY_MODIF(scene, false);
+ const bool is_render = (bool)(DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
+ const bool time_remap = BKE_gpencil_has_time_modifiers(ob);
+ int cfra_eval = (int)DEG_get_ctime(depsgraph);
+
+ /* Create array of derived frames equal to number of layers. */
+ ob->runtime.tot_layers = BLI_listbase_count(&gpd->layers);
+ CLAMP_MIN(ob->runtime.tot_layers, 1);
+ if (ob->runtime.derived_frames == NULL) {
+ ob->runtime.derived_frames = MEM_callocN(sizeof(struct bGPDframe) * ob->runtime.tot_layers,
+ __func__);
+ }
+ else {
+ ob->runtime.derived_frames = MEM_reallocN(ob->runtime.derived_frames,
+ sizeof(struct bGPDframe) * ob->runtime.tot_layers);
+ }
+
+ /* Init general modifiers data. */
+ if (ob->greasepencil_modifiers.first) {
+ BKE_gpencil_lattice_init(ob);
+ }
+
+ /* *****************************************************************
+ * Loop all layers, duplicate data and apply modifiers.
+ *
+ * ******************************************************************/
+ int idx = 0;
+ for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+ /* Remap frame (Time modifier) */
+ int remap_cfra = cfra_eval;
+ if ((time_remap) && (!simplify_modif)) {
+ remap_cfra = BKE_gpencil_time_modifier(depsgraph, scene, ob, gpl, cfra_eval, is_render);
+ }
+ bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, remap_cfra, GP_GETFRAME_USE_PREV);
+
+ if (gpf == NULL) {
+ idx++;
+ continue;
+ }
+
+ /* Create a duplicate data set of stroke to modify. */
+ bGPDframe *derived_gpf = NULL;
+ gpencil_ensure_derived_frame(idx, ob, gpl, gpf, &derived_gpf);
+
+ /* Skip all if some disable flag is enabled. */
+ if ((ob->greasepencil_modifiers.first == NULL) || (is_multiedit) || (simplify_modif)) {
+ idx++;
+ continue;
+ }
+
+ /* Apply geometry modifiers (create new geometry). */
+ if (BKE_gpencil_has_geometry_modifiers(ob)) {
+ BKE_gpencil_geometry_modifiers(depsgraph, ob, gpl, derived_gpf, is_render);
+ }
+
+ /* Loop all strokes and deform them. */
+ for (bGPDstroke *gps = derived_gpf->strokes.first; gps; gps = gps->next) {
+ /* Apply modifiers that only deform geometry */
+ BKE_gpencil_stroke_modifiers(depsgraph, ob, gpl, derived_gpf, gps, is_render);
+ }
+
+ idx++;
+ }
+
+ /* Clear any lattice data. */
+ if (ob->greasepencil_modifiers.first) {
+ BKE_gpencil_lattice_clear(ob);
+ }
+}
diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c
index 183bc968897..0e6f3380f4d 100644
--- a/source/blender/blenkernel/intern/object_update.c
+++ b/source/blender/blenkernel/intern/object_update.c
@@ -42,6 +42,7 @@
#include "BKE_displist.h"
#include "BKE_editmesh.h"
#include "BKE_effect.h"
+#include "BKE_gpencil_modifier.h"
#include "BKE_image.h"
#include "BKE_key.h"
#include "BKE_layer.h"
@@ -209,6 +210,9 @@ void BKE_object_handle_data_update(Depsgraph *depsgraph, Scene *scene, Object *o
case OB_LATTICE:
BKE_lattice_modifiers_calc(depsgraph, scene, ob);
break;
+ case OB_GPENCIL:
+ BKE_gpencil_modifiers_calc(depsgraph, scene, ob);
+ break;
}
/* particles */
diff --git a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
index 9b833a99d30..b0608343ab3 100644
--- a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
@@ -274,11 +274,6 @@ static GpencilBatchCache *gpencil_batch_cache_init(Object *ob, int cfra)
cache->cache_frame = cfra;
- /* create array of derived frames equal to number of layers */
- cache->tot_layers = BLI_listbase_count(&gpd->layers);
- CLAMP_MIN(cache->tot_layers, 1);
- cache->derived_array = MEM_callocN(sizeof(struct bGPDframe) * cache->tot_layers, "Derived GPF");
-
return cache;
}
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list