[Bf-blender-cvs] [9efd3a3f637] blender2.8: Cleanup: move custom-data layers into a struct
Campbell Barton
noreply at git.blender.org
Mon May 22 09:21:38 CEST 2017
Commit: 9efd3a3f6371135eb0c8048286062396d1b3e104
Author: Campbell Barton
Date: Mon May 22 17:21:22 2017 +1000
Branches: blender2.8
https://developer.blender.org/rB9efd3a3f6371135eb0c8048286062396d1b3e104
Cleanup: move custom-data layers into a struct
Changed because the values co-exist with active layers
(Mesh.mloopuv, Mesh.mloopcol).
===================================================================
M source/blender/draw/intern/draw_cache_impl_mesh.c
===================================================================
diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c
index 22154eb5fb2..a01e1d4beff 100644
--- a/source/blender/draw/intern/draw_cache_impl_mesh.c
+++ b/source/blender/draw/intern/draw_cache_impl_mesh.c
@@ -129,47 +129,53 @@ typedef struct MeshRenderData {
MLoop *mloop;
MPoly *mpoly;
float (*orco)[3];
- MLoopUV **mloopuv;
- MLoopCol **mloopcol;
- float (**mtangent)[4];
MDeformVert *dvert;
- MLoopCol *loopcol;
+ MLoopCol *mloopcol;
+
+ /* CustomData 'cd' cache for efficient access. */
+ struct {
+ struct {
+ MLoopUV **uv;
+ int uv_len;
+ int uv_active;
+
+ MLoopCol **vcol;
+ int vcol_len;
+ int vcol_active;
+
+ float (**tangent)[4];
+ int tangent_active;
+
+ bool *auto_vcol;
+ } layers;
+
+ /* Custom-data offsets (only needed for BMesh access) */
+ struct {
+ int crease;
+ int bweight;
+ int *uv;
+ int *vcol;
+ } offset;
+
+ struct {
+ char (*auto_mix)[32];
+ char (*uv)[32];
+ char (*vcol)[32];
+ char (*tangent)[32];
+ } uuid;
+
+ /* for certain cases we need an output loop-data storage (bmesh tangents) */
+ struct {
+ CustomData ldata;
+ /* grr, special case variable (use in place of 'dm->tangent_mask') */
+ char tangent_mask;
+ } output;
+ } cd;
BMVert *eve_act;
BMEdge *eed_act;
BMFace *efa_act;
- int uv_len;
- int vcol_len;
-
- bool *auto_vcol;
-
- int uv_active;
- int vcol_active;
- int tangent_active;
-
- /* Custom-data offsets (only needed for BMesh access) */
- struct {
- int crease;
- int bweight;
- int *uv;
- int *vcol;
- } cd_offset;
-
- struct {
- char (*auto_mix)[32];
- char (*uv)[32];
- char (*vcol)[32];
- char (*tangent)[32];
- } cd_uuid;
-
- /* for certain cases we need an output loop-data storage (bmesh tangents) */
- struct {
- CustomData ldata;
- /* grr, special case variable (use in place of 'dm->tangent_mask') */
- char tangent_mask;
- } cd_output;
-
/* Data created on-demand (usually not for bmesh-based data). */
EdgeAdjacentPolys *edges_adjacent_polys;
MLoopTri *mlooptri;
@@ -232,7 +238,7 @@ static MeshRenderData *mesh_render_data_create(Mesh *me, const int types)
rdata->types = types;
rdata->mat_len = mesh_render_mat_len_get(me);
- CustomData_reset(&rdata->cd_output.ldata);
+ CustomData_reset(&rdata->cd.output.ldata);
if (me->edit_btmesh) {
BMEditMesh *embm = me->edit_btmesh;
@@ -265,8 +271,8 @@ static MeshRenderData *mesh_render_data_create(Mesh *me, const int types)
rdata->efa_act = BM_mesh_active_face_get(bm, false, true);
rdata->eed_act = BM_mesh_active_edge_get(bm);
rdata->eve_act = BM_mesh_active_vert_get(bm);
- rdata->cd_offset.crease = CustomData_get_offset(&bm->edata, CD_CREASE);
- rdata->cd_offset.bweight = CustomData_get_offset(&bm->edata, CD_BWEIGHT);
+ rdata->cd.offset.crease = CustomData_get_offset(&bm->edata, CD_CREASE);
+ rdata->cd.offset.bweight = CustomData_get_offset(&bm->edata, CD_BWEIGHT);
}
if (types & (MR_DATATYPE_DVERT)) {
bm_ensure_types |= BM_VERT;
@@ -340,7 +346,7 @@ static MeshRenderData *mesh_render_data_create(Mesh *me, const int types)
}
if (types & MR_DATATYPE_LOOPCOL) {
rdata->loop_len = me->totloop;
- rdata->loopcol = CustomData_get_layer(&me->ldata, CD_MLOOPCOL);
+ rdata->mloopcol = CustomData_get_layer(&me->ldata, CD_MLOOPCOL);
}
}
@@ -385,25 +391,25 @@ static MeshRenderData *mesh_render_data_create(Mesh *me, const int types)
#ifdef me /* quiet warning */
#endif
- rdata->uv_len = CustomData_number_of_layers(cd_ldata, CD_MLOOPUV);
- rdata->vcol_len = CustomData_number_of_layers(cd_ldata, CD_MLOOPCOL);
+ rdata->cd.layers.uv_len = CustomData_number_of_layers(cd_ldata, CD_MLOOPUV);
+ rdata->cd.layers.vcol_len = CustomData_number_of_layers(cd_ldata, CD_MLOOPCOL);
- rdata->mloopuv = MEM_mallocN(sizeof(*rdata->mloopuv) * rdata->uv_len, __func__);
- rdata->mloopcol = MEM_mallocN(sizeof(*rdata->mloopcol) * rdata->vcol_len, __func__);
- rdata->mtangent = MEM_mallocN(sizeof(*rdata->mtangent) * rdata->uv_len, __func__);
+ rdata->cd.layers.uv = MEM_mallocN(sizeof(*rdata->cd.layers.uv) * rdata->cd.layers.uv_len, __func__);
+ rdata->cd.layers.vcol = MEM_mallocN(sizeof(*rdata->cd.layers.vcol) * rdata->cd.layers.vcol_len, __func__);
+ rdata->cd.layers.tangent = MEM_mallocN(sizeof(*rdata->cd.layers.tangent) * rdata->cd.layers.uv_len, __func__);
- rdata->cd_uuid.uv = MEM_mallocN(sizeof(*rdata->cd_uuid.uv) * rdata->uv_len, __func__);
- rdata->cd_uuid.vcol = MEM_mallocN(sizeof(*rdata->cd_uuid.vcol) * rdata->vcol_len, __func__);
- rdata->cd_uuid.tangent = MEM_mallocN(sizeof(*rdata->cd_uuid.tangent) * rdata->uv_len, __func__);
+ rdata->cd.uuid.uv = MEM_mallocN(sizeof(*rdata->cd.uuid.uv) * rdata->cd.layers.uv_len, __func__);
+ rdata->cd.uuid.vcol = MEM_mallocN(sizeof(*rdata->cd.uuid.vcol) * rdata->cd.layers.vcol_len, __func__);
+ rdata->cd.uuid.tangent = MEM_mallocN(sizeof(*rdata->cd.uuid.tangent) * rdata->cd.layers.uv_len, __func__);
- rdata->cd_offset.uv = MEM_mallocN(sizeof(*rdata->cd_offset.uv) * rdata->uv_len, __func__);
- rdata->cd_offset.vcol = MEM_mallocN(sizeof(*rdata->cd_offset.vcol) * rdata->vcol_len, __func__);
+ rdata->cd.offset.uv = MEM_mallocN(sizeof(*rdata->cd.offset.uv) * rdata->cd.layers.uv_len, __func__);
+ rdata->cd.offset.vcol = MEM_mallocN(sizeof(*rdata->cd.offset.vcol) * rdata->cd.layers.vcol_len, __func__);
/* Allocate max */
- rdata->auto_vcol = MEM_callocN(
- sizeof(*rdata->auto_vcol) * rdata->vcol_len, __func__);
- rdata->cd_uuid.auto_mix = MEM_mallocN(
- sizeof(*rdata->cd_uuid.auto_mix) * (rdata->vcol_len + rdata->uv_len), __func__);
+ rdata->cd.layers.auto_vcol = MEM_callocN(
+ sizeof(*rdata->cd.layers.auto_vcol) * rdata->cd.layers.vcol_len, __func__);
+ rdata->cd.uuid.auto_mix = MEM_mallocN(
+ sizeof(*rdata->cd.uuid.auto_mix) * (rdata->cd.layers.vcol_len + rdata->cd.layers.uv_len), __func__);
/* XXX FIXME XXX */
/* We use a hash to identify each data layer based on its name.
@@ -412,56 +418,56 @@ static MeshRenderData *mesh_render_data_create(Mesh *me, const int types)
* One solution to hash collision would be to format the cd layer name
* to a safe glsl var name, but without name clash.
* NOTE 2 : Replicate changes to code_generate_vertex_new() in gpu_codegen.c */
- for (int i = 0; i < rdata->vcol_len; ++i) {
+ for (int i = 0; i < rdata->cd.layers.vcol_len; ++i) {
const char *name = CustomData_get_layer_name(cd_ldata, CD_MLOOPCOL, i);
unsigned int hash = BLI_ghashutil_strhash_p(name);
- BLI_snprintf(rdata->cd_uuid.vcol[i], sizeof(*rdata->cd_uuid.vcol), "c%u", hash);
- rdata->mloopcol[i] = CustomData_get_layer_n(cd_ldata, CD_MLOOPCOL, i);
+ BLI_snprintf(rdata->cd.uuid.vcol[i], sizeof(*rdata->cd.uuid.vcol), "c%u", hash);
+ rdata->cd.layers.vcol[i] = CustomData_get_layer_n(cd_ldata, CD_MLOOPCOL, i);
if (rdata->edit_bmesh) {
- rdata->cd_offset.vcol[i] = CustomData_get_n_offset(&rdata->edit_bmesh->bm->ldata, CD_MLOOPCOL, i);
+ rdata->cd.offset.vcol[i] = CustomData_get_n_offset(&rdata->edit_bmesh->bm->ldata, CD_MLOOPCOL, i);
}
/* Gather number of auto layers. */
/* We only do vcols that are not overridden by uvs */
if (CustomData_get_named_layer_index(cd_ldata, CD_MLOOPUV, name) == -1) {
BLI_snprintf(
- rdata->cd_uuid.auto_mix[rdata->uv_len + i],
- sizeof(*rdata->cd_uuid.auto_mix), "a%u", hash);
- rdata->auto_vcol[i] = true;
+ rdata->cd.uuid.auto_mix[rdata->cd.layers.uv_len + i],
+ sizeof(*rdata->cd.uuid.auto_mix), "a%u", hash);
+ rdata->cd.layers.auto_vcol[i] = true;
}
}
/* Start Fresh */
CustomData_free_layers(cd_ldata, CD_MLOOPTANGENT, rdata->loop_len);
- for (int i = 0; i < rdata->uv_len; ++i) {
+ for (int i = 0; i < rdata->cd.layers.uv_len; ++i) {
const char *name = CustomData_get_layer_name(cd_ldata, CD_MLOOPUV, i);
unsigned int hash = BLI_ghashutil_strhash_p(name);
{
/* UVs */
- BLI_snprintf(rdata->cd_uuid.uv[i], sizeof(*rdata->cd_uuid.uv), "u%u", hash);
- rdata->mloopuv[i] = CustomData_get_layer_n(cd_ldata, CD_MLOOPUV, i);
+ BLI_snprintf(rdata->cd.uuid.uv[i], sizeof(*rdata->cd.uuid.uv), "u%u", hash);
+ rdata->cd.layers.uv[i] = CustomData_get_layer_n(cd_ldata, CD_MLOOPUV, i);
if (rdata->edit_bmesh) {
- rdata->cd_offset.uv[i] = CustomData_get_n_offset(&rdata->edit_bmesh->bm->ldata, CD_MLOOPUV, i);
+ rdata->cd.offset.uv[i] = CustomData_get_n_offset(&rdata->edit_bmesh->bm->ldata, CD_MLOOPUV, i);
}
- BLI_snprintf(rdata->cd_uuid.auto_mix[i], sizeof(*rdata->cd_uuid.auto_mix), "a%u", hash);
+ BLI_snprintf(rdata->cd.uuid.auto_mix[i], sizeof(*rdata->cd.uuid.auto_mix), "a%u", hash);
}
{
/* Tangents*/
- BLI_snprintf(rdata->cd_uuid.tangent[i], sizeof(*rdata->cd_uuid.tangent), "t%u", hash);
+ BLI_snprintf(rdata->cd.uuid.tangent[i], sizeof(*rdata->cd.uuid.tangent), "t%u", hash);
if (rdata->edit_bmesh) {
BMEditMesh *em = rdata->edit_bmesh;
BMesh *bm = em->bm;
- if (!CustomData_has_layer(&rdata->cd_output.ldata, CD_MLOOPTANGENT)) {
+ if (!CustomData_has_layer(&rdata->cd.output.ldata, CD_MLOOPTANGENT)) {
bool calc_active_tangent = false;
float (*poly_normals)[3] = rdata->poly_normals;
float (*loop_normals)[3] = CustomData_get_layer(cd_ldata, CD_NORMAL);
char tangent_names[MAX_MTFACE][MAX_NAME];
int tangent_names_len = 0;
- for (tangent_names_len = 0; tangent_names_len < rdata->uv_len; tangent_names_len++) {
+ for (tangent_names_len = 0; tangent_names_len < rdata->cd.layers.uv_len; tangent_names_len++) {
BLI_strncpy(
tangent_names[tangent_names_len],
CustomData_get_layer_name(cd_ldata, CD_MLOOPUV, tangent_names_len), MAX_NAME);
@@ -472,14 +478,14 @@ static MeshRenderData *mesh_render_data_create(Mesh *me, const int types)
tangent_names, tangent_names_len,
poly_normals, loop_normals,
rdata->orco,
- &rdata->cd_output.ldata, bm->totloop,
- &rdata->cd_output.tangent_mask);
+ &rdata->cd
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list