Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/customdata.c
| Show First 20 Lines • Show All 2,327 Lines • ▼ Show 20 Lines | if (dest->layers[dest_i].type == source->layers[src_i].type) { | ||||
| */ | */ | ||||
| dest_i++; | dest_i++; | ||||
| } | } | ||||
| } | } | ||||
| if (count > SOURCE_BUF_SIZE) MEM_freeN((void *)sources); | if (count > SOURCE_BUF_SIZE) MEM_freeN((void *)sources); | ||||
| } | } | ||||
| void CustomData_swap(struct CustomData *data, int index, const int *corner_indices) | void CustomData_swap_corners(struct CustomData *data, int index, const int *corner_indices) | ||||
| { | { | ||||
| const LayerTypeInfo *typeInfo; | const LayerTypeInfo *typeInfo; | ||||
| int i; | int i; | ||||
| for (i = 0; i < data->totlayer; ++i) { | for (i = 0; i < data->totlayer; ++i) { | ||||
| typeInfo = layerType_getInfo(data->layers[i].type); | typeInfo = layerType_getInfo(data->layers[i].type); | ||||
| if (typeInfo->swap) { | if (typeInfo->swap) { | ||||
| const int offset = index * typeInfo->size; | const int offset = index * typeInfo->size; | ||||
| typeInfo->swap(POINTER_OFFSET(data->layers[i].data, offset), corner_indices); | typeInfo->swap(POINTER_OFFSET(data->layers[i].data, offset), corner_indices); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * Swap two items of given custom data, in all available layers. | |||||
| */ | |||||
| void CustomData_swap(struct CustomData *data, const int index_a, const int index_b) | |||||
| { | |||||
| int i; | |||||
| char buff_static[256]; | |||||
| if (index_a == index_b) { | |||||
| return; | |||||
| } | |||||
| for (i = 0; i < data->totlayer; ++i) { | |||||
| const LayerTypeInfo *typeInfo = layerType_getInfo(data->layers[i].type); | |||||
| const size_t size = typeInfo->size; | |||||
| const size_t offset_a = size * index_a; | |||||
| const size_t offset_b = size * index_b; | |||||
| void *buff = size <= sizeof(buff_static) ? buff_static : MEM_mallocN(size, __func__); | |||||
| memcpy(buff, POINTER_OFFSET(data->layers[i].data, offset_a), size); | |||||
| memcpy(POINTER_OFFSET(data->layers[i].data, offset_a), POINTER_OFFSET(data->layers[i].data, offset_b), size); | |||||
| memcpy(POINTER_OFFSET(data->layers[i].data, offset_b), buff, size); | |||||
| if (buff != buff_static) { | |||||
| MEM_freeN(buff); | |||||
| } | |||||
| } | |||||
| } | |||||
| void *CustomData_get(const CustomData *data, int index, int type) | void *CustomData_get(const CustomData *data, int index, int type) | ||||
| { | { | ||||
| int offset; | int offset; | ||||
| int layer_index; | int layer_index; | ||||
| BLI_assert(index >= 0); | BLI_assert(index >= 0); | ||||
| /* get the layer index of the active layer of type */ | /* get the layer index of the active layer of type */ | ||||
| ▲ Show 20 Lines • Show All 1,672 Lines • Show Last 20 Lines | |||||