Mesh: move runtime members to own struct

This commit is contained in:
Campbell Barton 2018-05-02 15:47:45 +02:00
parent 5659d8bc0a
commit 9e477bdf63
5 changed files with 38 additions and 32 deletions

View File

@ -2488,7 +2488,7 @@ static void editbmesh_calc_modifiers(
struct Mesh *mesh = ob->data;
if (mesh->id.tag & LIB_TAG_COPY_ON_WRITE) {
BKE_mesh_ensure_edit_data(mesh);
mesh->emd->vertexCos = MEM_dupallocN(deformedVerts);
mesh->runtime.edit_data->vertexCos = MEM_dupallocN(deformedVerts);
}
*r_cage = getEditDerivedBMesh(
em, ob, mask,
@ -2530,9 +2530,9 @@ static void editbmesh_calc_modifiers(
struct Mesh *mesh = ob->data;
if (mesh->id.tag & LIB_TAG_COPY_ON_WRITE) {
BKE_mesh_ensure_edit_data(mesh);
if (mesh->emd->vertexCos != NULL)
MEM_freeN((void *)mesh->emd->vertexCos);
mesh->emd->vertexCos = MEM_dupallocN(deformedVerts);
if (mesh->runtime.edit_data->vertexCos != NULL)
MEM_freeN((void *)mesh->runtime.edit_data->vertexCos);
mesh->runtime.edit_data->vertexCos = MEM_dupallocN(deformedVerts);
}
*r_final = getEditDerivedBMesh(em, ob, dataMask, deformedVerts);
deformedVerts = NULL;

View File

@ -392,30 +392,30 @@ void BKE_mesh_ensure_skin_customdata(Mesh *me)
bool BKE_mesh_ensure_edit_data(struct Mesh *me)
{
if (me->emd != NULL) {
if (me->runtime.edit_data != NULL) {
return false;
}
me->emd = MEM_callocN(sizeof(EditMeshData), "EditMeshData");
me->runtime.edit_data = MEM_callocN(sizeof(EditMeshData), "EditMeshData");
return true;
}
bool BKE_mesh_clear_edit_data(struct Mesh *me)
{
if (me->emd == NULL) {
if (me->runtime.edit_data == NULL) {
return false;
}
if (me->emd->polyCos != NULL)
MEM_freeN((void *)me->emd->polyCos);
if (me->emd->polyNos != NULL)
MEM_freeN((void *)me->emd->polyNos);
if (me->emd->vertexCos != NULL)
MEM_freeN((void *)me->emd->vertexCos);
if (me->emd->vertexNos != NULL)
MEM_freeN((void *)me->emd->vertexNos);
if (me->runtime.edit_data->polyCos != NULL)
MEM_freeN((void *)me->runtime.edit_data->polyCos);
if (me->runtime.edit_data->polyNos != NULL)
MEM_freeN((void *)me->runtime.edit_data->polyNos);
if (me->runtime.edit_data->vertexCos != NULL)
MEM_freeN((void *)me->runtime.edit_data->vertexCos);
if (me->runtime.edit_data->vertexNos != NULL)
MEM_freeN((void *)me->runtime.edit_data->vertexNos);
MEM_SAFE_FREE(me->emd);
MEM_SAFE_FREE(me->runtime.edit_data);
return true;
}
@ -602,7 +602,7 @@ void BKE_mesh_copy_data(Main *bmain, Mesh *me_dst, const Mesh *me_src, const int
BKE_mesh_update_customdata_pointers(me_dst, do_tessface);
me_dst->edit_btmesh = NULL;
me_dst->batch_cache = NULL;
me_dst->runtime.batch_cache = NULL;
me_dst->mselect = MEM_dupallocN(me_dst->mselect);
me_dst->bb = MEM_dupallocN(me_dst->bb);
@ -2755,13 +2755,13 @@ void (*BKE_mesh_batch_cache_free_cb)(Mesh *me) = NULL;
void BKE_mesh_batch_cache_dirty(Mesh *me, int mode)
{
if (me->batch_cache) {
if (me->runtime.batch_cache) {
BKE_mesh_batch_cache_dirty_cb(me, mode);
}
}
void BKE_mesh_batch_cache_free(Mesh *me)
{
if (me->batch_cache) {
if (me->runtime.batch_cache) {
BKE_mesh_batch_cache_free_cb(me);
}
}

View File

@ -4676,7 +4676,7 @@ static void direct_link_mesh(FileData *fd, Mesh *mesh)
mesh->bb = NULL;
mesh->edit_btmesh = NULL;
mesh->batch_cache = NULL;
mesh->runtime.batch_cache = NULL;
/* happens with old files */
if (mesh->mselect == NULL) {

View File

@ -391,7 +391,7 @@ static MeshRenderData *mesh_render_data_create_ex(
BMesh *bm = embm->bm;
rdata->edit_bmesh = embm;
rdata->edit_data = me->emd;
rdata->edit_data = me->runtime.edit_data;
int bm_ensure_types = 0;
if (types & (MR_DATATYPE_VERT)) {
@ -1582,7 +1582,7 @@ typedef struct MeshBatchCache {
static bool mesh_batch_cache_valid(Mesh *me)
{
MeshBatchCache *cache = me->batch_cache;
MeshBatchCache *cache = me->runtime.batch_cache;
if (cache == NULL) {
return false;
@ -1623,10 +1623,10 @@ static bool mesh_batch_cache_valid(Mesh *me)
static void mesh_batch_cache_init(Mesh *me)
{
MeshBatchCache *cache = me->batch_cache;
MeshBatchCache *cache = me->runtime.batch_cache;
if (!cache) {
cache = me->batch_cache = MEM_callocN(sizeof(*cache), __func__);
cache = me->runtime.batch_cache = MEM_callocN(sizeof(*cache), __func__);
}
else {
memset(cache, 0, sizeof(*cache));
@ -1653,12 +1653,12 @@ static MeshBatchCache *mesh_batch_cache_get(Mesh *me)
mesh_batch_cache_clear(me);
mesh_batch_cache_init(me);
}
return me->batch_cache;
return me->runtime.batch_cache;
}
void DRW_mesh_batch_cache_dirty(Mesh *me, int mode)
{
MeshBatchCache *cache = me->batch_cache;
MeshBatchCache *cache = me->runtime.batch_cache;
if (cache == NULL) {
return;
}
@ -1704,7 +1704,7 @@ void DRW_mesh_batch_cache_dirty(Mesh *me, int mode)
**/
static void mesh_batch_cache_clear_selective(Mesh *me, Gwn_VertBuf *vert)
{
MeshBatchCache *cache = me->batch_cache;
MeshBatchCache *cache = me->runtime.batch_cache;
if (!cache) {
return;
}
@ -1741,7 +1741,7 @@ static void mesh_batch_cache_clear_selective(Mesh *me, Gwn_VertBuf *vert)
static void mesh_batch_cache_clear(Mesh *me)
{
MeshBatchCache *cache = me->batch_cache;
MeshBatchCache *cache = me->runtime.batch_cache;
if (!cache) {
return;
}
@ -1820,7 +1820,7 @@ static void mesh_batch_cache_clear(Mesh *me)
void DRW_mesh_batch_cache_free(Mesh *me)
{
mesh_batch_cache_clear(me);
MEM_SAFE_FREE(me->batch_cache);
MEM_SAFE_FREE(me->runtime.batch_cache);
}
/* Gwn_Batch cache usage. */
@ -3959,7 +3959,7 @@ Gwn_Batch *DRW_mesh_batch_cache_get_weight_overlay_verts(Mesh *me)
*/
void DRW_mesh_cache_sculpt_coords_ensure(Mesh *me)
{
if (me->batch_cache) {
if (me->runtime.batch_cache) {
MeshBatchCache *cache = mesh_batch_cache_get(me);
if (cache && cache->pos_with_normals && cache->is_sculpt_points_tag) {
/* XXX Force update of all the batches that contains the pos_with_normals buffer.

View File

@ -65,6 +65,12 @@ typedef struct EditMeshData {
const float (*polyCos)[3];
} EditMeshData;
/* not saved in file! */
typedef struct MeshRuntime {
struct EditMeshData *edit_data;
void *batch_cache;
} MeshRuntime;
typedef struct Mesh {
ID id;
struct AnimData *adt; /* animation data (must be immediately after id for utilities to use it) */
@ -100,7 +106,6 @@ typedef struct Mesh {
/* When the object is available, the preferred access method is: BKE_editmesh_from_object(ob) */
struct BMEditMesh *edit_btmesh; /* not saved in file! */
struct EditMeshData *emd; /* not saved in file! */
struct CustomData vdata, edata, fdata;
@ -140,7 +145,8 @@ typedef struct Mesh {
short totcol;
struct Multires *mr DNA_DEPRECATED; /* deprecated multiresolution modeling data, only keep for loading old files */
void *batch_cache;
MeshRuntime runtime;
} Mesh;
/* deprecated by MTFace, only here for file reading */