GPencil: Rename BKE_gpencil_visible_stroke_iter

Renamed to  BKE_gpencil_visible_stroke_advanced_iter

Also created a simple version of the iterator to be used without multiframe and onion skin.
This commit is contained in:
Antonio Vazquez 2021-07-06 22:18:49 +02:00
parent 4a24c6fe37
commit f49f406f67
6 changed files with 79 additions and 35 deletions

View File

@ -282,20 +282,25 @@ bool BKE_gpencil_from_image(struct SpaceImage *sima,
const float size,
const bool mask);
/* Iterator */
/* Iterators */
/* frame & stroke are NULL if it is a layer callback. */
typedef void (*gpIterCb)(struct bGPDlayer *layer,
struct bGPDframe *frame,
struct bGPDstroke *stroke,
void *thunk);
void BKE_gpencil_visible_stroke_iter(struct ViewLayer *view_layer,
struct Object *ob,
void BKE_gpencil_visible_stroke_iter(struct bGPdata *gpd,
gpIterCb layer_cb,
gpIterCb stroke_cb,
void *thunk,
bool do_onion,
int cfra);
void *thunk);
void BKE_gpencil_visible_stroke_advanced_iter(struct ViewLayer *view_layer,
struct Object *ob,
gpIterCb layer_cb,
gpIterCb stroke_cb,
void *thunk,
bool do_onion,
int cfra);
extern void (*BKE_gpencil_batch_cache_dirty_tag_cb)(struct bGPdata *gpd);
extern void (*BKE_gpencil_batch_cache_free_cb)(struct bGPdata *gpd);

View File

@ -2694,19 +2694,57 @@ static bool gpencil_is_layer_mask(ViewLayer *view_layer, bGPdata *gpd, bGPDlayer
}
/* -------------------------------------------------------------------- */
/** \name Iterators
/** \name Iterator
*
* Iterate over all visible stroke of all visible layers inside a grease pencil datablock.
* \{ */
void BKE_gpencil_visible_stroke_iter(bGPdata *gpd,
gpIterCb layer_cb,
gpIterCb stroke_cb,
void *thunk)
{
LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
if (gpl->flag & GP_LAYER_HIDE) {
continue;
}
/* If scale to 0 the layer must be invisible. */
if (is_zero_v3(gpl->scale)) {
continue;
}
bGPDframe *act_gpf = gpl->actframe;
if (layer_cb) {
layer_cb(gpl, act_gpf, NULL, thunk);
}
if (act_gpf) {
LISTBASE_FOREACH (bGPDstroke *, gps, &act_gpf->strokes) {
if (gps->totpoints == 0) {
continue;
}
stroke_cb(gpl, act_gpf, gps, thunk);
}
}
}
}
/* -------------------------------------------------------------------- */
/** \name Advanced Iterator
*
* Iterate over all visible stroke of all visible layers inside a gpObject.
* Also take into account onion-skinning.
* \{ */
void BKE_gpencil_visible_stroke_iter(ViewLayer *view_layer,
Object *ob,
gpIterCb layer_cb,
gpIterCb stroke_cb,
void *thunk,
bool do_onion,
int cfra)
void BKE_gpencil_visible_stroke_advanced_iter(ViewLayer *view_layer,
Object *ob,
gpIterCb layer_cb,
gpIterCb stroke_cb,
void *thunk,
bool do_onion,
int cfra)
{
bGPdata *gpd = (bGPdata *)ob->data;
const bool is_multiedit = ((GPENCIL_MULTIEDIT_SESSIONS_ON(gpd)) && (!GPENCIL_PLAY_ON(gpd)));

View File

@ -640,13 +640,13 @@ void GPENCIL_cache_populate(void *ved, Object *ob)
}
}
BKE_gpencil_visible_stroke_iter(is_final_render ? pd->view_layer : NULL,
ob,
gpencil_layer_cache_populate,
gpencil_stroke_cache_populate,
&iter,
do_onion,
pd->cfra);
BKE_gpencil_visible_stroke_advanced_iter(is_final_render ? pd->view_layer : NULL,
ob,
gpencil_layer_cache_populate,
gpencil_stroke_cache_populate,
&iter,
do_onion,
pd->cfra);
gpencil_drawcall_flush(&iter);

View File

