Tag object-data level boundbox as invalid rather than freeing it

Object update used to free object-data level bounding box to trigger
it's re-calculation in the future. Such a freeing performed from
object update isn't thread-safe because mesh could be shared between
multiple objects.

Rather than freeing bounding box, tag it's as invalid, this is safe
from threading point of view and also prevents unnecessary memory
re-allocation.

Object-level bounding box is still reallocating, but think we could
change this easily in the future as well.

--
svn merge -r58154:58156 -r59258:59259 ^/branches/soc-2013-depsgraph_mt
This commit is contained in:
Sergey Sharybin
2013-08-19 09:58:28 +00:00
parent 2dcb1d7002
commit f030758515
8 changed files with 55 additions and 23 deletions

View File

@@ -70,7 +70,10 @@ void BKE_curve_make_local(struct Curve *cu);
short BKE_curve_type_get(struct Curve *cu);
void BKE_curve_type_test(struct Object *ob);
void BKE_curve_curve_dimension_update(struct Curve *cu);
struct BoundBox *BKE_curve_boundbox_get(struct Object *ob);
void BKE_curve_texspace_calc(struct Curve *cu);
void BKE_curve_texspace_get(struct Curve *cu, float r_loc[3], float r_rot[3], float r_size[3]);
bool BKE_curve_minmax(struct Curve *cu, float min[3], float max[3]);
bool BKE_curve_center_median(struct Curve *cu, float cent[3]);

View File

@@ -394,8 +394,34 @@ void BKE_curve_texspace_calc(Curve *cu)
if (cu->size[2] == 0.0f) cu->size[2] = 1.0f;
else if (cu->size[2] > 0.0f && cu->size[2] < 0.00001f) cu->size[2] = 0.00001f;
else if (cu->size[2] < 0.0f && cu->size[2] > -0.00001f) cu->size[2] = -0.00001f;
}
cu->bb->flag &= ~BOUNDBOX_DIRTY;
}
BoundBox *BKE_curve_boundbox_get(Object *ob)
{
Curve *cu = ob->data;
if (ob->bb)
return ob->bb;
if (cu->bb == NULL || (cu->bb->flag & BOUNDBOX_DIRTY)) {
BKE_curve_texspace_calc(cu);
}
return cu->bb;
}
void BKE_curve_texspace_get(Curve *cu, float r_loc[3], float r_rot[3], float r_size[3])
{
if (cu->bb == NULL || (cu->bb->flag & BOUNDBOX_DIRTY)) {
BKE_curve_texspace_calc(cu);
}
if (r_loc) copy_v3_v3(r_loc, cu->loc);
if (r_rot) copy_v3_v3(r_rot, cu->rot);
if (r_size) copy_v3_v3(r_size, cu->size);
}
int BKE_nurbList_index_get_co(ListBase *nurb, const int index, float r_co[3])

View File

@@ -657,6 +657,8 @@ void BKE_mesh_boundbox_calc(Mesh *me, float r_loc[3], float r_size[3])
r_size[2] = (max[2] - min[2]) / 2.0f;
BKE_boundbox_init_from_minmax(bb, min, max);
bb->flag &= ~BOUNDBOX_DIRTY;
}
void BKE_mesh_texspace_calc(Mesh *me)
@@ -686,15 +688,16 @@ BoundBox *BKE_mesh_boundbox_get(Object *ob)
if (ob->bb)
return ob->bb;
if (!me->bb)
if (me->bb == NULL || (me->bb->flag & BOUNDBOX_DIRTY)) {
BKE_mesh_texspace_calc(me);
}
return me->bb;
}
void BKE_mesh_texspace_get(Mesh *me, float r_loc[3], float r_rot[3], float r_size[3])
{
if (!me->bb) {
if (me->bb == NULL || (me->bb->flag & BOUNDBOX_DIRTY)) {
BKE_mesh_texspace_calc(me);
}

View File

@@ -259,8 +259,14 @@ void BKE_object_free_derived_caches(Object *ob)
Mesh *me = ob->data;
if (me->bb) {
MEM_freeN(me->bb);
me->bb = NULL;
me->bb->flag |= BOUNDBOX_DIRTY;
}
}
else if (ELEM3(ob->type, OB_SURF, OB_CURVE, OB_FONT)) {
Curve *cu = ob->data;
if (cu->bb) {
cu->bb->flag |= BOUNDBOX_DIRTY;
}
}
@@ -2384,18 +2390,7 @@ void BKE_object_minmax(Object *ob, float min_r[3], float max_r[3], const bool us
case OB_FONT:
case OB_SURF:
{
Curve *cu = ob->data;
/* Use the object bounding box so that modifier output
* gets taken into account */
if (ob->bb) {
bb = *(ob->bb);
}
else {
if (cu->bb == NULL)
BKE_curve_texspace_calc(cu);
bb = *(cu->bb);
}
bb = *BKE_curve_boundbox_get(ob);
for (a = 0; a < 8; a++) {
mul_m4_v3(ob->obmat, bb.vec[a]);

View File

@@ -2073,7 +2073,7 @@ static void draw_dupli_objects_color(Scene *scene, ARegion *ar, View3D *v3d, Bas
bb = *bb_tmp; /* must make a copy */
/* disable boundbox check for list creation */
BKE_object_boundbox_flag(dob->ob, OB_BB_DISABLED, 1);
BKE_object_boundbox_flag(dob->ob, BOUNDBOX_DISABLED, 1);
/* need this for next part of code */
unit_m4(dob->ob->obmat); /* obmat gets restored */
@@ -2083,7 +2083,7 @@ static void draw_dupli_objects_color(Scene *scene, ARegion *ar, View3D *v3d, Bas
glEndList();
use_displist = true;
BKE_object_boundbox_flag(dob->ob, OB_BB_DISABLED, 0);
BKE_object_boundbox_flag(dob->ob, BOUNDBOX_DISABLED, 0);
}
}
if (use_displist) {

View File

@@ -617,7 +617,7 @@ bool ED_view3d_boundbox_clip(RegionView3D *rv3d, float obmat[4][4], const BoundB
int a, flag = -1, fl;
if (bb == NULL) return true;
if (bb->flag & OB_BB_DISABLED) return true;
if (bb->flag & BOUNDBOX_DISABLED) return true;
mul_m4_m4m4(mat, rv3d->persmat, obmat);

View File

@@ -100,7 +100,10 @@ typedef struct BoundBox {
} BoundBox;
/* boundbox flag */
#define OB_BB_DISABLED 1
enum {
BOUNDBOX_DISABLED = (1 << 0),
BOUNDBOX_DIRTY = (1 << 1),
};
typedef struct Object {
ID id;

View File

@@ -575,8 +575,9 @@ static void rna_Mesh_texspace_size_get(PointerRNA *ptr, float values[3])
{
Mesh *me = (Mesh *)ptr->data;
if (!me->bb)
if (me->bb == NULL || (me->bb->flag & BOUNDBOX_DIRTY)) {
BKE_mesh_texspace_calc(me);
}
copy_v3_v3(values, me->size);
}
@@ -585,8 +586,9 @@ static void rna_Mesh_texspace_loc_get(PointerRNA *ptr, float values[3])
{
Mesh *me = (Mesh *)ptr->data;
if (!me->bb)
if (me->bb == NULL || (me->bb->flag & BOUNDBOX_DIRTY)) {
BKE_mesh_texspace_calc(me);
}
copy_v3_v3(values, me->loc);
}