Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_cache_impl_mesh.c
| Show First 20 Lines • Show All 560 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static void mesh_cd_extract_auto_layers_names_and_srgb(Mesh *me, | static void mesh_cd_extract_auto_layers_names_and_srgb(Mesh *me, | ||||
| DRW_MeshCDMask cd_used, | DRW_MeshCDMask cd_used, | ||||
| char **r_auto_layers_names, | char **r_auto_layers_names, | ||||
| int **r_auto_layers_srgb, | int **r_auto_layers_srgb, | ||||
| int *r_auto_layers_len) | int *r_auto_layers_len) | ||||
| { | { | ||||
| char *auto_names = NULL; | |||||
| int *auto_is_srgb = NULL; | |||||
| uint auto_is_srgb_ofs = 0; | |||||
| if (cd_used.uv && cd_used.vcol) { | |||||
| 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 uv_len_used = count_bits_i(cd_used.uv); | int uv_len_used = count_bits_i(cd_used.uv); | ||||
| int vcol_len_used = count_bits_i(cd_used.vcol); | int vcol_len_used = count_bits_i(cd_used.vcol); | ||||
| int uv_len = CustomData_number_of_layers(cd_ldata, CD_MLOOPUV); | int uv_len = CustomData_number_of_layers(cd_ldata, CD_MLOOPUV); | ||||
| int vcol_len = CustomData_number_of_layers(cd_ldata, CD_MLOOPCOL); | int vcol_len = CustomData_number_of_layers(cd_ldata, CD_MLOOPCOL); | ||||
| uint auto_names_len = 32 * (uv_len_used + vcol_len_used); | uint auto_names_len = 32 * (uv_len_used + vcol_len_used); | ||||
| uint auto_ofs = 0; | uint auto_ofs = 0; | ||||
| /* Allocate max, resize later. */ | /* Allocate max, resize later. */ | ||||
| char *auto_names = MEM_callocN(sizeof(char) * auto_names_len, __func__); | auto_names = MEM_callocN(sizeof(char) * auto_names_len, __func__); | ||||
| int *auto_is_srgb = MEM_callocN(sizeof(int) * (uv_len_used + vcol_len_used), __func__); | auto_is_srgb = MEM_callocN(sizeof(int) * (uv_len_used + vcol_len_used), __func__); | ||||
| for (int i = 0; i < uv_len; i++) { | for (int i = 0; i < uv_len; i++) { | ||||
| if ((cd_used.uv & (1 << i)) != 0) { | if ((cd_used.uv & (1 << i)) != 0) { | ||||
| const char *name = CustomData_get_layer_name(cd_ldata, CD_MLOOPUV, i); | const char *name = CustomData_get_layer_name(cd_ldata, CD_MLOOPUV, i); | ||||
| uint hash = BLI_ghashutil_strhash_p(name); | uint hash = BLI_ghashutil_strhash_p(name); | ||||
| /* +1 to include '\0' terminator. */ | /* +1 to include '\0' terminator. */ | ||||
| auto_ofs += 1 + BLI_snprintf_rlen( | auto_ofs += 1 + BLI_snprintf_rlen( | ||||
| auto_names + auto_ofs, auto_names_len - auto_ofs, "ba%u", hash); | auto_names + auto_ofs, auto_names_len - auto_ofs, "ba%u", hash); | ||||
| } | } | ||||
| } | } | ||||
| uint auto_is_srgb_ofs = uv_len_used; | auto_is_srgb_ofs = uv_len_used; | ||||
| for (int i = 0; i < vcol_len; i++) { | for (int i = 0; i < vcol_len; i++) { | ||||
| if ((cd_used.vcol & (1 << i)) != 0) { | if ((cd_used.vcol & (1 << i)) != 0) { | ||||
| const char *name = CustomData_get_layer_name(cd_ldata, CD_MLOOPCOL, i); | const char *name = CustomData_get_layer_name(cd_ldata, CD_MLOOPCOL, i); | ||||
| /* We only do vcols that are not overridden by a uv layer with same name. */ | /* We only do vcols that are not overridden by a uv layer with same name. */ | ||||
| if (CustomData_get_named_layer_index(cd_ldata, CD_MLOOPUV, name) == -1) { | if (CustomData_get_named_layer_index(cd_ldata, CD_MLOOPUV, name) == -1) { | ||||
| uint hash = BLI_ghashutil_strhash_p(name); | uint hash = BLI_ghashutil_strhash_p(name); | ||||
| /* +1 to include '\0' terminator. */ | /* +1 to include '\0' terminator. */ | ||||
| auto_ofs += 1 + BLI_snprintf_rlen( | auto_ofs += 1 + BLI_snprintf_rlen( | ||||
| auto_names + auto_ofs, auto_names_len - auto_ofs, "ba%u", hash); | auto_names + auto_ofs, auto_names_len - auto_ofs, "ba%u", hash); | ||||
| auto_is_srgb[auto_is_srgb_ofs] = true; | auto_is_srgb[auto_is_srgb_ofs] = true; | ||||
| auto_is_srgb_ofs++; | auto_is_srgb_ofs++; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| auto_names = MEM_reallocN(auto_names, sizeof(char) * auto_ofs); | auto_names = MEM_reallocN(auto_names, sizeof(char) * auto_ofs); | ||||
| auto_is_srgb = MEM_reallocN(auto_is_srgb, sizeof(int) * auto_is_srgb_ofs); | auto_is_srgb = MEM_reallocN(auto_is_srgb, sizeof(int) * auto_is_srgb_ofs); | ||||
| } | |||||
| /* WATCH: May have been referenced somewhere before freeing. */ | /* WATCH: May have been referenced somewhere before freeing. */ | ||||
| MEM_SAFE_FREE(*r_auto_layers_names); | MEM_SAFE_FREE(*r_auto_layers_names); | ||||
| MEM_SAFE_FREE(*r_auto_layers_srgb); | MEM_SAFE_FREE(*r_auto_layers_srgb); | ||||
| *r_auto_layers_names = auto_names; | *r_auto_layers_names = auto_names; | ||||
| *r_auto_layers_srgb = auto_is_srgb; | *r_auto_layers_srgb = auto_is_srgb; | ||||
| *r_auto_layers_len = auto_is_srgb_ofs; | *r_auto_layers_len = auto_is_srgb_ofs; | ||||
| ▲ Show 20 Lines • Show All 5,010 Lines • Show Last 20 Lines | |||||