Refactor: Const correct Custom Data API, prepare for CoW

Currently you can retrieve a mutable array from a const CustomData.
That makes code unsafe since the compiler can't check for correctness
itself. Fix that by introducing a separate function to retrieve mutable
arrays from CustomData. The new functions have the `_for_write`
suffix that make the code's intention clearer.

Because it makes retrieving write access an explicit step, this change
also makes proper copy-on-write possible for attributes.

Notes:
- The previous "duplicate referenced layer" functions are redundant
  with retrieving layers with write access
- The custom data functions that give a specific index only have
  `for_write` to simplify the API

Differential Revision: https://developer.blender.org/D14140
This commit is contained in:
2023-01-13 17:21:20 -06:00
parent 4160da187c
commit 3a3d9488a1
76 changed files with 524 additions and 503 deletions

View File

@@ -421,12 +421,14 @@ void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *me, int id)
const float(*lnors)[3] = nullptr;
if (CustomData_has_layer(&me->ldata, CD_NORMAL)) {
lnors = (float(*)[3])CustomData_get_layer(&me->ldata, CD_NORMAL);
lnors = (const float(*)[3])CustomData_get_layer(&me->ldata, CD_NORMAL);
}
// Get other mesh data
const FreestyleEdge *fed = (FreestyleEdge *)CustomData_get_layer(&me->edata, CD_FREESTYLE_EDGE);
const FreestyleFace *ffa = (FreestyleFace *)CustomData_get_layer(&me->pdata, CD_FREESTYLE_FACE);
const FreestyleEdge *fed = (const FreestyleEdge *)CustomData_get_layer(&me->edata,
CD_FREESTYLE_EDGE);
const FreestyleFace *ffa = (const FreestyleFace *)CustomData_get_layer(&me->pdata,
CD_FREESTYLE_FACE);
// Compute view matrix
Object *ob_camera_eval = DEG_get_evaluated_object(_depsgraph, RE_GetCamera(_re));