diff options
author | Antonioya <blendergit@gmail.com> | 2018-08-26 17:39:01 +0300 |
---|---|---|
committer | Antonioya <blendergit@gmail.com> | 2018-08-26 17:40:06 +0300 |
commit | 1948681440c011ae3008cd5d2a575eb6d45dc7ec (patch) | |
tree | c1ae82fe27da01caf3efdeab5d99a6b6e30950d8 /source/blender/editors/gpencil/gpencil_paint.c | |
parent | 85aafba04c18a849eda08fe3f7d46a515ba455d6 (diff) |
GP: Reduce weight paint data memory footprint
Before, the weight data array was created always, but now only is added when a weight value is assigned.
This change was suggested by algorithm, and both agreed it was good idea.
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_paint.c')
-rw-r--r-- | source/blender/editors/gpencil/gpencil_paint.c | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index b50624d07d2..aa163e02cfe 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -758,13 +758,16 @@ static short gp_stroke_addpoint( /* first time point is adding to temporary buffer -- need to allocate new point in stroke */ if (gpd->runtime.sbuffer_size == 0) { gps->points = MEM_reallocN(gps->points, sizeof(bGPDspoint) * (gps->totpoints + 1)); - gps->dvert = MEM_reallocN(gps->dvert, sizeof(MDeformVert) * (gps->totpoints + 1)); + if (gps->dvert != NULL) { + gps->dvert = MEM_reallocN(gps->dvert, sizeof(MDeformVert) * (gps->totpoints + 1)); + } gps->totpoints++; } pts = &gps->points[gps->totpoints - 1]; - dvert = &gps->dvert[gps->totpoints - 1]; - + if (gps->dvert != NULL) { + dvert = &gps->dvert[gps->totpoints - 1]; + } /* special case for poly lines: normally, * depth is needed only when creating new stroke from buffer, * but poly lines are converting to stroke instantly, @@ -789,8 +792,10 @@ static short gp_stroke_addpoint( pts->uv_fac = pt->uv_fac; pts->uv_rot = pt->uv_rot; - dvert->totweight = 0; - dvert->dw = NULL; + if (gps->dvert != NULL) { + dvert->totweight = 0; + dvert->dw = NULL; + } /* force fill recalc */ gps->flag |= GP_STROKE_RECALC_CACHES; @@ -895,7 +900,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) bGPDstroke *gps; bGPDspoint *pt; tGPspoint *ptc; - MDeformVert *dvert; + MDeformVert *dvert = NULL; Brush *brush = p->brush; ToolSettings *ts = p->scene->toolsettings; Depsgraph *depsgraph = p->depsgraph; @@ -949,7 +954,6 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) const int subdivide = brush->gpencil_settings->draw_subdivide; gps->points = MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "gp_stroke_points"); - gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights"); /* initialize triangle memory to dummy data */ gps->triangles = MEM_callocN(sizeof(bGPDtriangle), "GP Stroke triangulation"); @@ -959,7 +963,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) gp_update_cache(p->gpd); /* set pointer to first non-initialized point */ pt = gps->points + (gps->totpoints - totelem); - dvert = gps->dvert + (gps->totpoints - totelem); + if (gps->dvert != NULL) { + dvert = gps->dvert + (gps->totpoints - totelem); + } /* copy points from the buffer to the stroke */ if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) { @@ -975,12 +981,14 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) pt->strength = ptc->strength; CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); pt->time = ptc->time; + pt++; - dvert->totweight = 0; - dvert->dw = NULL; + if (dvert != NULL) { + dvert->totweight = 0; + dvert->dw = NULL; - pt++; - dvert++; + dvert++; + } } if (totelem == 2) { @@ -995,8 +1003,10 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); pt->time = ptc->time; - dvert->totweight = 0; - dvert->dw = NULL; + if (dvert != NULL) { + dvert->totweight = 0; + dvert->dw = NULL; + } } /* reproject to plane (only in 3d space) */ @@ -1023,9 +1033,10 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); pt->time = ptc->time; - dvert->totweight = 0; - dvert->dw = NULL; - + if (dvert != NULL) { + dvert->totweight = 0; + dvert->dw = NULL; + } } else { float *depth_arr = NULL; |