Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_cache_impl_mesh.c
| Show First 20 Lines • Show All 231 Lines • ▼ Show 20 Lines | typedef struct MeshRenderData { | ||||
| float (*loop_normals)[3]; | float (*loop_normals)[3]; | ||||
| /* CustomData 'cd' cache for efficient access. */ | /* CustomData 'cd' cache for efficient access. */ | ||||
| struct { | struct { | ||||
| struct { | struct { | ||||
| MLoopUV **uv; | MLoopUV **uv; | ||||
| int uv_len; | int uv_len; | ||||
| int uv_active; | int uv_active; | ||||
| int uv_mask_active; | |||||
| MLoopCol **vcol; | MLoopCol **vcol; | ||||
| int vcol_len; | int vcol_len; | ||||
| int vcol_active; | int vcol_active; | ||||
| float (**tangent)[4]; | float (**tangent)[4]; | ||||
| int tangent_len; | int tangent_len; | ||||
| int tangent_active; | int tangent_active; | ||||
| ▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | static void mesh_cd_calc_active_uv_layer( | ||||
| const CustomData *cd_ldata = (me->edit_mesh) ? &me->edit_mesh->bm->ldata : &me->ldata; | const CustomData *cd_ldata = (me->edit_mesh) ? &me->edit_mesh->bm->ldata : &me->ldata; | ||||
| int layer = CustomData_get_active_layer(cd_ldata, CD_MLOOPUV); | int layer = CustomData_get_active_layer(cd_ldata, CD_MLOOPUV); | ||||
| if (layer != -1) { | if (layer != -1) { | ||||
| cd_lused[CD_MLOOPUV] |= (1 << layer); | cd_lused[CD_MLOOPUV] |= (1 << layer); | ||||
| } | } | ||||
| } | } | ||||
| static void mesh_cd_calc_active_mask_uv_layer( | |||||
| const Mesh *me, ushort cd_lused[CD_NUMTYPES]) | |||||
| { | |||||
| const CustomData *cd_ldata = (me->edit_mesh) ? &me->edit_mesh->bm->ldata : &me->ldata; | |||||
| int layer = CustomData_get_stencil_layer(cd_ldata, CD_MLOOPUV); | |||||
| if (layer != -1) { | |||||
| cd_lused[CD_MLOOPUV] |= (1 << layer); | |||||
| } | |||||
| } | |||||
| static void mesh_cd_calc_active_vcol_layer( | static void mesh_cd_calc_active_vcol_layer( | ||||
| const Mesh *me, ushort cd_lused[CD_NUMTYPES]) | const Mesh *me, ushort cd_lused[CD_NUMTYPES]) | ||||
| { | { | ||||
| const CustomData *cd_ldata = (me->edit_mesh) ? &me->edit_mesh->bm->ldata : &me->ldata; | const CustomData *cd_ldata = (me->edit_mesh) ? &me->edit_mesh->bm->ldata : &me->ldata; | ||||
| int layer = CustomData_get_active_layer(cd_ldata, CD_MLOOPCOL); | int layer = CustomData_get_active_layer(cd_ldata, CD_MLOOPCOL); | ||||
| if (layer != -1) { | if (layer != -1) { | ||||
| cd_lused[CD_MLOOPCOL] |= (1 << layer); | cd_lused[CD_MLOOPCOL] |= (1 << layer); | ||||
| ▲ Show 20 Lines • Show All 434 Lines • ▼ Show 20 Lines | if (me->edit_mesh) { | ||||
| cd_ldata = &bm->ldata; | cd_ldata = &bm->ldata; | ||||
| } | } | ||||
| else { | else { | ||||
| cd_vdata = &me->vdata; | cd_vdata = &me->vdata; | ||||
| cd_ldata = &me->ldata; | cd_ldata = &me->ldata; | ||||
| } | } | ||||
| rdata->cd.layers.uv_active = CustomData_get_active_layer(cd_ldata, CD_MLOOPUV); | rdata->cd.layers.uv_active = CustomData_get_active_layer(cd_ldata, CD_MLOOPUV); | ||||
| rdata->cd.layers.uv_mask_active = CustomData_get_stencil_layer(cd_ldata, CD_MLOOPUV); | |||||
| rdata->cd.layers.vcol_active = CustomData_get_active_layer(cd_ldata, CD_MLOOPCOL); | rdata->cd.layers.vcol_active = CustomData_get_active_layer(cd_ldata, CD_MLOOPCOL); | ||||
| rdata->cd.layers.tangent_active = rdata->cd.layers.uv_active; | rdata->cd.layers.tangent_active = rdata->cd.layers.uv_active; | ||||
| #define CD_VALIDATE_ACTIVE_LAYER(active_index, used) \ | #define CD_VALIDATE_ACTIVE_LAYER(active_index, used) \ | ||||
| if ((active_index != -1) && (used & (1 << active_index)) == 0) { \ | if ((active_index != -1) && (used & (1 << active_index)) == 0) { \ | ||||
| active_index = -1; \ | active_index = -1; \ | ||||
| } ((void)0) | } ((void)0) | ||||
| CD_VALIDATE_ACTIVE_LAYER(rdata->cd.layers.uv_active, cd_lused[CD_MLOOPUV]); | CD_VALIDATE_ACTIVE_LAYER(rdata->cd.layers.uv_active, cd_lused[CD_MLOOPUV]); | ||||
| CD_VALIDATE_ACTIVE_LAYER(rdata->cd.layers.uv_mask_active, cd_lused[CD_MLOOPUV]); | |||||
| CD_VALIDATE_ACTIVE_LAYER(rdata->cd.layers.tangent_active, cd_lused[CD_TANGENT]); | CD_VALIDATE_ACTIVE_LAYER(rdata->cd.layers.tangent_active, cd_lused[CD_TANGENT]); | ||||
| CD_VALIDATE_ACTIVE_LAYER(rdata->cd.layers.vcol_active, cd_lused[CD_MLOOPCOL]); | CD_VALIDATE_ACTIVE_LAYER(rdata->cd.layers.vcol_active, cd_lused[CD_MLOOPCOL]); | ||||
| #undef CD_VALIDATE_ACTIVE_LAYER | #undef CD_VALIDATE_ACTIVE_LAYER | ||||
| rdata->is_orco_allocated = false; | rdata->is_orco_allocated = false; | ||||
| if (cd_vused[CD_ORCO] & 1) { | if (cd_vused[CD_ORCO] & 1) { | ||||
| rdata->orco = CustomData_get_layer(cd_vdata, CD_ORCO); | rdata->orco = CustomData_get_layer(cd_vdata, CD_ORCO); | ||||
| ▲ Show 20 Lines • Show All 2,123 Lines • ▼ Show 20 Lines | |||||
| #endif | #endif | ||||
| /* Auto Name */ | /* Auto Name */ | ||||
| attr_name = mesh_render_data_uv_auto_layer_uuid_get(rdata, i); | attr_name = mesh_render_data_uv_auto_layer_uuid_get(rdata, i); | ||||
| GPU_vertformat_alias_add(&format, attr_name); | GPU_vertformat_alias_add(&format, attr_name); | ||||
| if (i == rdata->cd.layers.uv_active) { | if (i == rdata->cd.layers.uv_active) { | ||||
| GPU_vertformat_alias_add(&format, "u"); | GPU_vertformat_alias_add(&format, "u"); | ||||
| } | } | ||||
| if (i == rdata->cd.layers.uv_mask_active) { | |||||
| GPU_vertformat_alias_add(&format, "mu"); | |||||
| } | |||||
| } | } | ||||
| for (uint i = 0; i < tangent_len; i++) { | for (uint i = 0; i < tangent_len; i++) { | ||||
| const char *attr_name = mesh_render_data_tangent_layer_uuid_get(rdata, i); | const char *attr_name = mesh_render_data_tangent_layer_uuid_get(rdata, i); | ||||
| #ifdef USE_COMP_MESH_DATA | #ifdef USE_COMP_MESH_DATA | ||||
| tangent_id[i] = GPU_vertformat_attr_add(&format, attr_name, GPU_COMP_I16, 4, GPU_FETCH_INT_TO_FLOAT_UNIT); | tangent_id[i] = GPU_vertformat_attr_add(&format, attr_name, GPU_COMP_I16, 4, GPU_FETCH_INT_TO_FLOAT_UNIT); | ||||
| #else | #else | ||||
| tangent_id[i] = GPU_vertformat_attr_add(&format, attr_name, GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | tangent_id[i] = GPU_vertformat_attr_add(&format, attr_name, GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | ||||
| ▲ Show 20 Lines • Show All 956 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| uchar cd_vneeded[CD_NUMTYPES] = {0}; | uchar cd_vneeded[CD_NUMTYPES] = {0}; | ||||
| ushort cd_lneeded[CD_NUMTYPES] = {0}; | ushort cd_lneeded[CD_NUMTYPES] = {0}; | ||||
| mesh_cd_calc_active_uv_layer(me, cd_lneeded); | mesh_cd_calc_active_uv_layer(me, cd_lneeded); | ||||
| if (cd_lneeded[CD_MLOOPUV] == 0) { | if (cd_lneeded[CD_MLOOPUV] == 0) { | ||||
| /* This should not happen. */ | /* This should not happen. */ | ||||
| BLI_assert(!"No uv layer available in texpaint, but batches requested anyway!"); | BLI_assert(!"No uv layer available in texpaint, but batches requested anyway!"); | ||||
| } | } | ||||
| mesh_cd_calc_active_mask_uv_layer(me, cd_lneeded); | |||||
| bool cd_overlap = mesh_cd_layers_type_overlap(cache->cd_vused, cache->cd_lused, | bool cd_overlap = mesh_cd_layers_type_overlap(cache->cd_vused, cache->cd_lused, | ||||
| cd_vneeded, cd_lneeded); | cd_vneeded, cd_lneeded); | ||||
| if (cd_overlap == false) { | if (cd_overlap == false) { | ||||
| /* XXX TODO(fclem): We are writting to batch cache here. Need to make this thread safe. */ | /* XXX TODO(fclem): We are writting to batch cache here. Need to make this thread safe. */ | ||||
| mesh_cd_layers_type_merge(cache->cd_vneeded, cache->cd_lneeded, | mesh_cd_layers_type_merge(cache->cd_vneeded, cache->cd_lneeded, | ||||
| cd_vneeded, cd_lneeded); | cd_vneeded, cd_lneeded); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 1,005 Lines • Show Last 20 Lines | |||||