bmesh: move internal API flags out of BMFlagLayer, into BMHeader which was being padded up anyway, added static assert to make sure it stays <=16 bytes.

This commit is contained in:
Campbell Barton
2012-11-18 10:17:07 +00:00
parent fd9dac77d1
commit 42ebc9bc80
6 changed files with 43 additions and 25 deletions

View File

@@ -48,6 +48,8 @@ struct Object;
* hrm. it doesn't but stull works ok, remove the comment above? - campbell.
*/
// #pragma GCC diagnostic error "-Wpadded"
/**
* BMHeader
*
@@ -69,10 +71,19 @@ typedef struct BMHeader {
* this is abused by various tools which set it dirty.
* - For loops this is used for sorting during tessellation. */
char htype; /* element geometric type (verts/edges/loops/faces) */
char hflag; /* this would be a CD layer, see below */
char htype; /* element geometric type (verts/edges/loops/faces) */
char hflag; /* this would be a CD layer, see below */
/* internal use only!
* note,.we are very picky about not bloating this struct
* but in this case its padded up to 16 bytes anyway,
* so adding a flag here gives no increase in size */
char api_flag;
// char _pad;
} BMHeader;
BLI_STATIC_ASSERT((sizeof(BMHeader) <= 16), "BMHeader size has grown!");
/* note: need some way to specify custom locations for custom data layers. so we can
* make them point directly into structs. and some way to make it only happen to the
* active layer, and properly update when switching active layers.*/
@@ -142,21 +153,24 @@ typedef struct BMFace {
BMHeader head;
struct BMFlagLayer *oflags; /* an array of flags, mostly used by the operator stack */
int len; /*includes all boundary loops*/
#ifdef USE_BMESH_HOLES
int totbounds; /*total boundaries, is one plus the number of holes in the face*/
ListBase loops;
#else
BMLoop *l_first;
#endif
float no[3]; /*yes, we do store this here*/
int len; /* includes all boundary loops */
float no[3]; /* yes, we do store this here */
short mat_nr;
// short _pad[3];
} BMFace;
typedef struct BMFlagLayer {
short f, pflag; /* flags */
short f; /* flags */
} BMFlagLayer;
// #pragma GCC diagnostic ignored "-Wpadded"
typedef struct BMesh {
int totvert, totedge, totloop, totface;
int totvertsel, totedgesel, totfacesel;
@@ -166,7 +180,7 @@ typedef struct BMesh {
* valid flags are - BM_VERT | BM_EDGE | BM_FACE.
* BM_LOOP isn't handled so far. */
char elem_index_dirty;
/*element pools*/
struct BLI_mempool *vpool, *epool, *lpool, *fpool;
@@ -192,7 +206,7 @@ typedef struct BMesh {
int walkers, totflags;
ListBase selected, error_stack;
BMFace *act_face;
ListBase errorstack;

View File

@@ -187,8 +187,10 @@ BMFace *BM_face_create_ngon(BMesh *bm, BMVert *v1, BMVert *v2, BMEdge **edges, i
* _and_ the old bmesh_mf functions, so its kindof smashed together
* - joeedh */
if (!len || !v1 || !v2 || !edges || !bm)
if (!len || !v1 || !v2 || !edges || !bm) {
BLI_assert(0);
return NULL;
}
/* put edges in correct order */
for (i = 0; i < len; i++) {

View File

@@ -1068,18 +1068,21 @@ static void bmo_flag_layer_alloc(BMesh *bm)
ele->oflags = BLI_mempool_calloc(newpool);
memcpy(ele->oflags, oldflags, old_totflags_size);
BM_elem_index_set(ele, i); /* set_inline */
BM_ELEM_API_FLAG_CLEAR((BMElemF *)ele);
}
BM_ITER_MESH_INDEX (ele, &iter, bm, BM_EDGES_OF_MESH, i) {
oldflags = ele->oflags;
ele->oflags = BLI_mempool_calloc(newpool);
memcpy(ele->oflags, oldflags, old_totflags_size);
BM_elem_index_set(ele, i); /* set_inline */
BM_ELEM_API_FLAG_CLEAR((BMElemF *)ele);
}
BM_ITER_MESH_INDEX (ele, &iter, bm, BM_FACES_OF_MESH, i) {
oldflags = ele->oflags;
ele->oflags = BLI_mempool_calloc(newpool);
memcpy(ele->oflags, oldflags, old_totflags_size);
BM_elem_index_set(ele, i); /* set_inline */
BM_ELEM_API_FLAG_CLEAR((BMElemF *)ele);
}
bm->elem_index_dirty &= ~(BM_VERT | BM_EDGE | BM_FACE);
@@ -1113,18 +1116,21 @@ static void bmo_flag_layer_free(BMesh *bm)
ele->oflags = BLI_mempool_calloc(newpool);
memcpy(ele->oflags, oldflags, new_totflags_size);
BM_elem_index_set(ele, i); /* set_inline */
BM_ELEM_API_FLAG_CLEAR((BMElemF *)ele);
}
BM_ITER_MESH_INDEX (ele, &iter, bm, BM_EDGES_OF_MESH, i) {
oldflags = ele->oflags;
ele->oflags = BLI_mempool_calloc(newpool);
memcpy(ele->oflags, oldflags, new_totflags_size);
BM_elem_index_set(ele, i); /* set_inline */
BM_ELEM_API_FLAG_CLEAR((BMElemF *)ele);
}
BM_ITER_MESH_INDEX (ele, &iter, bm, BM_FACES_OF_MESH, i) {
oldflags = ele->oflags;
ele->oflags = BLI_mempool_calloc(newpool);
memcpy(ele->oflags, oldflags, new_totflags_size);
BM_elem_index_set(ele, i); /* set_inline */
BM_ELEM_API_FLAG_CLEAR((BMElemF *)ele);
}
bm->elem_index_dirty &= ~(BM_VERT | BM_EDGE | BM_FACE);

View File

@@ -62,9 +62,10 @@ int bmesh_disk_count(BMVert *v);
#define _FLAG_MF 2 /* make face */
#define _FLAG_MV 2 /* make face, vertex */
#define BM_ELEM_API_FLAG_ENABLE(element, f) ((element)->oflags[0].pflag |= (f))
#define BM_ELEM_API_FLAG_DISABLE(element, f) ((element)->oflags[0].pflag &= ~(f))
#define BM_ELEM_API_FLAG_TEST(element, f) ((element)->oflags[0].pflag & (f))
#define BM_ELEM_API_FLAG_ENABLE(element, f) ((element)->head.api_flag |= (f))
#define BM_ELEM_API_FLAG_DISABLE(element, f) ((element)->head.api_flag &= ~(f))
#define BM_ELEM_API_FLAG_TEST(element, f) ((element)->head.api_flag & (f))
#define BM_ELEM_API_FLAG_CLEAR(element) ((element)->head.api_flag = 0)
void calc_poly_plane(float (*verts)[3], const int nverts);
void poly_rotate_plane(const float normal[3], float (*verts)[3], const int nverts);

View File

@@ -252,22 +252,19 @@ static BMFace *bev_create_ngon(BMesh *bm, BMVert **vert_arr, int totv, BMFace *f
BMFace *f;
if (totv == 3) {
f = BM_face_create_quad_tri(bm,
vert_arr[0], vert_arr[1], vert_arr[2], NULL, facerep, 0);
f = BM_face_create_quad_tri_v(bm, vert_arr, 3, facerep, 0);
}
else if (totv == 4) {
f = BM_face_create_quad_tri(bm,
vert_arr[0], vert_arr[1], vert_arr[2], vert_arr[3], facerep, 0);
f = BM_face_create_quad_tri_v(bm, vert_arr, 4, facerep, 0);
}
else {
int i;
BMEdge *e;
BMEdge **ee = NULL;
BLI_array_staticdeclare(ee, 30);
BLI_array_staticdeclare(ee, BM_DEFAULT_NGON_STACK_SIZE);
BLI_array_grow_items(ee, totv);
for (i = 0; i < totv; i++) {
e = BM_edge_create(bm, vert_arr[i], vert_arr[(i + 1) % totv], NULL, TRUE);
BLI_array_append(ee, e);
ee[i] = BM_edge_create(bm, vert_arr[i], vert_arr[(i + 1) % totv], NULL, TRUE);
}
f = BM_face_create_ngon(bm, vert_arr[0], vert_arr[1], ee, totv, FALSE);
BLI_array_free(ee);

View File

@@ -111,7 +111,7 @@ static DerivedMesh *applyModifier(ModifierData *md, struct Object *UNUSED(ob),
BMIter iter;
BMEdge *e;
BevelModifierData *bmd = (BevelModifierData *) md;
float threshold = cosf((bmd->bevel_angle + 0.00001f) * (float)M_PI / 180.0f);
const float threshold = cosf((bmd->bevel_angle + 0.00001f) * (float)M_PI / 180.0f);
const int segments = 16; /* XXX */
bm = DM_to_bmesh(dm);
@@ -119,11 +119,9 @@ static DerivedMesh *applyModifier(ModifierData *md, struct Object *UNUSED(ob),
if (bmd->lim_flags & BME_BEVEL_ANGLE) {
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
/* check for 1 edge having 2 face users */
BMLoop *l1, *l2;
if ((l1 = e->l) &&
(l2 = e->l->radial_next) != l1)
{
if (dot_v3v3(l1->f->no, l2->f->no) < threshold) {
BMLoop *l_a, *l_b;
if (BM_edge_loop_pair(e, &l_a, &l_b)) {
if (dot_v3v3(l_a->f->no, l_b->f->no) < threshold) {
BM_elem_flag_enable(e, BM_ELEM_TAG);
BM_elem_flag_enable(e->v1, BM_ELEM_TAG);
BM_elem_flag_enable(e->v2, BM_ELEM_TAG);