@ -431,7 +431,7 @@ static void OVERLAY_gpencil_color_names(Object *ob)
const DRWContextState *draw_ctx = DRW_context_state_get();
int cfra = DEG_get_ctime(draw_ctx->depsgraph);
BKE_gpencil_visible_stroke_iter(
BKE_gpencil_visible_stroke_advanced_iter(
NULL, ob, NULL, overlay_gpencil_draw_stroke_color_name, ob, false, cfra);
}

View File

@ -263,13 +263,13 @@ static void OVERLAY_outline_gpencil(OVERLAY_PrivateData *pd, Object *ob)
gpencil_depth_plane(ob, iter.plane);
}
BKE_gpencil_visible_stroke_iter(NULL,
ob,
gpencil_layer_cache_populate,
gpencil_stroke_cache_populate,
&iter,
false,
pd->cfra);
BKE_gpencil_visible_stroke_advanced_iter(NULL,
ob,
gpencil_layer_cache_populate,
gpencil_stroke_cache_populate,
&iter,
false,
pd->cfra);
}
static void OVERLAY_outline_volume(OVERLAY_PrivateData *pd, Object *ob)

View File

@ -422,7 +422,7 @@ static void gpencil_batches_ensure(Object *ob, GpencilBatchCache *cache, int cfr
.tri_len = 0,
.curve_len = 0,
};
BKE_gpencil_visible_stroke_iter(
BKE_gpencil_visible_stroke_advanced_iter(
NULL, ob, NULL, gpencil_object_verts_count_cb, &iter, do_onion, cfra);
/* Create VBOs. */
@ -439,7 +439,8 @@ static void gpencil_batches_ensure(Object *ob, GpencilBatchCache *cache, int cfr
GPU_indexbuf_init(&iter.ibo, GPU_PRIM_TRIS, iter.tri_len, iter.vert_len);
/* Fill buffers with data. */
BKE_gpencil_visible_stroke_iter(NULL, ob, NULL, gpencil_stroke_iter_cb, &iter, do_onion, cfra);
BKE_gpencil_visible_stroke_advanced_iter(
NULL, ob, NULL, gpencil_stroke_iter_cb, &iter, do_onion, cfra);
/* Mark last 2 verts as invalid. */
for (int i = 0; i < 2; i++) {
@ -514,7 +515,7 @@ GPUBatch *DRW_cache_gpencil_face_wireframe_get(Object *ob)
/* IMPORTANT: Keep in sync with gpencil_edit_batches_ensure() */
bool do_onion = true;
BKE_gpencil_visible_stroke_iter(
BKE_gpencil_visible_stroke_advanced_iter(
NULL, ob, NULL, gpencil_lines_indices_cb, &iter, do_onion, cfra);
GPUIndexBuf *ibo = GPU_indexbuf_build(&iter.ibo);
@ -856,7 +857,7 @@ static void gpencil_edit_batches_ensure(Object *ob, GpencilBatchCache *cache, in
iter.verts = (gpEditVert *)GPU_vertbuf_get_data(cache->edit_vbo);
/* Fill buffers with data. */
BKE_gpencil_visible_stroke_iter(
BKE_gpencil_visible_stroke_advanced_iter(
NULL, ob, NULL, gpencil_edit_stroke_iter_cb, &iter, do_onion, cfra);
/* Create the batches */
@ -883,7 +884,7 @@ static void gpencil_edit_batches_ensure(Object *ob, GpencilBatchCache *cache, in
cache->edit_curve_vbo = GPU_vertbuf_create_with_format(format);
/* Count data. */
BKE_gpencil_visible_stroke_iter(
BKE_gpencil_visible_stroke_advanced_iter(
NULL, ob, NULL, gpencil_edit_curve_stroke_count_cb, &iterdata, false, cfra);
gpEditCurveIterData iter;
@ -894,7 +895,7 @@ static void gpencil_edit_batches_ensure(Object *ob, GpencilBatchCache *cache, in
iter.verts = (gpEditCurveVert *)GPU_vertbuf_get_data(cache->edit_curve_vbo);
/* Fill buffers with data. */
BKE_gpencil_visible_stroke_iter(
BKE_gpencil_visible_stroke_advanced_iter(
NULL, ob, NULL, gpencil_edit_curve_stroke_iter_cb, &iter, false, cfra);
cache->edit_curve_handles_batch = GPU_batch_create(