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:
authorCampbell Barton <ideasman42@gmail.com>2012-11-18 16:14:22 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-11-18 16:14:22 +0400
commita9af5635264d8a143fb0902f2d8819b2a6f9f23c (patch)
tree527037a7cc100684228d8606117e0ab6fff866c1
parent317dff520c18ef7030e64534358a1861b89c8ed0 (diff)
bmesh: lazy initialize bmesh tool flag pool, has the advantage that modifiers that dont use bmesh operators can skip allocating it.
-rw-r--r--source/blender/bmesh/bmesh_class.h5
-rw-r--r--source/blender/bmesh/intern/bmesh_core.c32
-rw-r--r--source/blender/bmesh/intern/bmesh_mesh.c38
-rw-r--r--source/blender/bmesh/intern/bmesh_mesh.h5
-rw-r--r--source/blender/bmesh/intern/bmesh_operators.c10
-rw-r--r--source/blender/bmesh/operators/bmo_dupe.c4
-rw-r--r--source/blender/bmesh/tools/BME_bevel.c5
-rw-r--r--source/blender/editors/mesh/editmesh_tools.c2
-rw-r--r--source/blender/modifiers/intern/MOD_array.c1
-rw-r--r--source/blender/modifiers/intern/MOD_bevel.c2
-rw-r--r--source/blender/modifiers/intern/MOD_decimate.c1
-rw-r--r--source/blender/modifiers/intern/MOD_edgesplit.c5
12 files changed, 88 insertions, 22 deletions
diff --git a/source/blender/bmesh/bmesh_class.h b/source/blender/bmesh/bmesh_class.h
index bec184a7ca7..f9dbf51a629 100644
--- a/source/blender/bmesh/bmesh_class.h
+++ b/source/blender/bmesh/bmesh_class.h
@@ -133,7 +133,10 @@ typedef struct BMLoop {
/* can cast BMFace/BMEdge/BMVert, but NOT BMLoop, since these don't have a flag layer */
typedef struct BMElemF {
BMHeader head;
- struct BMFlagLayer *oflags; /* keep after header, an array of flags, mostly used by the operator stack */
+
+ /* keep directly after header,
+ * optional array of flags, only used by the operator stack */
+ struct BMFlagLayer *oflags;
} BMElemF;
/* can cast anything to this, including BMLoop */
diff --git a/source/blender/bmesh/intern/bmesh_core.c b/source/blender/bmesh/intern/bmesh_core.c
index c427734f58d..d4539050147 100644
--- a/source/blender/bmesh/intern/bmesh_core.c
+++ b/source/blender/bmesh/intern/bmesh_core.c
@@ -76,7 +76,9 @@ BMVert *BM_vert_create(BMesh *bm, const float co[3], const BMVert *example)
}
/* allocate flag */
- v->oflags = BLI_mempool_calloc(bm->toolflagpool);
+ if (bm->toolflagpool) {
+ v->oflags = BLI_mempool_calloc(bm->toolflagpool);
+ }
CustomData_bmesh_set_default(&bm->vdata, &v->head.data);
@@ -125,7 +127,9 @@ BMEdge *BM_edge_create(BMesh *bm, BMVert *v1, BMVert *v2, const BMEdge *example,
e->head.htype = BM_EDGE;
/* allocate flag */
- e->oflags = BLI_mempool_calloc(bm->toolflagpool);
+ if (bm->toolflagpool) {
+ e->oflags = BLI_mempool_calloc(bm->toolflagpool);
+ }
e->v1 = v1;
e->v2 = v2;
@@ -278,7 +282,9 @@ BLI_INLINE BMFace *bm_face_create__internal(BMesh *bm)
f->head.htype = BM_FACE;
/* allocate flag */
- f->oflags = BLI_mempool_calloc(bm->toolflagpool);
+ if (bm->toolflagpool) {
+ f->oflags = BLI_mempool_calloc(bm->toolflagpool);
+ }
CustomData_bmesh_set_default(&bm->pdata, &f->head.data);
@@ -495,7 +501,9 @@ static void bm_kill_only_vert(BMesh *bm, BMVert *v)
if (v->head.data)
CustomData_bmesh_free_block(&bm->vdata, &v->head.data);
- BLI_mempool_free(bm->toolflagpool, v->oflags);
+ if (bm->toolflagpool) {
+ BLI_mempool_free(bm->toolflagpool, v->oflags);
+ }
BLI_mempool_free(bm->vpool, v);
}
@@ -513,7 +521,9 @@ static void bm_kill_only_edge(BMesh *bm, BMEdge *e)
if (e->head.data)
CustomData_bmesh_free_block(&bm->edata, &e->head.data);
- BLI_mempool_free(bm->toolflagpool, e->oflags);
+ if (bm->toolflagpool) {
+ BLI_mempool_free(bm->toolflagpool, e->oflags);
+ }
BLI_mempool_free(bm->epool, e);
}
@@ -534,7 +544,9 @@ static void bm_kill_only_face(BMesh *bm, BMFace *f)
if (f->head.data)
CustomData_bmesh_free_block(&bm->pdata, &f->head.data);
- BLI_mempool_free(bm->toolflagpool, f->oflags);
+ if (bm->toolflagpool) {
+ BLI_mempool_free(bm->toolflagpool, f->oflags);
+ }
BLI_mempool_free(bm->fpool, f);
}
@@ -1773,14 +1785,18 @@ BMFace *bmesh_jfke(BMesh *bm, BMFace *f1, BMFace *f2, BMEdge *e)
bmesh_disk_edge_remove(f1loop->e, f1loop->e->v2);
/* deallocate edge and its two loops as well as f2 */
- BLI_mempool_free(bm->toolflagpool, f1loop->e->oflags);
+ if (bm->toolflagpool) {
+ BLI_mempool_free(bm->toolflagpool, f1loop->e->oflags);
+ }
BLI_mempool_free(bm->epool, f1loop->e);
bm->totedge--;
BLI_mempool_free(bm->lpool, f1loop);
bm->totloop--;
BLI_mempool_free(bm->lpool, f2loop);
bm->totloop--;
- BLI_mempool_free(bm->toolflagpool, f2->oflags);
+ if (bm->toolflagpool) {
+ BLI_mempool_free(bm->toolflagpool, f2->oflags);
+ }
BLI_mempool_free(bm->fpool, f2);
bm->totface--;
/* account for both above */
diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c
index d3e3bcd3556..062c47dc686 100644
--- a/source/blender/bmesh/intern/bmesh_mesh.c
+++ b/source/blender/bmesh/intern/bmesh_mesh.c
@@ -59,9 +59,37 @@ static void bm_mempool_init(BMesh *bm, const BMAllocTemplate *allocsize)
#ifdef USE_BMESH_HOLES
bm->looplistpool = BLI_mempool_create(sizeof(BMLoopList), 512, 512, 0);
#endif
+}
- /* allocate one flag pool that we don't get rid of. */
- bm->toolflagpool = BLI_mempool_create(sizeof(BMFlagLayer), 512, 512, 0);
+void BM_mesh_elem_toolflags_ensure(BMesh *bm)
+{
+ if (bm->toolflagpool == NULL) {
+ const int totflagpool_size = max_ii(512, bm->totvert + bm->totedge + bm->totface);
+ BLI_mempool *toolflagpool;
+
+ BMIter iter;
+ BMElemF *ele;
+ const char iter_types[3] = {BM_VERTS_OF_MESH,
+ BM_EDGES_OF_MESH,
+ BM_FACES_OF_MESH};
+
+ int i;
+
+ BLI_assert(bm->totflags == 0);
+
+ /* allocate one flag pool that we don't get rid of. */
+ toolflagpool = BLI_mempool_create(sizeof(BMFlagLayer), totflagpool_size, 512, 0);
+
+
+ for (i = 0; i < 3; i++) {
+ BM_ITER_MESH (ele, &iter, bm, iter_types[i]) {
+ ele->oflags = BLI_mempool_calloc(toolflagpool);
+ }
+ }
+
+ bm->toolflagpool = toolflagpool;
+ bm->totflags = 1;
+ }
}
/**
@@ -83,7 +111,7 @@ BMesh *BM_mesh_create(BMAllocTemplate *allocsize)
/* allocate one flag pool that we don't get rid of. */
bm->stackdepth = 1;
- bm->totflags = 1;
+ bm->totflags = 0;
CustomData_reset(&bm->vdata);
CustomData_reset(&bm->edata);
@@ -143,7 +171,9 @@ void BM_mesh_data_free(BMesh *bm)
BLI_mempool_destroy(bm->fpool);
/* destroy flag pool */
- BLI_mempool_destroy(bm->toolflagpool);
+ if (bm->toolflagpool) {
+ BLI_mempool_destroy(bm->toolflagpool);
+ }
#ifdef USE_BMESH_HOLES
BLI_mempool_destroy(bm->looplistpool);
diff --git a/source/blender/bmesh/intern/bmesh_mesh.h b/source/blender/bmesh/intern/bmesh_mesh.h
index 8b6ef9aa3e0..0dcd3fc2f01 100644
--- a/source/blender/bmesh/intern/bmesh_mesh.h
+++ b/source/blender/bmesh/intern/bmesh_mesh.h
@@ -29,6 +29,7 @@
struct BMAllocTemplate;
+void BM_mesh_elem_toolflags_ensure(BMesh *bm);
BMesh *BM_mesh_create(struct BMAllocTemplate *allocsize);
void BM_mesh_free(BMesh *bm);
@@ -58,4 +59,8 @@ typedef struct BMAllocTemplate {
extern BMAllocTemplate bm_mesh_allocsize_default;
extern BMAllocTemplate bm_mesh_chunksize_default;
+enum {
+ BM_MESH_CREATE_USE_TOOLFLAGS = (1 << 0)
+};
+
#endif /* __BMESH_MESH_H__ */
diff --git a/source/blender/bmesh/intern/bmesh_operators.c b/source/blender/bmesh/intern/bmesh_operators.c
index 4c2b353b258..8f38e1c9ba2 100644
--- a/source/blender/bmesh/intern/bmesh_operators.c
+++ b/source/blender/bmesh/intern/bmesh_operators.c
@@ -101,6 +101,8 @@ void BMO_push(BMesh *bm, BMOperator *UNUSED(op))
{
bm->stackdepth++;
+ BLI_assert(bm->totflags > 0);
+
/* add flag layer, if appropriate */
if (bm->stackdepth > 1)
bmo_flag_layer_alloc(bm);
@@ -172,7 +174,9 @@ void BMO_op_init(BMesh *bm, BMOperator *op, const int flag, const char *opname)
*/
void BMO_op_exec(BMesh *bm, BMOperator *op)
{
-
+ /* allocate tool flags on demand */
+ BM_mesh_elem_toolflags_ensure(bm);
+
BMO_push(bm, op);
if (bm->stackdepth == 2)
@@ -1056,7 +1060,9 @@ static void bmo_flag_layer_alloc(BMesh *bm)
/* store memcpy size for reuse */
const size_t old_totflags_size = (bm->totflags * sizeof(BMFlagLayer));
-
+
+ BLI_assert(oldpool != NULL);
+
bm->totflags++;
/* allocate new flag poo */
diff --git a/source/blender/bmesh/operators/bmo_dupe.c b/source/blender/bmesh/operators/bmo_dupe.c
index 32270007a0b..aa502203b50 100644
--- a/source/blender/bmesh/operators/bmo_dupe.c
+++ b/source/blender/bmesh/operators/bmo_dupe.c
@@ -181,7 +181,7 @@ static BMFace *copy_face(BMOperator *op, BMesh *source_mesh,
* Internal Copy function.
*/
-static void BKE_mesh_copy(BMOperator *op, BMesh *source, BMesh *target)
+static void bmo_mesh_copy(BMOperator *op, BMesh *source, BMesh *target)
{
BMVert *v = NULL, *v2;
@@ -326,7 +326,7 @@ void bmo_duplicate_exec(BMesh *bm, BMOperator *op)
BMO_slot_buffer_flag_enable(bm, dupeop, "geom", BM_ALL, DUPE_INPUT);
/* use the internal copy function */
- BKE_mesh_copy(dupeop, bm, bm2);
+ bmo_mesh_copy(dupeop, bm, bm2);
/* Output */
/* First copy the input buffers to output buffers - original data */
diff --git a/source/blender/bmesh/tools/BME_bevel.c b/source/blender/bmesh/tools/BME_bevel.c
index a632a4446ed..cdfd8372d61 100644
--- a/source/blender/bmesh/tools/BME_bevel.c
+++ b/source/blender/bmesh/tools/BME_bevel.c
@@ -1110,10 +1110,13 @@ BMesh *BME_bevel(BMesh *bm, float value, int res, int options, int defgrp_index,
td = BME_init_transdata(BLI_MEMARENA_STD_BUFSIZE);
/* recursion math courtesy of Martin Poirier (theeth) */
for (i = 0; i < res - 1; i++) {
- if (i == 0) fac += 1.0 / 3.0; else fac += 1.0 / (3.0 * i * 2.0);
+ if (i == 0) fac += 1.0 / 3.0;
+ else fac += 1.0 / (3.0 * i * 2.0);
}
d = 1.0 / fac;
+ BM_mesh_elem_toolflags_ensure(bm);
+
for (i = 0; i < res || (res == 0 && i == 0); i++) {
BMO_push(bm, NULL);
BME_bevel_initialize(bm, options, defgrp_index, angle, td);
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c
index e9fd2f142a2..57d6a9b3361 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -3006,6 +3006,8 @@ static int mesh_separate_tagged(Main *bmain, Scene *scene, Base *base_old, BMesh
BMesh *bm_new;
bm_new = BM_mesh_create(&bm_mesh_allocsize_default);
+ BM_mesh_elem_toolflags_ensure(bm_new); /* needed for 'duplicate' bmo */
+
CustomData_copy(&bm_old->vdata, &bm_new->vdata, CD_MASK_BMESH, CD_CALLOC, 0);
CustomData_copy(&bm_old->edata, &bm_new->edata, CD_MASK_BMESH, CD_CALLOC, 0);
CustomData_copy(&bm_old->ldata, &bm_new->ldata, CD_MASK_BMESH, CD_CALLOC, 0);
diff --git a/source/blender/modifiers/intern/MOD_array.c b/source/blender/modifiers/intern/MOD_array.c
index b9dd37ac50c..8ddae9f3c57 100644
--- a/source/blender/modifiers/intern/MOD_array.c
+++ b/source/blender/modifiers/intern/MOD_array.c
@@ -408,6 +408,7 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
* cleaner way to do this. One possibility: a "mirror" BMOp would
* certainly help by compressing it all into one top-level BMOp that
* executes a lot of second-level BMOps. */
+ BM_mesh_elem_toolflags_ensure(bm);
BMO_push(bm, NULL);
bmesh_edit_begin(bm, 0);
diff --git a/source/blender/modifiers/intern/MOD_bevel.c b/source/blender/modifiers/intern/MOD_bevel.c
index cb63da659b2..59befe4db05 100644
--- a/source/blender/modifiers/intern/MOD_bevel.c
+++ b/source/blender/modifiers/intern/MOD_bevel.c
@@ -143,6 +143,8 @@ static DerivedMesh *applyModifier(ModifierData *md, struct Object *UNUSED(ob),
BM_mesh_bevel(bm, bmd->value, segments);
result = CDDM_from_bmesh(bm, TRUE);
+
+ BLI_assert(bm->toolflagpool == NULL); /* make sure we never alloc'd this */
BM_mesh_free(bm);
CDDM_calc_normals(result);
diff --git a/source/blender/modifiers/intern/MOD_decimate.c b/source/blender/modifiers/intern/MOD_decimate.c
index dc29e59d549..3f8eaa438c9 100644
--- a/source/blender/modifiers/intern/MOD_decimate.c
+++ b/source/blender/modifiers/intern/MOD_decimate.c
@@ -186,6 +186,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
/* update for display only */
dmd->face_count = bm->totface;
result = CDDM_from_bmesh(bm, FALSE);
+ BLI_assert(bm->toolflagpool == NULL); /* make sure we never alloc'd this */
BM_mesh_free(bm);
#ifdef USE_TIMEIT
diff --git a/source/blender/modifiers/intern/MOD_edgesplit.c b/source/blender/modifiers/intern/MOD_edgesplit.c
index 21717d07fef..ec81c5ce699 100644
--- a/source/blender/modifiers/intern/MOD_edgesplit.c
+++ b/source/blender/modifiers/intern/MOD_edgesplit.c
@@ -67,8 +67,7 @@ static DerivedMesh *doEdgeSplit(DerivedMesh *dm, EdgeSplitModifierData *emd, Obj
float threshold = cosf((emd->split_angle + 0.00001f) * (float)M_PI / 180.0f);
bm = DM_to_bmesh(dm);
-
- BMO_push(bm, NULL);
+ BM_mesh_elem_toolflags_ensure(bm);
if (emd->flags & MOD_EDGESPLIT_FROMANGLE) {
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
@@ -103,8 +102,6 @@ static DerivedMesh *doEdgeSplit(DerivedMesh *dm, EdgeSplitModifierData *emd, Obj
BMO_op_callf(bm, BMO_FLAG_DEFAULTS,
"split_edges edges=%fe", EDGE_MARK);
-
- BMO_pop(bm);
/* BM_mesh_validate(bm); */ /* for troubleshooting */