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:
Diffstat (limited to 'source/blender/editors/gpencil')
-rw-r--r--source/blender/editors/gpencil/annotate_draw.c2
-rw-r--r--source/blender/editors/gpencil/annotate_paint.c95
-rw-r--r--source/blender/editors/gpencil/drawgpencil.c3
-rw-r--r--source/blender/editors/gpencil/gpencil_add_monkey.c7
-rw-r--r--source/blender/editors/gpencil/gpencil_add_stroke.c7
-rw-r--r--source/blender/editors/gpencil/gpencil_armature.c2
-rw-r--r--source/blender/editors/gpencil/gpencil_brush.c44
-rw-r--r--source/blender/editors/gpencil/gpencil_convert.c47
-rw-r--r--source/blender/editors/gpencil/gpencil_data.c9
-rw-r--r--source/blender/editors/gpencil/gpencil_edit.c71
-rw-r--r--source/blender/editors/gpencil/gpencil_fill.c20
-rw-r--r--source/blender/editors/gpencil/gpencil_intern.h8
-rw-r--r--source/blender/editors/gpencil/gpencil_interpolate.c12
-rw-r--r--source/blender/editors/gpencil/gpencil_merge.c5
-rw-r--r--source/blender/editors/gpencil/gpencil_ops.c8
-rw-r--r--source/blender/editors/gpencil/gpencil_paint.c118
-rw-r--r--source/blender/editors/gpencil/gpencil_primitive.c38
-rw-r--r--source/blender/editors/gpencil/gpencil_select.c13
-rw-r--r--source/blender/editors/gpencil/gpencil_utils.c47
19 files changed, 274 insertions, 282 deletions
diff --git a/source/blender/editors/gpencil/annotate_draw.c b/source/blender/editors/gpencil/annotate_draw.c
index e8f97290173..dce6ed29c05 100644
--- a/source/blender/editors/gpencil/annotate_draw.c
+++ b/source/blender/editors/gpencil/annotate_draw.c
@@ -924,7 +924,7 @@ static void annotation_draw_data_layers(
* i.e. tGPspoints NOT bGPDspoints
*/
annotation_draw_stroke_buffer(gpd->runtime.sbuffer,
- gpd->runtime.sbuffer_size,
+ gpd->runtime.sbuffer_used,
lthick,
dflag,
gpd->runtime.sbuffer_sflag,
diff --git a/source/blender/editors/gpencil/annotate_paint.c b/source/blender/editors/gpencil/annotate_paint.c
index 5962d95c5af..e59e5d6a878 100644
--- a/source/blender/editors/gpencil/annotate_paint.c
+++ b/source/blender/editors/gpencil/annotate_paint.c
@@ -281,7 +281,7 @@ static bool gp_stroke_filtermval(tGPsdata *p, const float mval[2], float pmval[2
int dy = (int)fabsf(mval[1] - pmval[1]);
/* if buffer is empty, just let this go through (i.e. so that dots will work) */
- if (p->gpd->runtime.sbuffer_size == 0) {
+ if (p->gpd->runtime.sbuffer_used == 0) {
return true;
/* check if mouse moved at least certain distance on both axes (best case)
@@ -382,7 +382,7 @@ static void gp_stroke_convertcoords(tGPsdata *p, const float mval[2], float out[
static void gp_smooth_buffer(tGPsdata *p, float inf, int idx)
{
bGPdata *gpd = p->gpd;
- short num_points = gpd->runtime.sbuffer_size;
+ short num_points = gpd->runtime.sbuffer_used;
/* Do nothing if not enough points to smooth out */
if ((num_points < 3) || (idx < 3) || (inf == 0.0f)) {
@@ -437,7 +437,7 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
/* check painting mode */
if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) {
/* straight lines only - i.e. only store start and end point in buffer */
- if (gpd->runtime.sbuffer_size == 0) {
+ if (gpd->runtime.sbuffer_used == 0) {
/* first point in buffer (start point) */
pt = (tGPspoint *)(gpd->runtime.sbuffer);
@@ -449,7 +449,7 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
pt->time = (float)(curtime - p->inittime);
/* increment buffer size */
- gpd->runtime.sbuffer_size++;
+ gpd->runtime.sbuffer_used++;
}
else {
/* just reset the endpoint to the latest value
@@ -465,20 +465,19 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
pt->time = (float)(curtime - p->inittime);
/* now the buffer has 2 points (and shouldn't be allowed to get any larger) */
- gpd->runtime.sbuffer_size = 2;
+ gpd->runtime.sbuffer_used = 2;
}
/* can keep carrying on this way :) */
return GP_STROKEADD_NORMAL;
}
else if (p->paintmode == GP_PAINTMODE_DRAW) { /* normal drawing */
- /* check if still room in buffer */
- if (gpd->runtime.sbuffer_size >= GP_STROKE_BUFFER_MAX) {
- return GP_STROKEADD_OVERFLOW;
- }
+ /* check if still room in buffer or add more */
+ gpd->runtime.sbuffer = ED_gpencil_sbuffer_ensure(
+ gpd->runtime.sbuffer, &gpd->runtime.sbuffer_size, &gpd->runtime.sbuffer_used, false);
/* get pointer to destination point */
- pt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_size);
+ pt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_used);
/* store settings */
copy_v2_v2(&pt->x, mval);
@@ -490,19 +489,13 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
pt->time = (float)(curtime - p->inittime);
/* increment counters */
- gpd->runtime.sbuffer_size++;
+ gpd->runtime.sbuffer_used++;
/* smooth while drawing previous points with a reduction factor for previous */
for (int s = 0; s < 3; s++) {
- gp_smooth_buffer(p, 0.5f * ((3.0f - s) / 3.0f), gpd->runtime.sbuffer_size - s);
+ gp_smooth_buffer(p, 0.5f * ((3.0f - s) / 3.0f), gpd->runtime.sbuffer_used - s);
}
- /* check if another operation can still occur */
- if (gpd->runtime.sbuffer_size == GP_STROKE_BUFFER_MAX) {
- return GP_STROKEADD_FULL;
- }
- else {
- return GP_STROKEADD_NORMAL;
- }
+ return GP_STROKEADD_NORMAL;
}
else if (p->paintmode == GP_PAINTMODE_DRAW_POLY) {
/* get pointer to destination point */
@@ -524,7 +517,7 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
bGPDspoint *pts;
/* first time point is adding to temporary buffer -- need to allocate new point in stroke */
- if (gpd->runtime.sbuffer_size == 0) {
+ if (gpd->runtime.sbuffer_used == 0) {
gps->points = MEM_reallocN(gps->points, sizeof(bGPDspoint) * (gps->totpoints + 1));
gps->totpoints++;
}
@@ -557,8 +550,8 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
}
/* increment counters */
- if (gpd->runtime.sbuffer_size == 0) {
- gpd->runtime.sbuffer_size++;
+ if (gpd->runtime.sbuffer_used == 0) {
+ gpd->runtime.sbuffer_used++;
}
return GP_STROKEADD_NORMAL;
@@ -576,7 +569,7 @@ static void gp_stroke_simplify(tGPsdata *p)
{
bGPdata *gpd = p->gpd;
tGPspoint *old_points = (tGPspoint *)gpd->runtime.sbuffer;
- short num_points = gpd->runtime.sbuffer_size;
+ short num_points = gpd->runtime.sbuffer_used;
short flag = gpd->runtime.sbuffer_sflag;
short i, j;
@@ -668,17 +661,17 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
* - drawing straight-lines only requires the endpoints
*/
if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) {
- totelem = (gpd->runtime.sbuffer_size >= 2) ? 2 : gpd->runtime.sbuffer_size;
+ totelem = (gpd->runtime.sbuffer_used >= 2) ? 2 : gpd->runtime.sbuffer_used;
}
else {
- totelem = gpd->runtime.sbuffer_size;
+ totelem = gpd->runtime.sbuffer_used;
}
/* exit with error if no valid points from this stroke */
if (totelem == 0) {
if (G.debug & G_DEBUG) {
printf("Error: No valid points in stroke buffer to convert (tot=%d)\n",
- gpd->runtime.sbuffer_size);
+ gpd->runtime.sbuffer_used);
}
return;
}
@@ -736,7 +729,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
if (totelem == 2) {
/* last point if applicable */
- ptc = ((tGPspoint *)gpd->runtime.sbuffer) + (gpd->runtime.sbuffer_size - 1);
+ ptc = ((tGPspoint *)gpd->runtime.sbuffer) + (gpd->runtime.sbuffer_used - 1);
/* convert screen-coordinates to appropriate coordinates (and store them) */
gp_stroke_convertcoords(p, &ptc->x, &pt->x, NULL);
@@ -769,9 +762,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
int interp_depth = 0;
int found_depth = 0;
- depth_arr = MEM_mallocN(sizeof(float) * gpd->runtime.sbuffer_size, "depth_points");
+ depth_arr = MEM_mallocN(sizeof(float) * gpd->runtime.sbuffer_used, "depth_points");
- for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_size; i++, ptc++, pt++) {
+ for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_used; i++, ptc++, pt++) {
round_v2i_v2fl(mval_i, &ptc->x);
if ((ED_view3d_autodist_depth(p->ar, mval_i, depth_margin, depth_arr + i) == 0) &&
@@ -788,7 +781,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
if (found_depth == false) {
/* eeh... not much we can do.. :/, ignore depth in this case, use the 3D cursor */
- for (i = gpd->runtime.sbuffer_size - 1; i >= 0; i--) {
+ for (i = gpd->runtime.sbuffer_used - 1; i >= 0; i--) {
depth_arr[i] = 0.9999f;
}
}
@@ -798,14 +791,14 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
int first_valid = 0;
int last_valid = 0;
- for (i = 0; i < gpd->runtime.sbuffer_size; i++) {
+ for (i = 0; i < gpd->runtime.sbuffer_used; i++) {
if (depth_arr[i] != FLT_MAX) {
break;
}
}
first_valid = i;
- for (i = gpd->runtime.sbuffer_size - 1; i >= 0; i--) {
+ for (i = gpd->runtime.sbuffer_used - 1; i >= 0; i--) {
if (depth_arr[i] != FLT_MAX) {
break;
}
@@ -821,7 +814,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
}
if (interp_depth) {
- interp_sparse_array(depth_arr, gpd->runtime.sbuffer_size, FLT_MAX);
+ interp_sparse_array(depth_arr, gpd->runtime.sbuffer_used, FLT_MAX);
}
}
}
@@ -829,7 +822,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
pt = gps->points;
/* convert all points (normal behavior) */
- for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_size && ptc;
+ for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_used && ptc;
i++, ptc++, pt++) {
/* convert screen-coordinates to appropriate coordinates (and store them) */
gp_stroke_convertcoords(p, &ptc->x, &pt->x, depth_arr ? depth_arr + i : NULL);
@@ -1049,19 +1042,8 @@ static void gp_session_validatebuffer(tGPsdata *p)
{
bGPdata *gpd = p->gpd;
- /* clear memory of buffer (or allocate it if starting a new session) */
- if (gpd->runtime.sbuffer) {
- /* printf("\t\tGP - reset sbuffer\n"); */
- memset(gpd->runtime.sbuffer, 0, sizeof(tGPspoint) * GP_STROKE_BUFFER_MAX);
- }
- else {
- /* printf("\t\tGP - allocate sbuffer\n"); */
- gpd->runtime.sbuffer = MEM_callocN(sizeof(tGPspoint) * GP_STROKE_BUFFER_MAX,
- "gp_session_strokebuffer");
- }
-
- /* reset indices */
- gpd->runtime.sbuffer_size = 0;
+ gpd->runtime.sbuffer = ED_gpencil_sbuffer_ensure(
+ gpd->runtime.sbuffer, &gpd->runtime.sbuffer_size, &gpd->runtime.sbuffer_used, true);
/* reset flags */
gpd->runtime.sbuffer_sflag = 0;
@@ -1091,7 +1073,7 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p)
/* pass on current scene and window */
p->bmain = CTX_data_main(C);
p->scene = CTX_data_scene(C);
- p->depsgraph = CTX_data_depsgraph(C);
+ p->depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
p->win = CTX_wm_window(C);
unit_m4(p->imat);
@@ -1295,6 +1277,7 @@ static void gp_session_cleanup(tGPsdata *p)
}
/* clear flags */
+ gpd->runtime.sbuffer_used = 0;
gpd->runtime.sbuffer_size = 0;
gpd->runtime.sbuffer_sflag = 0;
p->inittime = 0.0;
@@ -1647,7 +1630,7 @@ static int gpencil_draw_init(bContext *C, wmOperator *op, const wmEvent *event)
}
/* init painting data */
- gp_paint_initstroke(p, paintmode, CTX_data_depsgraph(C));
+ gp_paint_initstroke(p, paintmode, CTX_data_ensure_evaluated_depsgraph(C));
if (p->status == GP_STATUS_ERROR) {
gpencil_draw_exit(C, op);
return 0;
@@ -1920,7 +1903,7 @@ static void annotation_draw_apply_event(
static int gpencil_draw_exec(bContext *C, wmOperator *op)
{
tGPsdata *p = NULL;
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
/* printf("GPencil - Starting Re-Drawing\n"); */
@@ -2074,7 +2057,7 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event
p->status = GP_STATUS_PAINTING;
/* handle the initial drawing - i.e. for just doing a simple dot */
- annotation_draw_apply_event(op, event, CTX_data_depsgraph(C), 0.0f, 0.0f);
+ annotation_draw_apply_event(op, event, CTX_data_ensure_evaluated_depsgraph(C), 0.0f, 0.0f);
op->flag |= OP_IS_MODAL_CURSOR_REGION;
}
else {
@@ -2115,7 +2098,7 @@ static tGPsdata *gpencil_stroke_begin(bContext *C, wmOperator *op)
* it'd be nice to allow changing paint-mode when in sketching-sessions */
if (gp_session_initdata(C, p)) {
- gp_paint_initstroke(p, p->paintmode, CTX_data_depsgraph(C));
+ gp_paint_initstroke(p, p->paintmode, CTX_data_ensure_evaluated_depsgraph(C));
}
if (p->status != GP_STATUS_ERROR) {
@@ -2150,6 +2133,7 @@ static void annotation_add_missing_events(bContext *C,
const wmEvent *event,
tGPsdata *p)
{
+ Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
float pt[2], a[2], b[2];
float factor = 10.0f;
@@ -2165,7 +2149,7 @@ static void annotation_add_missing_events(bContext *C,
interp_v2_v2v2(pt, a, b, 0.5f);
sub_v2_v2v2(pt, b, pt);
/* create fake event */
- annotation_draw_apply_event(op, event, CTX_data_depsgraph(C), pt[0], pt[1]);
+ annotation_draw_apply_event(op, event, depsgraph, pt[0], pt[1]);
}
else if (dist >= factor) {
int slices = 2 + (int)((dist - 1.0) / factor);
@@ -2174,7 +2158,7 @@ static void annotation_add_missing_events(bContext *C,
interp_v2_v2v2(pt, a, b, n * i);
sub_v2_v2v2(pt, b, pt);
/* create fake event */
- annotation_draw_apply_event(op, event, CTX_data_depsgraph(C), pt[0], pt[1]);
+ annotation_draw_apply_event(op, event, depsgraph, pt[0], pt[1]);
}
}
}
@@ -2404,7 +2388,8 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
annotation_add_missing_events(C, op, event, p);
}
- annotation_draw_apply_event(op, event, CTX_data_depsgraph(C), 0.0f, 0.0f);
+ /* TODO(sergey): Possibly evaluating dependency graph from modal operator? */
+ annotation_draw_apply_event(op, event, CTX_data_ensure_evaluated_depsgraph(C), 0.0f, 0.0f);
/* finish painting operation if anything went wrong just now */
if (p->status == GP_STATUS_ERROR) {
diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index 809acc3b322..0c2af982279 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -1117,7 +1117,8 @@ void ED_gp_draw_interpolation(const bContext *C, tGPDinterpolate *tgpi, const in
RegionView3D *rv3d = ar->regiondata;
tGPDinterpolate_layer *tgpil;
Object *obact = CTX_data_active_object(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ /* Drawing code is expected to run with fully evaluated depsgraph. */
+ Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C);
float color[4];
diff --git a/source/blender/editors/gpencil/gpencil_add_monkey.c b/source/blender/editors/gpencil/gpencil_add_monkey.c
index 4d62d169bf8..c4528518009 100644
--- a/source/blender/editors/gpencil/gpencil_add_monkey.c
+++ b/source/blender/editors/gpencil/gpencil_add_monkey.c
@@ -829,8 +829,7 @@ static const ColorTemplate gp_monkey_pct_pupils = {
void ED_gpencil_create_monkey(bContext *C, Object *ob, float mat[4][4])
{
Main *bmain = CTX_data_main(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
- int cfra_eval = (int)DEG_get_ctime(depsgraph);
+ Scene *scene = CTX_data_scene(C);
bGPdata *gpd = (bGPdata *)ob->data;
bGPDstroke *gps;
@@ -852,8 +851,8 @@ void ED_gpencil_create_monkey(bContext *C, Object *ob, float mat[4][4])
/* frames */
/* NOTE: No need to check for existing, as this will take care of it for us */
- bGPDframe *frameFills = BKE_gpencil_frame_addnew(Fills, cfra_eval);
- bGPDframe *frameLines = BKE_gpencil_frame_addnew(Lines, cfra_eval);
+ bGPDframe *frameFills = BKE_gpencil_frame_addnew(Fills, CFRA);
+ bGPDframe *frameLines = BKE_gpencil_frame_addnew(Lines, CFRA);
/* generate strokes */
gps = BKE_gpencil_add_stroke(frameFills, color_Skin, 270, 75);
diff --git a/source/blender/editors/gpencil/gpencil_add_stroke.c b/source/blender/editors/gpencil/gpencil_add_stroke.c
index f6ff5ed4f13..80e239c9ae5 100644
--- a/source/blender/editors/gpencil/gpencil_add_stroke.c
+++ b/source/blender/editors/gpencil/gpencil_add_stroke.c
@@ -215,8 +215,7 @@ static const ColorTemplate gp_stroke_material_grey = {
void ED_gpencil_create_stroke(bContext *C, Object *ob, float mat[4][4])
{
Main *bmain = CTX_data_main(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
- int cfra_eval = (int)DEG_get_ctime(depsgraph);
+ Scene *scene = CTX_data_scene(C);
bGPdata *gpd = (bGPdata *)ob->data;
bGPDstroke *gps;
@@ -236,8 +235,8 @@ void ED_gpencil_create_stroke(bContext *C, Object *ob, float mat[4][4])
bGPDlayer *lines = BKE_gpencil_layer_addnew(gpd, "Lines", true);
/* frames */
- bGPDframe *frame_color = BKE_gpencil_frame_addnew(colors, cfra_eval);
- bGPDframe *frame_lines = BKE_gpencil_frame_addnew(lines, cfra_eval);
+ bGPDframe *frame_color = BKE_gpencil_frame_addnew(colors, CFRA);
+ bGPDframe *frame_lines = BKE_gpencil_frame_addnew(lines, CFRA);
UNUSED_VARS(frame_color);
/* generate stroke */
diff --git a/source/blender/editors/gpencil/gpencil_armature.c b/source/blender/editors/gpencil/gpencil_armature.c
index 08f752bb72e..9e70be323eb 100644
--- a/source/blender/editors/gpencil/gpencil_armature.c
+++ b/source/blender/editors/gpencil/gpencil_armature.c
@@ -554,7 +554,7 @@ static bool gpencil_generate_weights_poll(bContext *C)
static int gpencil_generate_weights_exec(bContext *C, wmOperator *op)
{
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
Object *ob = CTX_data_active_object(C);
Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c
index 7d866aedd87..1a7422cd174 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -87,7 +87,6 @@
typedef struct tGP_BrushEditData {
/* Current editor/region/etc. */
/* NOTE: This stuff is mainly needed to handle 3D view projection stuff... */
- Depsgraph *depsgraph;
struct Main *bmain;
Scene *scene;
Object *object;
@@ -1051,11 +1050,8 @@ static void gp_brush_clone_add(bContext *C, tGP_BrushEditData *gso)
tGPSB_CloneBrushData *data = gso->customdata;
Object *ob = CTX_data_active_object(C);
- bGPDlayer *gpl = CTX_data_active_gpencil_layer(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
- int cfra_eval = (int)DEG_get_ctime(depsgraph);
-
- bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_ADD_NEW);
+ bGPdata *gpd = (bGPdata *)ob->data;
+ Scene *scene = CTX_data_scene(C);
bGPDstroke *gps;
float delta[3];
@@ -1074,6 +1070,18 @@ static void gp_brush_clone_add(bContext *C, tGP_BrushEditData *gso)
bGPDspoint *pt;
int i;
+ bGPDlayer *gpl = NULL;
+ /* Try to use original layer. */
+ if (gps->runtime.tmp_layerinfo != NULL) {
+ gpl = BLI_findstring(&gpd->layers, gps->runtime.tmp_layerinfo, offsetof(bGPDlayer, info));
+ }
+
+ /* if not available, use active layer. */
+ if (gpl == NULL) {
+ gpl = CTX_data_active_gpencil_layer(C);
+ }
+ bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_ADD_NEW);
+
/* Make a new stroke */
new_stroke = MEM_dupallocN(gps);
@@ -1088,10 +1096,10 @@ static void gp_brush_clone_add(bContext *C, tGP_BrushEditData *gso)
BLI_addtail(&gpf->strokes, new_stroke);
/* Fix color references */
- Material *ma = BLI_ghash_lookup(data->new_colors, &new_stroke->mat_nr);
- gps->mat_nr = BKE_gpencil_object_material_get_index(ob, ma);
- if (!ma || gps->mat_nr) {
- gps->mat_nr = 0;
+ Material *ma = BLI_ghash_lookup(data->new_colors, POINTER_FROM_INT(new_stroke->mat_nr));
+ new_stroke->mat_nr = BKE_gpencil_object_material_get_index(ob, ma);
+ if (!ma || new_stroke->mat_nr < 0) {
+ new_stroke->mat_nr = 0;
}
/* Adjust all the stroke's points, so that the strokes
* get pasted relative to where the cursor is now
@@ -1224,7 +1232,6 @@ static bool gpsculpt_brush_init(bContext *C, wmOperator *op)
gso = MEM_callocN(sizeof(tGP_BrushEditData), "tGP_BrushEditData");
op->customdata = gso;
- gso->depsgraph = CTX_data_depsgraph(C);
gso->bmain = CTX_data_main(C);
/* store state */
gso->settings = gpsculpt_get_settings(scene);
@@ -1400,10 +1407,11 @@ static void gpsculpt_brush_init_stroke(tGP_BrushEditData *gso)
bGPdata *gpd = gso->gpd;
bGPDlayer *gpl;
- int cfra_eval = (int)DEG_get_ctime(gso->depsgraph);
+ Scene *scene = gso->scene;
+ int cfra = CFRA;
/* only try to add a new frame if this is the first stroke, or the frame has changed */
- if ((gpd == NULL) || (cfra_eval == gso->cfra)) {
+ if ((gpd == NULL) || (cfra == gso->cfra)) {
return;
}
@@ -1419,14 +1427,14 @@ static void gpsculpt_brush_init_stroke(tGP_BrushEditData *gso)
* spent too much time editing the wrong frame.
*/
// XXX: should this be allowed when framelock is enabled?
- if (gpf->framenum != cfra_eval) {
- BKE_gpencil_frame_addcopy(gpl, cfra_eval);
+ if (gpf->framenum != cfra) {
+ BKE_gpencil_frame_addcopy(gpl, cfra);
}
}
}
/* save off new current frame, so that next update works fine */
- gso->cfra = cfra_eval;
+ gso->cfra = cfra;
}
/* Apply ----------------------------------------------- */
@@ -1478,7 +1486,7 @@ static bool gpsculpt_brush_do_stroke(tGP_BrushEditData *gso,
/* Skip if neither one is selected
* (and we are only allowed to edit/consider selected points) */
- if (gso->settings->flag & GP_SCULPT_SETT_FLAG_SELECT_MASK) {
+ if ((gso->settings->flag & GP_SCULPT_SETT_FLAG_SELECT_MASK) && (!gso->is_weight_mode)) {
if (!(pt1->flag & GP_SPOINT_SELECT) && !(pt2->flag & GP_SPOINT_SELECT)) {
include_last = false;
continue;
@@ -1642,7 +1650,7 @@ static bool gpsculpt_brush_do_frame(
static bool gpsculpt_brush_apply_standard(bContext *C, tGP_BrushEditData *gso)
{
ToolSettings *ts = CTX_data_tool_settings(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
Object *obact = gso->object;
bGPdata *gpd = gso->gpd;
bool changed = false;
diff --git a/source/blender/editors/gpencil/gpencil_convert.c b/source/blender/editors/gpencil/gpencil_convert.c
index 5afa379e04f..4a91a90c075 100644
--- a/source/blender/editors/gpencil/gpencil_convert.c
+++ b/source/blender/editors/gpencil/gpencil_convert.c
@@ -162,7 +162,10 @@ static void gp_strokepoint_convertcoords(bContext *C,
Scene *scene = CTX_data_scene(C);
View3D *v3d = CTX_wm_view3d(C);
ARegion *ar = CTX_wm_region(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ /* TODO(sergey): This function might be called from a loop, but no tagging is happening in it,
+ * so it's not that expensive to ensure evaluated depsgraph here. However, ideally all the
+ * parameters are to wrapped into a context style struct and queried from Context once.*/
+ Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
Object *obact = CTX_data_active_object(C);
bGPDspoint mypt, *pt;
@@ -387,8 +390,7 @@ static void gp_stroke_path_animation_preprocess_gaps(tGpTimingData *gtd,
}
}
-static void gp_stroke_path_animation_add_keyframes(Depsgraph *depsgraph,
- ReportList *reports,
+static void gp_stroke_path_animation_add_keyframes(ReportList *reports,
PointerRNA ptr,
PropertyRNA *prop,
FCurve *fcu,
@@ -446,7 +448,7 @@ static void gp_stroke_path_animation_add_keyframes(Depsgraph *depsgraph,
cfra = last_valid_time + MIN_TIME_DELTA;
}
insert_keyframe_direct(
- depsgraph, reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST);
+ reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST);
last_valid_time = cfra;
}
else if (G.debug & G_DEBUG) {
@@ -459,7 +461,7 @@ static void gp_stroke_path_animation_add_keyframes(Depsgraph *depsgraph,
cfra = last_valid_time + MIN_TIME_DELTA;
}
insert_keyframe_direct(
- depsgraph, reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST);
+ reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST);
last_valid_time = cfra;
}
else {
@@ -467,15 +469,8 @@ static void gp_stroke_path_animation_add_keyframes(Depsgraph *depsgraph,
* and also far enough from (not yet added!) end_stroke keyframe!
*/
if ((cfra - last_valid_time) > MIN_TIME_DELTA && (end_stroke_time - cfra) > MIN_TIME_DELTA) {
- insert_keyframe_direct(depsgraph,
- reports,
- ptr,
- prop,
- fcu,
- cfra,
- BEZT_KEYTYPE_BREAKDOWN,
- NULL,
- INSERTKEY_FAST);
+ insert_keyframe_direct(
+ reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_BREAKDOWN, NULL, INSERTKEY_FAST);
last_valid_time = cfra;
}
else if (G.debug & G_DEBUG) {
@@ -493,7 +488,6 @@ static void gp_stroke_path_animation(bContext *C,
Curve *cu,
tGpTimingData *gtd)
{
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
bAction *act;
@@ -538,7 +532,7 @@ static void gp_stroke_path_animation(bContext *C,
cu->ctime = 0.0f;
cfra = (float)gtd->start_frame;
insert_keyframe_direct(
- depsgraph, reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST);
+ reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST);
cu->ctime = cu->pathlen;
if (gtd->realtime) {
@@ -548,7 +542,7 @@ static void gp_stroke_path_animation(bContext *C,
cfra = (float)gtd->end_frame;
}
insert_keyframe_direct(
- depsgraph, reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST);
+ reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST);
}
else {
/* Use actual recorded timing! */
@@ -575,7 +569,7 @@ static void gp_stroke_path_animation(bContext *C,
}
gp_stroke_path_animation_add_keyframes(
- depsgraph, reports, ptr, prop, fcu, cu, gtd, rng, time_range, nbr_gaps, tot_gaps_time);
+ reports, ptr, prop, fcu, cu, gtd, rng, time_range, nbr_gaps, tot_gaps_time);
BLI_rng_free(rng);
}
@@ -1250,7 +1244,7 @@ static int gp_camera_view_subrect(bContext *C, rctf *subrect)
/* for camera view set the subrect */
if (rv3d->persp == RV3D_CAMOB) {
Scene *scene = CTX_data_scene(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, subrect, true);
return 1;
}
@@ -1274,10 +1268,9 @@ static void gp_layer_to_curve(bContext *C,
struct Main *bmain = CTX_data_main(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
Collection *collection = CTX_data_collection(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
- int cfra_eval = (int)DEG_get_ctime(depsgraph);
+ Scene *scene = CTX_data_scene(C);
- bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_USE_PREV);
+ bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_USE_PREV);
bGPDstroke *gps, *prev_gps = NULL;
Object *ob;
Curve *cu;
@@ -1406,8 +1399,7 @@ static void gp_layer_to_curve(bContext *C,
*/
static bool gp_convert_check_has_valid_timing(bContext *C, bGPDlayer *gpl, wmOperator *op)
{
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
- int cfra_eval = (int)DEG_get_ctime(depsgraph);
+ Scene *scene = CTX_data_scene(C);
bGPDframe *gpf = NULL;
bGPDstroke *gps = NULL;
@@ -1416,7 +1408,7 @@ static bool gp_convert_check_has_valid_timing(bContext *C, bGPDlayer *gpl, wmOpe
int i;
bool valid = true;
- if (!gpl || !(gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_USE_PREV)) ||
+ if (!gpl || !(gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_USE_PREV)) ||
!(gps = gpf->strokes.first)) {
return false;
}
@@ -1468,8 +1460,7 @@ static void gp_convert_set_end_frame(struct Main *UNUSED(main),
static bool gp_convert_poll(bContext *C)
{
Object *ob = CTX_data_active_object(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
- int cfra_eval = (int)DEG_get_ctime(depsgraph);
+ Scene *scene = CTX_data_scene(C);
if ((ob == NULL) || (ob->type != OB_GPENCIL)) {
return false;
@@ -1484,7 +1475,7 @@ static bool gp_convert_poll(bContext *C)
* and if we are not in edit mode!
*/
return ((sa && sa->spacetype == SPACE_VIEW3D) && (gpl = BKE_gpencil_layer_getactive(gpd)) &&
- (gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_USE_PREV)) &&
+ (gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_USE_PREV)) &&
(gpf->strokes.first) && (!GPENCIL_ANY_EDIT_MODE(gpd)));
}
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index 90a2b2d613c..696c98c6646 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -594,8 +594,7 @@ static int gp_frame_duplicate_exec(bContext *C, wmOperator *op)
{
bGPdata *gpd = ED_gpencil_data_get_active(C);
bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
- int cfra_eval = (int)DEG_get_ctime(depsgraph);
+ Scene *scene = CTX_data_scene(C);
int mode = RNA_enum_get(op->ptr, "mode");
@@ -605,12 +604,12 @@ static int gp_frame_duplicate_exec(bContext *C, wmOperator *op)
}
if (mode == 0) {
- BKE_gpencil_frame_addcopy(gpl, cfra_eval);
+ BKE_gpencil_frame_addcopy(gpl, CFRA);
}
else {
for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
if ((gpl->flag & GP_LAYER_LOCKED) == 0) {
- BKE_gpencil_frame_addcopy(gpl, cfra_eval);
+ BKE_gpencil_frame_addcopy(gpl, CFRA);
}
}
}
@@ -2201,7 +2200,7 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
Object *ob_active = CTX_data_active_object(C);
bGPdata *gpd_dst = NULL;
bool ok = false;
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 0c1c24a9432..c6d0d6e3ce2 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -139,7 +139,6 @@ static int gpencil_editmode_toggle_exec(bContext *C, wmOperator *op)
const int back = RNA_boolean_get(op->ptr, "back");
struct wmMsgBus *mbus = CTX_wm_message_bus(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
bGPdata *gpd = ED_gpencil_data_get_active(C);
bool is_object = false;
short mode;
@@ -159,6 +158,7 @@ static int gpencil_editmode_toggle_exec(bContext *C, wmOperator *op)
gpd->flag ^= GP_DATA_STROKE_EDITMODE;
/* recalculate parent matrix */
if (gpd->flag & GP_DATA_STROKE_EDITMODE) {
+ Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
ED_gpencil_reset_layers_parent(depsgraph, ob, gpd);
}
/* set mode */
@@ -1237,8 +1237,7 @@ static int gp_strokes_paste_exec(bContext *C, wmOperator *op)
Object *ob = CTX_data_active_object(C);
bGPdata *gpd = ED_gpencil_data_get_active(C);
bGPDlayer *gpl = CTX_data_active_gpencil_layer(C); /* only use active for copy merge */
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
- int cfra_eval = (int)DEG_get_ctime(depsgraph);
+ Scene *scene = CTX_data_scene(C);
bGPDframe *gpf;
eGP_PasteMode type = RNA_enum_get(op->ptr, "type");
@@ -1329,7 +1328,7 @@ static int gp_strokes_paste_exec(bContext *C, wmOperator *op)
* we are obliged to add a new frame if one
* doesn't exist already
*/
- gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_ADD_NEW);
+ gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_ADD_NEW);
if (gpf) {
/* Create new stroke */
bGPDstroke *new_stroke = MEM_dupallocN(gps);
@@ -1382,7 +1381,7 @@ void GPENCIL_OT_paste(wmOperatorType *ot)
ot->poll = gp_strokes_paste_poll;
/* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA;
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
ot->prop = RNA_def_enum(ot->srna, "type", copy_type, 0, "Type", "");
@@ -1408,8 +1407,7 @@ static int gp_move_to_layer_invoke(bContext *C, wmOperator *op, const wmEvent *U
static int gp_move_to_layer_exec(bContext *C, wmOperator *op)
{
bGPdata *gpd = CTX_data_gpencil_data(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
- int cfra_eval = (int)DEG_get_ctime(depsgraph);
+ Scene *scene = CTX_data_scene(C);
bGPDlayer *target_layer = NULL;
ListBase strokes = {NULL, NULL};
int layer_num = RNA_enum_get(op->ptr, "layer");
@@ -1482,7 +1480,7 @@ static int gp_move_to_layer_exec(bContext *C, wmOperator *op)
/* Paste them all in one go */
if (strokes.first) {
- bGPDframe *gpf = BKE_gpencil_layer_getframe(target_layer, cfra_eval, GP_GETFRAME_ADD_NEW);
+ bGPDframe *gpf = BKE_gpencil_layer_getframe(target_layer, CFRA, GP_GETFRAME_ADD_NEW);
BLI_movelisttolist(&gpf->strokes, &strokes);
BLI_assert((strokes.first == strokes.last) && (strokes.first == NULL));
@@ -1545,8 +1543,8 @@ static bool UNUSED_FUNCTION(gp_blank_frame_add_poll)(bContext *C)
static int gp_blank_frame_add_exec(bContext *C, wmOperator *op)
{
bGPdata *gpd = ED_gpencil_data_get_active(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
- int cfra_eval = (int)DEG_get_ctime(depsgraph);
+ Scene *scene = CTX_data_scene(C);
+ int cfra = CFRA;
bGPDlayer *active_gpl = BKE_gpencil_layer_getactive(gpd);
@@ -1568,7 +1566,7 @@ static int gp_blank_frame_add_exec(bContext *C, wmOperator *op)
}
/* 1) Check for an existing frame on the current frame */
- bGPDframe *gpf = BKE_gpencil_layer_find_frame(gpl, cfra_eval);
+ bGPDframe *gpf = BKE_gpencil_layer_find_frame(gpl, cfra);
if (gpf) {
/* Shunt all frames after (and including) the existing one later by 1-frame */
for (; gpf; gpf = gpf->next) {
@@ -1577,7 +1575,7 @@ static int gp_blank_frame_add_exec(bContext *C, wmOperator *op)
}
/* 2) Now add a new frame, with nothing in it */
- gpl->actframe = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_ADD_NEW);
+ gpl->actframe = BKE_gpencil_layer_getframe(gpl, cfra, GP_GETFRAME_ADD_NEW);
}
CTX_DATA_END;
@@ -1627,10 +1625,9 @@ static int gp_actframe_delete_exec(bContext *C, wmOperator *op)
bGPdata *gpd = ED_gpencil_data_get_active(C);
bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
- int cfra_eval = (int)DEG_get_ctime(depsgraph);
+ Scene *scene = CTX_data_scene(C);
- bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_USE_PREV);
+ bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_USE_PREV);
/* if there's no existing Grease-Pencil data there, add some */
if (gpd == NULL) {
@@ -1681,14 +1678,13 @@ static bool gp_actframe_delete_all_poll(bContext *C)
static int gp_actframe_delete_all_exec(bContext *C, wmOperator *op)
{
bGPdata *gpd = ED_gpencil_data_get_active(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
- int cfra_eval = (int)DEG_get_ctime(depsgraph);
+ Scene *scene = CTX_data_scene(C);
bool success = false;
CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
/* try to get the "active" frame - but only if it actually occurs on this frame */
- bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_USE_PREV);
+ bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_USE_PREV);
if (gpf == NULL) {
continue;
@@ -1940,9 +1936,11 @@ static int gp_dissolve_selected_points(bContext *C, eGP_DissolveMode mode)
*ndvert = *dvert;
ndvert->dw = MEM_dupallocN(dvert->dw);
ndvert++;
- dvert++;
}
}
+ if (gps->dvert != NULL) {
+ dvert++;
+ }
}
break;
case GP_DISSOLVE_BETWEEN:
@@ -1970,9 +1968,11 @@ static int gp_dissolve_selected_points(bContext *C, eGP_DissolveMode mode)
*ndvert = *dvert;
ndvert->dw = MEM_dupallocN(dvert->dw);
ndvert++;
- dvert++;
}
}
+ if (gps->dvert != NULL) {
+ dvert++;
+ }
}
/* copy last segment */
(gps->dvert != NULL) ? dvert = gps->dvert + last : NULL;
@@ -2001,9 +2001,11 @@ static int gp_dissolve_selected_points(bContext *C, eGP_DissolveMode mode)
*ndvert = *dvert;
ndvert->dw = MEM_dupallocN(dvert->dw);
ndvert++;
- dvert++;
}
}
+ if (gps->dvert != NULL) {
+ dvert++;
+ }
}
break;
}
@@ -2493,7 +2495,7 @@ static int gp_snap_to_grid(bContext *C, wmOperator *UNUSED(op))
RegionView3D *rv3d = CTX_wm_region_data(C);
View3D *v3d = CTX_wm_view3d(C);
Scene *scene = CTX_data_scene(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
Object *obact = CTX_data_active_object(C);
const float gridf = ED_view3d_grid_view_scale(scene, v3d, rv3d, NULL);
@@ -2568,7 +2570,7 @@ static int gp_snap_to_cursor(bContext *C, wmOperator *op)
bGPdata *gpd = ED_gpencil_data_get_active(C);
Scene *scene = CTX_data_scene(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
Object *obact = CTX_data_active_object(C);
const bool use_offset = RNA_boolean_get(op->ptr, "use_offset");
@@ -2661,7 +2663,7 @@ static int gp_snap_cursor_to_sel(bContext *C, wmOperator *UNUSED(op))
Scene *scene = CTX_data_scene(C);
View3D *v3d = CTX_wm_view3d(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
Object *obact = CTX_data_active_object(C);
float *cursor = scene->cursor.location;
@@ -3142,10 +3144,7 @@ static void gpencil_stroke_join_strokes(bGPDstroke *gps_a,
/* 3rd: add all points */
for (i = 0, pt = gps_b->points; i < gps_b->totpoints && pt; i++, pt++) {
- /* check if still room in buffer */
- if (gps_a->totpoints <= GP_STROKE_BUFFER_MAX - 2) {
- gpencil_stroke_copy_point(gps_a, pt, i, delta, pt->pressure, pt->strength, deltatime);
- }
+ gpencil_stroke_copy_point(gps_a, pt, i, delta, pt->pressure, pt->strength, deltatime);
}
}
@@ -3375,7 +3374,7 @@ static int gp_strokes_reproject_exec(bContext *C, wmOperator *op)
bGPdata *gpd = ED_gpencil_data_get_active(C);
Scene *scene = CTX_data_scene(C);
ToolSettings *ts = CTX_data_tool_settings(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
Object *ob = CTX_data_active_object(C);
ARegion *ar = CTX_wm_region(C);
RegionView3D *rv3d = ar->regiondata;
@@ -3401,12 +3400,6 @@ static int gp_strokes_reproject_exec(bContext *C, wmOperator *op)
if (gps->flag & GP_STROKE_SELECT) {
bGPDspoint *pt;
int i;
- float inverse_diff_mat[4][4];
-
- /* Compute inverse matrix for unapplying parenting once instead of doing per-point */
- /* TODO: add this bit to the iteration macro? */
- invert_m4_m4(inverse_diff_mat, gpstroke_iter.diff_mat);
-
/* Adjust each point */
for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
float xy[2];
@@ -3493,7 +3486,7 @@ static int gp_strokes_reproject_exec(bContext *C, wmOperator *op)
/* Unapply parent corrections */
if (!ELEM(mode, GP_REPROJECT_FRONT, GP_REPROJECT_SIDE, GP_REPROJECT_TOP)) {
- mul_m4_v3(inverse_diff_mat, &pt->x);
+ mul_m4_v3(gpstroke_iter.inverse_diff_mat, &pt->x);
}
}
}
@@ -3526,7 +3519,7 @@ void GPENCIL_OT_reproject(wmOperatorType *ot)
"CURSOR",
0,
"Cursor",
- "Reproject the strokes using the orienation of 3D cursor"},
+ "Reproject the strokes using the orientation of 3D cursor"},
{0, NULL, 0, NULL, NULL},
};
@@ -3544,7 +3537,7 @@ void GPENCIL_OT_reproject(wmOperatorType *ot)
ot->poll = gp_strokes_edit3d_poll;
/* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA;
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
ot->prop = RNA_def_enum(
@@ -4534,7 +4527,7 @@ void GPENCIL_OT_stroke_cutter(wmOperatorType *ot)
ot->cancel = WM_gesture_lasso_cancel;
/* flag */
- ot->flag = OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA;
+ ot->flag = OPTYPE_UNDO;
/* properties */
WM_operator_properties_gesture_lasso(ot);
diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c
index d914cdea442..5637e755198 100644
--- a/source/blender/editors/gpencil/gpencil_fill.c
+++ b/source/blender/editors/gpencil/gpencil_fill.c
@@ -135,7 +135,7 @@ typedef struct tGPDfill {
short fill_factor;
/** number of elements currently in cache */
- short sbuffer_size;
+ short sbuffer_used;
/** temporary points */
void *sbuffer;
/** depth array for reproject */
@@ -918,7 +918,7 @@ static void gpencil_get_depth_array(tGPDfill *tgpf)
{
tGPspoint *ptc;
ToolSettings *ts = tgpf->scene->toolsettings;
- int totpoints = tgpf->sbuffer_size;
+ int totpoints = tgpf->sbuffer_used;
int i = 0;
if (totpoints == 0) {
@@ -984,7 +984,7 @@ static void gpencil_points_from_stack(tGPDfill *tgpf)
return;
}
- tgpf->sbuffer_size = (short)totpoints;
+ tgpf->sbuffer_used = (short)totpoints;
tgpf->sbuffer = MEM_callocN(sizeof(tGPspoint) * totpoints, __func__);
point2D = tgpf->sbuffer;
@@ -1020,7 +1020,7 @@ static void gpencil_stroke_from_buffer(tGPDfill *tgpf)
MDeformVert *dvert = NULL;
tGPspoint *point2D;
- if (tgpf->sbuffer_size == 0) {
+ if (tgpf->sbuffer_used == 0) {
return;
}
@@ -1041,8 +1041,8 @@ static void gpencil_stroke_from_buffer(tGPDfill *tgpf)
gps->mat_nr = BKE_gpencil_object_material_ensure(tgpf->bmain, tgpf->ob, tgpf->mat);
/* allocate memory for storage points */
- gps->totpoints = tgpf->sbuffer_size;
- gps->points = MEM_callocN(sizeof(bGPDspoint) * tgpf->sbuffer_size, "gp_stroke_points");
+ gps->totpoints = tgpf->sbuffer_used;
+ gps->points = MEM_callocN(sizeof(bGPDspoint) * tgpf->sbuffer_used, "gp_stroke_points");
/* initialize triangle memory to dummy data */
gps->tot_triangles = 0;
@@ -1069,7 +1069,7 @@ static void gpencil_stroke_from_buffer(tGPDfill *tgpf)
dvert = gps->dvert;
}
- for (int i = 0; i < tgpf->sbuffer_size && point2D; i++, point2D++, pt++) {
+ for (int i = 0; i < tgpf->sbuffer_used && point2D; i++, point2D++, pt++) {
/* convert screen-coordinates to 3D coordinates */
gp_stroke_convertcoords_tpoint(tgpf->scene,
tgpf->ar,
@@ -1120,7 +1120,7 @@ static void gpencil_stroke_from_buffer(tGPDfill *tgpf)
}
/* if parented change position relative to parent object */
- for (int a = 0; a < tgpf->sbuffer_size; a++) {
+ for (int a = 0; a < tgpf->sbuffer_used; a++) {
pt = &gps->points[a];
gp_apply_parent_point(tgpf->depsgraph, tgpf->ob, tgpf->gpd, tgpf->gpl, pt);
}
@@ -1213,7 +1213,7 @@ static tGPDfill *gp_session_init_fill(bContext *C, wmOperator *UNUSED(op))
tgpf->ar = CTX_wm_region(C);
tgpf->rv3d = tgpf->ar->regiondata;
tgpf->v3d = tgpf->sa->spacedata.first;
- tgpf->depsgraph = CTX_data_depsgraph(C);
+ tgpf->depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
tgpf->win = CTX_wm_window(C);
/* set GP datablock */
@@ -1225,7 +1225,7 @@ static tGPDfill *gp_session_init_fill(bContext *C, wmOperator *UNUSED(op))
tgpf->lock_axis = ts->gp_sculpt.lock_axis;
tgpf->oldkey = -1;
- tgpf->sbuffer_size = 0;
+ tgpf->sbuffer_used = 0;
tgpf->sbuffer = NULL;
tgpf->depth_arr = NULL;
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index df9cb2e9a01..a8a3c2f9306 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -378,8 +378,8 @@ typedef enum eGPencil_PaintModes {
GP_PAINTMODE_SET_CP,
} eGPencil_PaintModes;
-/* maximum sizes of gp-session buffer */
-#define GP_STROKE_BUFFER_MAX 5000
+/* chunk size for gp-session buffer (the total size is a multiple of this number) */
+#define GP_STROKE_BUFFER_CHUNK 2048
/* stroke editing ----- */
@@ -583,6 +583,7 @@ typedef enum ACTCONT_TYPES {
struct GP_EditableStrokes_Iter {
float diff_mat[4][4];
+ float inverse_diff_mat[4][4];
};
/**
@@ -598,7 +599,7 @@ struct GP_EditableStrokes_Iter {
#define GP_EDITABLE_STROKES_BEGIN(gpstroke_iter, C, gpl, gps) \
{ \
struct GP_EditableStrokes_Iter gpstroke_iter = {{{0}}}; \
- Depsgraph *depsgraph_ = CTX_data_depsgraph(C); \
+ Depsgraph *depsgraph_ = CTX_data_ensure_evaluated_depsgraph(C); \
Object *obact_ = CTX_data_active_object(C); \
bGPdata *gpd_ = CTX_data_gpencil_data(C); \
const bool is_multiedit_ = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd_); \
@@ -607,6 +608,7 @@ struct GP_EditableStrokes_Iter {
for (bGPDframe *gpf_ = init_gpf_; gpf_; gpf_ = gpf_->next) { \
if ((gpf_ == gpl->actframe) || ((gpf_->flag & GP_FRAME_SELECT) && is_multiedit_)) { \
ED_gpencil_parent_location(depsgraph_, obact_, gpd_, gpl, gpstroke_iter.diff_mat); \
+ invert_m4_m4(gpstroke_iter.inverse_diff_mat, gpstroke_iter.diff_mat); \
/* loop over strokes */ \
for (bGPDstroke *gps = gpf_->strokes.first; gps; gps = gps->next) { \
/* skip strokes that are invalid for current view */ \
diff --git a/source/blender/editors/gpencil/gpencil_interpolate.c b/source/blender/editors/gpencil/gpencil_interpolate.c
index 4d5548dcdf3..698e508a2a5 100644
--- a/source/blender/editors/gpencil/gpencil_interpolate.c
+++ b/source/blender/editors/gpencil/gpencil_interpolate.c
@@ -511,8 +511,8 @@ static int gpencil_interpolate_invoke(bContext *C, wmOperator *op, const wmEvent
wmWindow *win = CTX_wm_window(C);
bGPdata *gpd = CTX_data_gpencil_data(C);
bGPDlayer *gpl = CTX_data_active_gpencil_layer(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
- int cfra_eval = (int)DEG_get_ctime(depsgraph);
+ Scene *scene = CTX_data_scene(C);
+ int cfra = CFRA;
bGPDframe *actframe = gpl->actframe;
tGPDinterpolate *tgpi = NULL;
@@ -526,7 +526,7 @@ static int gpencil_interpolate_invoke(bContext *C, wmOperator *op, const wmEvent
}
/* cannot interpolate in extremes */
- if (ELEM(cfra_eval, actframe->framenum, actframe->next->framenum)) {
+ if (ELEM(cfra, actframe->framenum, actframe->next->framenum)) {
BKE_report(op->reports,
RPT_ERROR,
"Cannot interpolate as current frame already has existing grease pencil frames");
@@ -949,8 +949,8 @@ static int gpencil_interpolate_seq_exec(bContext *C, wmOperator *op)
Object *ob = CTX_data_active_object(C);
ToolSettings *ts = CTX_data_tool_settings(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
- int cfra_eval = (int)DEG_get_ctime(depsgraph);
+ Scene *scene = CTX_data_scene(C);
+ int cfra = CFRA;
GP_Interpolate_Settings *ipo_settings = &ts->gp_interpolate;
eGP_Interpolate_SettingsFlag flag = ipo_settings->flag;
@@ -964,7 +964,7 @@ static int gpencil_interpolate_seq_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
/* cannot interpolate in extremes */
- if (ELEM(cfra_eval, actframe->framenum, actframe->next->framenum)) {
+ if (ELEM(cfra, actframe->framenum, actframe->next->framenum)) {
BKE_report(op->reports,
RPT_ERROR,
"Cannot interpolate as current frame already has existing grease pencil frames");
diff --git a/source/blender/editors/gpencil/gpencil_merge.c b/source/blender/editors/gpencil/gpencil_merge.c
index 93d8555e014..cb11bb4cd63 100644
--- a/source/blender/editors/gpencil/gpencil_merge.c
+++ b/source/blender/editors/gpencil/gpencil_merge.c
@@ -98,11 +98,10 @@ static void gpencil_insert_points_to_stroke(bGPDstroke *gps,
static bGPDstroke *gpencil_prepare_stroke(bContext *C, wmOperator *op, int totpoints)
{
ToolSettings *ts = CTX_data_tool_settings(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
Object *ob = CTX_data_active_object(C);
bGPDlayer *gpl = CTX_data_active_gpencil_layer(C);
- int cfra_eval = (int)DEG_get_ctime(depsgraph);
+ Scene *scene = CTX_data_scene(C);
const bool back = RNA_boolean_get(op->ptr, "back");
const bool additive = RNA_boolean_get(op->ptr, "additive");
@@ -124,7 +123,7 @@ static bGPDstroke *gpencil_prepare_stroke(bContext *C, wmOperator *op, int totpo
else {
add_frame_mode = GP_GETFRAME_ADD_NEW;
}
- bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, add_frame_mode);
+ bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, CFRA, add_frame_mode);
/* stroke */
bGPDstroke *gps = MEM_callocN(sizeof(bGPDstroke), "gp_stroke");
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index db4c601709c..d259bb9183c 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -81,9 +81,15 @@ static bool gp_stroke_paintmode_poll_with_tool(bContext *C, const char gpencil_t
{
/* TODO: limit this to mode, but review 2D editors */
bGPdata *gpd = CTX_data_gpencil_data(C);
+ if (!gpd)
+ return false;
+
ToolSettings *ts = CTX_data_tool_settings(C);
+ if (!ts || !ts->gp_paint)
+ return false;
+
Brush *brush = BKE_paint_brush(&ts->gp_paint->paint);
- return ((gpd) && (gpd->flag & GP_DATA_STROKE_PAINTMODE) && (brush && brush->gpencil_settings) &&
+ return ((gpd->flag & GP_DATA_STROKE_PAINTMODE) && (brush && brush->gpencil_settings) &&
WM_toolsystem_active_tool_is_brush(C) && (brush->gpencil_tool == gpencil_tool));
}
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index b49094c4fd6..a271274fa71 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -349,7 +349,7 @@ static bool gp_stroke_filtermval(tGPsdata *p, const float mval[2], float mvalo[2
brush->gpencil_settings->flag &= ~GP_BRUSH_STABILIZE_MOUSE_TEMP;
/* if buffer is empty, just let this go through (i.e. so that dots will work) */
- if (p->gpd->runtime.sbuffer_size == 0) {
+ if (p->gpd->runtime.sbuffer_used == 0) {
return true;
}
/* if lazy mouse, check minimum distance */
@@ -486,7 +486,7 @@ static void gp_brush_jitter(bGPdata *gpd,
/* Jitter is applied perpendicular to the mouse movement vector (2D space) */
float mvec[2], svec[2];
/* mouse movement in ints -> floats */
- if (gpd->runtime.sbuffer_size > 1) {
+ if (gpd->runtime.sbuffer_used > 1) {
mvec[0] = (mval[0] - (pt - 1)->x);
mvec[1] = (mval[1] - (pt - 1)->y);
normalize_v2(mvec);
@@ -524,7 +524,7 @@ static void gp_brush_angle(bGPdata *gpd, Brush *brush, tGPspoint *pt, const floa
float v0[2] = {cos(angle), sin(angle)};
/* Apply to first point (only if there are 2 points because before no data to do it ) */
- if (gpd->runtime.sbuffer_size == 1) {
+ if (gpd->runtime.sbuffer_used == 1) {
mvec[0] = (mval[0] - (pt - 1)->x);
mvec[1] = (mval[1] - (pt - 1)->y);
normalize_v2(mvec);
@@ -537,7 +537,7 @@ static void gp_brush_angle(bGPdata *gpd, Brush *brush, tGPspoint *pt, const floa
}
/* apply from second point */
- if (gpd->runtime.sbuffer_size >= 1) {
+ if (gpd->runtime.sbuffer_used >= 1) {
mvec[0] = (mval[0] - (pt - 1)->x);
mvec[1] = (mval[1] - (pt - 1)->y);
normalize_v2(mvec);
@@ -563,7 +563,7 @@ static void gp_brush_angle(bGPdata *gpd, Brush *brush, tGPspoint *pt, const floa
static void gp_smooth_buffer(tGPsdata *p, float inf, int idx)
{
bGPdata *gpd = p->gpd;
- short num_points = gpd->runtime.sbuffer_size;
+ short num_points = gpd->runtime.sbuffer_used;
/* Do nothing if not enough points to smooth out */
if ((num_points < 3) || (idx < 3) || (inf == 0.0f)) {
@@ -626,7 +626,7 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
/* check painting mode */
if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) {
/* straight lines only - i.e. only store start and end point in buffer */
- if (gpd->runtime.sbuffer_size == 0) {
+ if (gpd->runtime.sbuffer_used == 0) {
/* first point in buffer (start point) */
pt = (tGPspoint *)(gpd->runtime.sbuffer);
@@ -638,7 +638,7 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
pt->time = (float)(curtime - p->inittime);
/* increment buffer size */
- gpd->runtime.sbuffer_size++;
+ gpd->runtime.sbuffer_used++;
}
else {
/* just reset the endpoint to the latest value
@@ -654,20 +654,19 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
pt->time = (float)(curtime - p->inittime);
/* now the buffer has 2 points (and shouldn't be allowed to get any larger) */
- gpd->runtime.sbuffer_size = 2;
+ gpd->runtime.sbuffer_used = 2;
}
/* can keep carrying on this way :) */
return GP_STROKEADD_NORMAL;
}
else if (p->paintmode == GP_PAINTMODE_DRAW) { /* normal drawing */
- /* check if still room in buffer */
- if (gpd->runtime.sbuffer_size >= GP_STROKE_BUFFER_MAX) {
- return GP_STROKEADD_OVERFLOW;
- }
+ /* check if still room in buffer or add more */
+ gpd->runtime.sbuffer = ED_gpencil_sbuffer_ensure(
+ gpd->runtime.sbuffer, &gpd->runtime.sbuffer_size, &gpd->runtime.sbuffer_used, false);
/* get pointer to destination point */
- pt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_size);
+ pt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_used);
/* store settings */
/* pressure */
@@ -760,9 +759,9 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
pt->time = (float)(curtime - p->inittime);
/* point uv (only 3d view) */
- if ((p->sa->spacetype == SPACE_VIEW3D) && (gpd->runtime.sbuffer_size > 0)) {
+ if ((p->sa->spacetype == SPACE_VIEW3D) && (gpd->runtime.sbuffer_used > 0)) {
float pixsize = gp_style->texture_pixsize / 1000000.0f;
- tGPspoint *ptb = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_size - 1;
+ tGPspoint *ptb = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_used - 1;
bGPDspoint spt, spt2;
/* get origin to reproject point */
@@ -787,24 +786,18 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
}
/* increment counters */
- gpd->runtime.sbuffer_size++;
+ gpd->runtime.sbuffer_used++;
/* smooth while drawing previous points with a reduction factor for previous */
if (brush->gpencil_settings->active_smooth > 0.0f) {
for (int s = 0; s < 3; s++) {
gp_smooth_buffer(p,
brush->gpencil_settings->active_smooth * ((3.0f - s) / 3.0f),
- gpd->runtime.sbuffer_size - s);
+ gpd->runtime.sbuffer_used - s);
}
}
- /* check if another operation can still occur */
- if (gpd->runtime.sbuffer_size == GP_STROKE_BUFFER_MAX) {
- return GP_STROKEADD_FULL;
- }
- else {
- return GP_STROKEADD_NORMAL;
- }
+ return GP_STROKEADD_NORMAL;
}
else if (p->paintmode == GP_PAINTMODE_DRAW_POLY) {
@@ -832,7 +825,7 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
MDeformVert *dvert = NULL;
/* first time point is adding to temporary buffer -- need to allocate new point in stroke */
- if (gpd->runtime.sbuffer_size == 0) {
+ if (gpd->runtime.sbuffer_used == 0) {
gps->points = MEM_reallocN(gps->points, sizeof(bGPDspoint) * (gps->totpoints + 1));
if (gps->dvert != NULL) {
gps->dvert = MEM_reallocN(gps->dvert, sizeof(MDeformVert) * (gps->totpoints + 1));
@@ -889,8 +882,8 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
}
/* increment counters */
- if (gpd->runtime.sbuffer_size == 0) {
- gpd->runtime.sbuffer_size++;
+ if (gpd->runtime.sbuffer_used == 0) {
+ gpd->runtime.sbuffer_used++;
}
return GP_STROKEADD_NORMAL;
@@ -930,17 +923,17 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
* - drawing straight-lines only requires the endpoints
*/
if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) {
- totelem = (gpd->runtime.sbuffer_size >= 2) ? 2 : gpd->runtime.sbuffer_size;
+ totelem = (gpd->runtime.sbuffer_used >= 2) ? 2 : gpd->runtime.sbuffer_used;
}
else {
- totelem = gpd->runtime.sbuffer_size;
+ totelem = gpd->runtime.sbuffer_used;
}
/* exit with error if no valid points from this stroke */
if (totelem == 0) {
if (G.debug & G_DEBUG) {
printf("Error: No valid points in stroke buffer to convert (tot=%d)\n",
- gpd->runtime.sbuffer_size);
+ gpd->runtime.sbuffer_used);
}
return;
}
@@ -1024,7 +1017,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
if (totelem == 2) {
/* last point if applicable */
- ptc = ((tGPspoint *)gpd->runtime.sbuffer) + (gpd->runtime.sbuffer_size - 1);
+ ptc = ((tGPspoint *)gpd->runtime.sbuffer) + (gpd->runtime.sbuffer_used - 1);
/* convert screen-coordinates to appropriate coordinates (and store them) */
gp_stroke_convertcoords(p, &ptc->x, &pt->x, NULL);
@@ -1105,9 +1098,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
int interp_depth = 0;
int found_depth = 0;
- depth_arr = MEM_mallocN(sizeof(float) * gpd->runtime.sbuffer_size, "depth_points");
+ depth_arr = MEM_mallocN(sizeof(float) * gpd->runtime.sbuffer_used, "depth_points");
- for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_size; i++, ptc++, pt++) {
+ for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_used; i++, ptc++, pt++) {
round_v2i_v2fl(mval_i, &ptc->x);
@@ -1125,7 +1118,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
if (found_depth == false) {
/* eeh... not much we can do.. :/, ignore depth in this case, use the 3D cursor */
- for (i = gpd->runtime.sbuffer_size - 1; i >= 0; i--) {
+ for (i = gpd->runtime.sbuffer_used - 1; i >= 0; i--) {
depth_arr[i] = 0.9999f;
}
}
@@ -1137,7 +1130,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
int last_valid = 0;
/* find first valid contact point */
- for (i = 0; i < gpd->runtime.sbuffer_size; i++) {
+ for (i = 0; i < gpd->runtime.sbuffer_used; i++) {
if (depth_arr[i] != FLT_MAX) {
break;
}
@@ -1149,7 +1142,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
last_valid = first_valid;
}
else {
- for (i = gpd->runtime.sbuffer_size - 1; i >= 0; i--) {
+ for (i = gpd->runtime.sbuffer_used - 1; i >= 0; i--) {
if (depth_arr[i] != FLT_MAX) {
break;
}
@@ -1158,7 +1151,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
}
/* invalidate any other point, to interpolate between
* first and last contact in an imaginary line between them */
- for (i = 0; i < gpd->runtime.sbuffer_size; i++) {
+ for (i = 0; i < gpd->runtime.sbuffer_used; i++) {
if ((i != first_valid) && (i != last_valid)) {
depth_arr[i] = FLT_MAX;
}
@@ -1167,7 +1160,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
}
if (interp_depth) {
- interp_sparse_array(depth_arr, gpd->runtime.sbuffer_size, FLT_MAX);
+ interp_sparse_array(depth_arr, gpd->runtime.sbuffer_used, FLT_MAX);
}
}
}
@@ -1176,7 +1169,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
dvert = gps->dvert;
/* convert all points (normal behavior) */
- for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_size && ptc;
+ for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_used && ptc;
i++, ptc++, pt++) {
/* convert screen-coordinates to appropriate coordinates (and store them) */
gp_stroke_convertcoords(p, &ptc->x, &pt->x, depth_arr ? depth_arr + i : NULL);
@@ -1725,18 +1718,8 @@ static void gp_session_validatebuffer(tGPsdata *p)
Brush *brush = p->brush;
/* clear memory of buffer (or allocate it if starting a new session) */
- if (gpd->runtime.sbuffer) {
- /* printf("\t\tGP - reset sbuffer\n"); */
- memset(gpd->runtime.sbuffer, 0, sizeof(tGPspoint) * GP_STROKE_BUFFER_MAX);
- }
- else {
- /* printf("\t\tGP - allocate sbuffer\n"); */
- gpd->runtime.sbuffer = MEM_callocN(sizeof(tGPspoint) * GP_STROKE_BUFFER_MAX,
- "gp_session_strokebuffer");
- }
-
- /* reset indices */
- gpd->runtime.sbuffer_size = 0;
+ gpd->runtime.sbuffer = ED_gpencil_sbuffer_ensure(
+ gpd->runtime.sbuffer, &gpd->runtime.sbuffer_size, &gpd->runtime.sbuffer_used, true);
/* reset flags */
gpd->runtime.sbuffer_sflag = 0;
@@ -1911,7 +1894,7 @@ static bool gp_session_initdata(bContext *C, wmOperator *op, tGPsdata *p)
p->C = C;
p->bmain = CTX_data_main(C);
p->scene = CTX_data_scene(C);
- p->depsgraph = CTX_data_depsgraph(C);
+ p->depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
p->win = CTX_wm_window(C);
p->disable_fill = RNA_boolean_get(op->ptr, "disable_fill");
@@ -2070,6 +2053,7 @@ static void gp_session_cleanup(tGPsdata *p)
}
/* clear flags */
+ gpd->runtime.sbuffer_used = 0;
gpd->runtime.sbuffer_size = 0;
gpd->runtime.sbuffer_sflag = 0;
p->inittime = 0.0;
@@ -2089,7 +2073,6 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps
{
Scene *scene = p->scene;
ToolSettings *ts = scene->toolsettings;
- int cfra_eval = (int)DEG_get_ctime(p->depsgraph);
/* get active layer (or add a new one if non-existent) */
p->gpl = BKE_gpencil_layer_getactive(p->gpd);
@@ -2131,7 +2114,7 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps
* -> If there are no strokes in that frame, don't add a new empty frame
*/
if (gpl->actframe && gpl->actframe->strokes.first) {
- gpl->actframe = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_ADD_COPY);
+ gpl->actframe = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_ADD_COPY);
has_layer_to_erase = true;
}
@@ -2169,7 +2152,7 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps
add_frame_mode = GP_GETFRAME_ADD_NEW;
}
- p->gpf = BKE_gpencil_layer_getframe(p->gpl, cfra_eval, add_frame_mode);
+ p->gpf = BKE_gpencil_layer_getframe(p->gpl, CFRA, add_frame_mode);
if (p->gpf == NULL) {
p->status = GP_STATUS_ERROR;
@@ -2448,7 +2431,7 @@ static int gpencil_draw_init(bContext *C, wmOperator *op, const wmEvent *event)
}
/* init painting data */
- gp_paint_initstroke(p, paintmode, CTX_data_depsgraph(C));
+ gp_paint_initstroke(p, paintmode, CTX_data_ensure_evaluated_depsgraph(C));
if (p->status == GP_STATUS_ERROR) {
gpencil_draw_exit(C, op);
return 0;
@@ -2624,14 +2607,14 @@ static void gpencil_draw_apply(bContext *C, wmOperator *op, tGPsdata *p, Depsgra
p->opressure = p->pressure;
p->ocurtime = p->curtime;
- pt = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_size - 1;
+ pt = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_used - 1;
if (p->paintmode != GP_PAINTMODE_ERASER) {
ED_gpencil_toggle_brush_cursor(C, true, &pt->x);
}
}
else if ((p->brush->gpencil_settings->flag & GP_BRUSH_STABILIZE_MOUSE_TEMP) &&
- (gpd->runtime.sbuffer_size > 0)) {
- pt = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_size - 1;
+ (gpd->runtime.sbuffer_used > 0)) {
+ pt = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_used - 1;
if (p->paintmode != GP_PAINTMODE_ERASER) {
ED_gpencil_toggle_brush_cursor(C, true, &pt->x);
}
@@ -2842,10 +2825,10 @@ static void gpencil_draw_apply_event(
float pt[2];
copy_v2_v2(tmp, p->mval);
sub_v2_v2v2(pt, p->mval, p->mvali);
- gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph(C), pt[0], pt[1]);
+ gpencil_draw_apply_event(C, op, event, depsgraph, pt[0], pt[1]);
if (len_v2v2(p->mval, p->mvalo)) {
sub_v2_v2v2(pt, p->mval, p->mvalo);
- gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph(C), pt[0], pt[1]);
+ gpencil_draw_apply_event(C, op, event, depsgraph, pt[0], pt[1]);
}
copy_v2_v2(p->mval, tmp);
}
@@ -2965,7 +2948,7 @@ static void gpencil_draw_apply_event(
static int gpencil_draw_exec(bContext *C, wmOperator *op)
{
tGPsdata *p = NULL;
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
/* printf("GPencil - Starting Re-Drawing\n"); */
@@ -3213,7 +3196,7 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event
p->status = GP_STATUS_PAINTING;
/* handle the initial drawing - i.e. for just doing a simple dot */
- gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph(C), 0.0f, 0.0f);
+ gpencil_draw_apply_event(C, op, event, CTX_data_ensure_evaluated_depsgraph(C), 0.0f, 0.0f);
op->flag |= OP_IS_MODAL_CURSOR_REGION;
}
else {
@@ -3277,7 +3260,7 @@ static tGPsdata *gpencil_stroke_begin(bContext *C, wmOperator *op)
* it'd be nice to allow changing paint-mode when in sketching-sessions */
if (gp_session_initdata(C, op, p)) {
- gp_paint_initstroke(p, p->paintmode, CTX_data_depsgraph(C));
+ gp_paint_initstroke(p, p->paintmode, CTX_data_depsgraph_pointer(C));
}
if (p->status != GP_STATUS_ERROR) {
@@ -3338,6 +3321,7 @@ static void gpencil_add_missing_events(bContext *C,
{
Brush *brush = p->brush;
GP_Sculpt_Guide *guide = &p->scene->toolsettings->gp_sculpt.guide;
+ Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
int input_samples = brush->gpencil_settings->input_samples;
/* ensure sampling when using circular guide */
@@ -3396,7 +3380,7 @@ static void gpencil_add_missing_events(bContext *C,
interp_v2_v2v2(pt, a, b, 0.5f);
sub_v2_v2v2(pt, b, pt);
/* create fake event */
- gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph(C), pt[0], pt[1]);
+ gpencil_draw_apply_event(C, op, event, depsgraph, pt[0], pt[1]);
}
else if (dist >= factor) {
int slices = 2 + (int)((dist - 1.0) / factor);
@@ -3405,7 +3389,7 @@ static void gpencil_add_missing_events(bContext *C,
interp_v2_v2v2(pt, a, b, n * i);
sub_v2_v2v2(pt, b, pt);
/* create fake event */
- gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph(C), pt[0], pt[1]);
+ gpencil_draw_apply_event(C, op, event, depsgraph, pt[0], pt[1]);
}
}
}
@@ -3712,7 +3696,7 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
gpencil_add_missing_events(C, op, event, p);
}
- gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph(C), 0.0f, 0.0f);
+ gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph_pointer(C), 0.0f, 0.0f);
/* finish painting operation if anything went wrong just now */
if (p->status == GP_STATUS_ERROR) {
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index cca94925e6e..bdc65e7172a 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -114,16 +114,8 @@ static void gp_session_validatebuffer(tGPDprimitive *p)
bGPdata *gpd = p->gpd;
/* clear memory of buffer (or allocate it if starting a new session) */
- if (gpd->runtime.sbuffer) {
- memset(gpd->runtime.sbuffer, 0, sizeof(tGPspoint) * GP_STROKE_BUFFER_MAX);
- }
- else {
- gpd->runtime.sbuffer = MEM_callocN(sizeof(tGPspoint) * GP_STROKE_BUFFER_MAX,
- "gp_session_strokebuffer");
- }
-
- /* reset indices */
- gpd->runtime.sbuffer_size = 0;
+ gpd->runtime.sbuffer = ED_gpencil_sbuffer_ensure(
+ gpd->runtime.sbuffer, &gpd->runtime.sbuffer_size, &gpd->runtime.sbuffer_used, true);
/* reset flags */
gpd->runtime.sbuffer_sflag = 0;
@@ -305,8 +297,8 @@ static void gpencil_primitive_allocate_memory(tGPDprimitive *tgpi)
/* Helper: Create internal strokes primitives data */
static void gp_primitive_set_initdata(bContext *C, tGPDprimitive *tgpi)
{
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
- int cfra_eval = (int)DEG_get_ctime(depsgraph);
+ Scene *scene = CTX_data_scene(C);
+ int cfra = CFRA;
bGPDlayer *gpl = CTX_data_active_gpencil_layer(C);
@@ -318,7 +310,7 @@ static void gp_primitive_set_initdata(bContext *C, tGPDprimitive *tgpi)
/* create a new temporary frame */
tgpi->gpf = MEM_callocN(sizeof(bGPDframe), "Temp bGPDframe");
- tgpi->gpf->framenum = tgpi->cframe = cfra_eval;
+ tgpi->gpf->framenum = tgpi->cframe = cfra;
/* create new temp stroke */
bGPDstroke *gps = MEM_callocN(sizeof(bGPDstroke), "Temp bGPDstroke");
@@ -828,7 +820,7 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
}
/* Copy points to buffer */
- tGPspoint *tpt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_size);
+ tGPspoint *tpt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_used);
/* Store original points */
float tmp_xyp[2];
@@ -927,10 +919,10 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
tpt->time = p2d->time;
/* point uv */
- if (gpd->runtime.sbuffer_size > 0) {
+ if (gpd->runtime.sbuffer_used > 0) {
MaterialGPencilStyle *gp_style = tgpi->mat->gp_style;
const float pixsize = gp_style->texture_pixsize / 1000000.0f;
- tGPspoint *tptb = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_size - 1;
+ tGPspoint *tptb = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_used - 1;
bGPDspoint spt, spt2;
/* get origin to reproject point */
@@ -958,7 +950,11 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
tpt->uv_rot = p2d->uv_rot;
- gpd->runtime.sbuffer_size++;
+ gpd->runtime.sbuffer_used++;
+
+ /* check if still room in buffer or add more */
+ gpd->runtime.sbuffer = ED_gpencil_sbuffer_ensure(
+ gpd->runtime.sbuffer, &gpd->runtime.sbuffer_size, &gpd->runtime.sbuffer_used, false);
/* add small offset to keep stroke over the surface */
if ((depth_arr) && (gpd->zdepth_offset > 0.0f)) {
@@ -1078,6 +1074,7 @@ static void gpencil_primitive_exit(bContext *C, wmOperator *op)
gpd->runtime.sbuffer = NULL;
/* clear flags */
+ gpd->runtime.sbuffer_used = 0;
gpd->runtime.sbuffer_size = 0;
gpd->runtime.sbuffer_sflag = 0;
}
@@ -1096,11 +1093,8 @@ static void gpencil_primitive_init(bContext *C, wmOperator *op)
bGPdata *gpd = CTX_data_gpencil_data(C);
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
Paint *paint = &ts->gp_paint->paint;
- int cfra_eval = (int)DEG_get_ctime(depsgraph);
-
/* create temporary operator data */
tGPDprimitive *tgpi = MEM_callocN(sizeof(tGPDprimitive), "GPencil Primitive Data");
op->customdata = tgpi;
@@ -1115,14 +1109,14 @@ static void gpencil_primitive_init(bContext *C, wmOperator *op)
tgpi->ar = CTX_wm_region(C);
tgpi->rv3d = tgpi->ar->regiondata;
tgpi->v3d = tgpi->sa->spacedata.first;
- tgpi->depsgraph = CTX_data_depsgraph(C);
+ tgpi->depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
tgpi->win = CTX_wm_window(C);
/* save original type */
tgpi->orign_type = RNA_enum_get(op->ptr, "type");
/* set current frame number */
- tgpi->cframe = cfra_eval;
+ tgpi->cframe = CFRA;
/* set GP datablock */
tgpi->gpd = gpd;
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index ba806022d3e..5a962809954 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -302,11 +302,10 @@ typedef enum eGP_SelectGrouped {
/* On each visible layer, check for selected strokes - if found, select all others */
static void gp_select_same_layer(bContext *C)
{
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
- int cfra_eval = (int)DEG_get_ctime(depsgraph);
+ Scene *scene = CTX_data_scene(C);
CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
- bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_USE_PREV);
+ bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_USE_PREV);
bGPDstroke *gps;
bool found = false;
@@ -990,7 +989,7 @@ void GPENCIL_OT_select_circle(wmOperatorType *ot)
ot->cancel = WM_gesture_circle_cancel;
/* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA;
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
WM_operator_properties_gesture_circle(ot);
@@ -1181,7 +1180,7 @@ void GPENCIL_OT_select_box(wmOperatorType *ot)
ot->poll = gpencil_select_poll;
/* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA;
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
WM_operator_properties_gesture_box(ot);
@@ -1249,7 +1248,7 @@ void GPENCIL_OT_select_lasso(wmOperatorType *ot)
ot->cancel = WM_gesture_lasso_cancel;
/* flags */
- ot->flag = OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA;
+ ot->flag = OPTYPE_UNDO;
/* properties */
WM_operator_properties_select_operation(ot);
@@ -1469,7 +1468,7 @@ void GPENCIL_OT_select(wmOperatorType *ot)
ot->poll = gpencil_select_poll;
/* flag */
- ot->flag = OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA;
+ ot->flag = OPTYPE_UNDO;
/* properties */
WM_operator_properties_mouse_select(ot);
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 065c133bf97..a475e43755c 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -259,7 +259,7 @@ bGPdata *ED_gpencil_data_get_active_evaluated(const bContext *C)
ID *screen_id = (ID *)CTX_wm_screen(C);
ScrArea *sa = CTX_wm_area(C);
- const Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
Object *ob = CTX_data_active_object(C);
Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
@@ -548,7 +548,7 @@ void gp_point_conversion_init(bContext *C, GP_SpaceConversion *r_gsc)
if (sa->spacetype == SPACE_VIEW3D) {
wmWindow *win = CTX_wm_window(C);
Scene *scene = CTX_data_scene(C);
- struct Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ struct Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
View3D *v3d = (View3D *)CTX_wm_space_data(C);
RegionView3D *rv3d = ar->regiondata;
@@ -560,8 +560,7 @@ void gp_point_conversion_init(bContext *C, GP_SpaceConversion *r_gsc)
/* for camera view set the subrect */
if (rv3d->persp == RV3D_CAMOB) {
- ED_view3d_calc_camera_border(
- scene, CTX_data_depsgraph(C), ar, v3d, rv3d, &r_gsc->subrect_data, true);
+ ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &r_gsc->subrect_data, true);
r_gsc->subrect = &r_gsc->subrect_data;
}
}
@@ -929,7 +928,7 @@ void ED_gp_get_drawing_reference(
void ED_gpencil_project_stroke_to_view(bContext *C, bGPDlayer *gpl, bGPDstroke *gps)
{
Scene *scene = CTX_data_scene(C);
- Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
Object *ob = CTX_data_active_object(C);
bGPdata *gpd = (bGPdata *)ob->data;
GP_SpaceConversion gsc = {NULL};
@@ -1094,7 +1093,7 @@ void ED_gp_project_point_to_plane(const Scene *scene,
/* get a vector from the point with the current view direction of the viewport */
ED_view3d_global_to_vector(rv3d, &pt->x, vn);
- /* calculate line extrem point to create a ray that cross the plane */
+ /* calculate line extreme point to create a ray that cross the plane */
mul_v3_fl(vn, -50.0f);
add_v3_v3v3(ray, &pt->x, vn);
@@ -1740,7 +1739,7 @@ static void gp_brush_cursor_draw(bContext *C, int x, int y, void *customdata)
}
/* while drawing hide */
- if ((gpd->runtime.sbuffer_size > 0) &&
+ if ((gpd->runtime.sbuffer_used > 0) &&
((brush->gpencil_settings->flag & GP_BRUSH_STABILIZE_MOUSE) == 0) &&
((brush->gpencil_settings->flag & GP_BRUSH_STABILIZE_MOUSE_TEMP) == 0)) {
return;
@@ -2525,3 +2524,37 @@ void ED_gpencil_select_toggle_all(bContext *C, int action)
CTX_DATA_END;
}
}
+
+/* Ensure the SBuffer (while drawing stroke) size is enough to save all points of the stroke */
+tGPspoint *ED_gpencil_sbuffer_ensure(tGPspoint *buffer_array,
+ short *buffer_size,
+ short *buffer_used,
+ const bool clear)
+{
+ tGPspoint *p = NULL;
+
+ /* By default a buffer is created with one block with a predefined number of free points,
+ * if the size is not enough, the cache is reallocated adding a new block of free points.
+ * This is done in order to keep cache small and improve speed. */
+ if (*buffer_used + 1 > *buffer_size) {
+ if ((*buffer_size == 0) || (buffer_array == NULL)) {
+ p = MEM_callocN(sizeof(struct tGPspoint) * GP_STROKE_BUFFER_CHUNK, "GPencil Sbuffer");
+ *buffer_size = GP_STROKE_BUFFER_CHUNK;
+ }
+ else {
+ *buffer_size += GP_STROKE_BUFFER_CHUNK;
+ p = MEM_recallocN(buffer_array, sizeof(struct tGPspoint) * *buffer_size);
+ }
+ buffer_array = p;
+ }
+
+ /* clear old data */
+ if (clear) {
+ *buffer_used = 0;
+ if (buffer_array != NULL) {
+ memset(buffer_array, 0, sizeof(tGPspoint) * *buffer_size);
+ }
+ }
+
+ return buffer_array;
+}