[Bf-blender-cvs] [1948681440c] blender2.8: GP: Reduce weight paint data memory footprint
Antonioya
noreply at git.blender.org
Sun Aug 26 16:40:26 CEST 2018
Commit: 1948681440c011ae3008cd5d2a575eb6d45dc7ec
Author: Antonioya
Date: Sun Aug 26 16:39:01 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB1948681440c011ae3008cd5d2a575eb6d45dc7ec
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.
===================================================================
M source/blender/blenkernel/BKE_gpencil.h
M source/blender/blenkernel/intern/gpencil.c
M source/blender/blenkernel/intern/gpencil_modifier.c
M source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M source/blender/editors/gpencil/editaction_gpencil.c
M source/blender/editors/gpencil/gpencil_brush.c
M source/blender/editors/gpencil/gpencil_edit.c
M source/blender/editors/gpencil/gpencil_fill.c
M source/blender/editors/gpencil/gpencil_interpolate.c
M source/blender/editors/gpencil/gpencil_old.c
M source/blender/editors/gpencil/gpencil_paint.c
M source/blender/editors/gpencil/gpencil_primitive.c
M source/blender/editors/gpencil/gpencil_utils.c
M source/blender/editors/space_view3d/view3d_gizmo_ruler.c
M source/blender/editors/space_view3d/view3d_ruler.c
M source/blender/gpencil_modifiers/intern/MOD_gpencilbuild.c
M source/blender/makesrna/intern/rna_gpencil.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 19535f23cf2..9c352da15a0 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -151,6 +151,7 @@ struct BoundBox *BKE_gpencil_boundbox_get(struct Object *ob);
void BKE_gpencil_centroid_3D(struct bGPdata *gpd, float r_centroid[3]);
/* vertex groups */
+void BKE_gpencil_dvert_ensure(struct bGPDstroke *gps);
float BKE_gpencil_vgroup_use_index(struct MDeformVert *dvert, int index);
void BKE_gpencil_vgroup_remove(struct Object *ob, struct bDeformGroup *defgroup);
struct MDeformWeight *BKE_gpencil_vgroup_add_point_weight(struct MDeformVert *dvert, int index, float weight);
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 57494397f40..51731cb3e8e 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -519,7 +519,6 @@ bGPDstroke *BKE_gpencil_add_stroke(bGPDframe *gpf, int mat_idx, int totpoints, s
gps->totpoints = totpoints;
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");
@@ -573,8 +572,13 @@ bGPDstroke *BKE_gpencil_stroke_duplicate(bGPDstroke *gps_src)
gps_dst->points = MEM_dupallocN(gps_src->points);
- gps_dst->dvert = MEM_dupallocN(gps_src->dvert);
- BKE_gpencil_stroke_weights_duplicate(gps_src, gps_dst);
+ if (gps_src->dvert != NULL) {
+ gps_dst->dvert = MEM_dupallocN(gps_src->dvert);
+ BKE_gpencil_stroke_weights_duplicate(gps_src, gps_dst);
+ }
+ else {
+ gps_dst->dvert = NULL;
+ }
/* Don't clear triangles, so that modifier evaluation can just use
* this without extra work first. Most places that need to force
@@ -1253,6 +1257,13 @@ void BKE_gpencil_vgroup_remove(Object *ob, bDeformGroup *defgroup)
BLI_freelinkN(&ob->defbase, defgroup);
}
+
+void BKE_gpencil_dvert_ensure(bGPDstroke *gps)
+{
+ if (gps->dvert == NULL) {
+ gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights");
+ }
+}
/* add a new weight */
MDeformWeight *BKE_gpencil_vgroup_add_point_weight(MDeformVert *dvert, int index, float weight)
{
diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c b/source/blender/blenkernel/intern/gpencil_modifier.c
index 3b0c86a1832..fd1170c1a9c 100644
--- a/source/blender/blenkernel/intern/gpencil_modifier.c
+++ b/source/blender/blenkernel/intern/gpencil_modifier.c
@@ -220,8 +220,12 @@ static void gpencil_rdp_stroke(bGPDstroke *gps, vec2f *points2d, float epsilon)
/* adding points marked */
bGPDspoint *old_points = MEM_dupallocN(gps->points);
- MDeformVert *old_dvert = MEM_dupallocN(gps->dvert);
+ MDeformVert *old_dvert = NULL;
+ MDeformVert *dvert_src = NULL;
+ if (gps->dvert != NULL) {
+ old_dvert = MEM_dupallocN(gps->dvert);
+ }
/* resize gps */
gps->flag |= GP_STROKE_RECALC_CACHES;
gps->tot_triangles = 0;
@@ -231,16 +235,20 @@ static void gpencil_rdp_stroke(bGPDstroke *gps, vec2f *points2d, float epsilon)
bGPDspoint *pt_src = &old_points[i];
bGPDspoint *pt = &gps->points[j];
- MDeformVert *dvert_src = &old_dvert[i];
- MDeformVert *dvert = &gps->dvert[j];
-
if ((marked[i]) || (i == 0) || (i == totpoints - 1)) {
memcpy(pt, pt_src, sizeof(bGPDspoint));
- memcpy(dvert, dvert_src, sizeof(MDeformVert));
+ if (gps->dvert != NULL) {
+ dvert_src = &old_dvert[i];
+ MDeformVert *dvert = &gps->dvert[j];
+ memcpy(dvert, dvert_src, sizeof(MDeformVert));
+ }
j++;
}
else {
- BKE_gpencil_free_point_weights(dvert_src);
+ if (gps->dvert != NULL) {
+ dvert_src = &old_dvert[i];
+ BKE_gpencil_free_point_weights(dvert_src);
+ }
}
}
@@ -257,11 +265,6 @@ void BKE_gpencil_simplify_stroke(bGPDstroke *gps, float factor)
/* first create temp data and convert points to 2D */
vec2f *points2d = MEM_mallocN(sizeof(vec2f) * gps->totpoints, "GP Stroke temp 2d points");
- /* for some old files, the weights array could not be initializated */
- if (gps->dvert == NULL) {
- gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights");
- }
-
gpencil_stroke_project_2d(gps->points, gps->totpoints, points2d);
gpencil_rdp_stroke(gps, points2d, factor);
@@ -276,14 +279,14 @@ void BKE_gpencil_simplify_fixed(bGPDstroke *gps)
return;
}
- /* for some old files, the weights array could not be initializated */
- if (gps->dvert == NULL) {
- gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights");
- }
-
/* save points */
bGPDspoint *old_points = MEM_dupallocN(gps->points);
- MDeformVert *old_dvert = MEM_dupallocN(gps->dvert);
+ MDeformVert *old_dvert = NULL;
+ MDeformVert *dvert_src = NULL;
+
+ if (gps->dvert != NULL) {
+ old_dvert = MEM_dupallocN(gps->dvert);
+ }
/* resize gps */
int newtot = (gps->totpoints - 2) / 2;
@@ -293,7 +296,9 @@ void BKE_gpencil_simplify_fixed(bGPDstroke *gps)
newtot += 2;
gps->points = MEM_recallocN(gps->points, sizeof(*gps->points) * newtot);
- gps->dvert = MEM_recallocN(gps->dvert, sizeof(*gps->dvert) * newtot);
+ if (gps->dvert != NULL) {
+ gps->dvert = MEM_recallocN(gps->dvert, sizeof(*gps->dvert) * newtot);
+ }
gps->flag |= GP_STROKE_RECALC_CACHES;
gps->tot_triangles = 0;
@@ -302,16 +307,21 @@ void BKE_gpencil_simplify_fixed(bGPDstroke *gps)
bGPDspoint *pt_src = &old_points[i];
bGPDspoint *pt = &gps->points[j];
- MDeformVert *dvert_src = &old_dvert[i];
- MDeformVert *dvert = &gps->dvert[j];
if ((i == 0) || (i == gps->totpoints - 1) || ((i % 2) > 0.0)) {
memcpy(pt, pt_src, sizeof(bGPDspoint));
- memcpy(dvert, dvert_src, sizeof(MDeformVert));
+ if (gps->dvert != NULL) {
+ dvert_src = &old_dvert[i];
+ MDeformVert *dvert = &gps->dvert[j];
+ memcpy(dvert, dvert_src, sizeof(MDeformVert));
+ }
j++;
}
else {
- BKE_gpencil_free_point_weights(dvert_src);
+ if (gps->dvert != NULL) {
+ dvert_src = &old_dvert[i];
+ BKE_gpencil_free_point_weights(dvert_src);
+ }
}
}
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index 2102f255f75..3f185c4fbfc 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -499,10 +499,10 @@ GPUBatch *DRW_gpencil_get_edit_geom(bGPDstroke *gps, float alpha, short dflag)
int idx = 0;
float fcolor[4];
float fsize = 0;
- for (int i = 0; i < gps->totpoints; i++, pt++, dvert++) {
+ for (int i = 0; i < gps->totpoints; i++, pt++) {
/* weight paint */
if (is_weight_paint) {
- float weight = BKE_gpencil_vgroup_use_index(dvert, vgindex);
+ float weight = gps->dvert!= NULL ? BKE_gpencil_vgroup_use_index(dvert, vgindex) : 0;
CLAMP(weight, 0.0f, 1.0f);
float hue = 2.0f * (1.0f - weight) / 3.0f;
hsv_to_rgb(hue, 1.0f, 1.0f, &selectColor[0], &selectColor[1], &selectColor[2]);
@@ -535,6 +535,9 @@ GPUBatch *DRW_gpencil_get_edit_geom(bGPDstroke *gps, float alpha, short dflag)
GPU_vertbuf_attr_set(vbo, size_id, idx, &fsize);
GPU_vertbuf_attr_set(vbo, pos_id, idx, &pt->x);
idx++;
+ if (gps->dvert != NULL) {
+ dvert++;
+ }
}
return GPU_batch_create_ex(GPU_PRIM_POINTS, vbo, NULL, GPU_BATCH_OWNS_VBO);
@@ -571,22 +574,14 @@ GPUBatch *DRW_gpencil_get_edlin_geom(bGPDstroke *gps, float alpha, short UNUSED(
/* Draw all the stroke lines (selected or not) */
bGPDspoint *pt = gps->points;
-
- /* GPXX: for some converted files, this struct could be null
- * maybe we can remove this and move to versioning code after
- * merge */
- if (gps->dvert == NULL) {
- gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights");
- }
-
MDeformVert *dvert = gps->dvert;
int idx = 0;
float fcolor[4];
- for (int i = 0; i < gps->totpoints; i++, pt++, dvert++) {
+ for (int i = 0; i < gps->totpoints; i++, pt++) {
/* weight paint */
if (is_weight_paint) {
- float weight = BKE_gpencil_vgroup_use_index(dvert, vgindex);
+ float weight = gps->dvert != NULL ? BKE_gpencil_vgroup_use_index(dvert, vgindex) : 0;
CLAMP(weight, 0.0f, 1.0f);
float hue = 2.0f * (1.0f - weight) / 3.0f;
hsv_to_rgb(hue, 1.0f, 1.0f, &selectColor[0], &selectColor[1], &selectColor[2]);
@@ -605,6 +600,10 @@ GPUBatch *DRW_gpencil_get_edlin_geom(bGPDstroke *gps, float alpha, short UNUSED(
GPU_vertbuf_attr_set(vbo, color_id, idx, fcolor);
GPU_vertbuf_attr_set(vbo, pos_id, idx, &pt->x);
idx++;
+
+ if (gps->dvert != NULL) {
+ dvert++;
+ }
}
return GPU_batch_create_ex(GPU_PRIM_LINE_STRIP, vbo, NULL, GPU_BATCH_OWNS_VBO);
diff --git a/source/blender/editors/gpencil/editaction_gpencil.c b/source/blender/editors/gpencil/editaction_gpencil.c
index 88f935eb8bf..2c3159692bf 100644
--- a/source/blender/editors/gpencil/editaction_gpencil.c
+++ b/source/blender/editors/gpencil/editaction_gpencil.c
@@ -492,8 +492,10 @@ bool ED_gpencil_anim_copybuf_paste(bAnimContext *ac, const short offset_mode)
/* make a copy of stroke, then of its points array */
gpsn = MEM_dupallocN(gps);
gpsn->points = MEM_dupallocN(gps->points);
- gpsn->dvert = MEM_dupallocN(gps->dvert);
- BKE_gpencil_stroke_weights_duplicate(gps, gpsn);
+ if (gps->dvert != NULL) {
+ gpsn->dvert = MEM_dupallocN(gps->dvert);
+ BKE_gpencil_stroke_weights_duplicate(gps, gpsn);
+ }
/* duplicate triangle information */
gpsn->triangles = MEM_dupallocN(gps->triangles);
/* append stroke to frame */
diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c
index ddce148a3a3..4ab344c7861 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -876,6 +876,9 @@ static bool gp_brush_weight_apply(
tGP_BrushEditData *gso, bGPDstroke *gps, int pt_index,
const int radius, const int co[2])
{
+ /* create dvert */
+ BKE_gpencil
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list