BMesh: Respect data alignment for attributes #109237
|
@ -62,6 +62,8 @@
|
|||
/* only for customdata_data_transfer_interp_normal_normals */
|
||||
#include "data_transfer_intern.h"
|
||||
|
||||
#include <array>
|
||||
JosephEagar marked this conversation as resolved
Outdated
|
||||
|
||||
using blender::Array;
|
||||
using blender::float2;
|
||||
using blender::ImplicitSharingInfo;
|
||||
|
@ -2544,6 +2546,8 @@ void CustomData_free_typemask(CustomData *data, const int totelem, eCustomDataMa
|
|||
static int customData_get_alignment(eCustomDataType type)
|
||||
JosephEagar marked this conversation as resolved
Hans Goudey
commented
This comment isn't quite right, since This comment isn't quite right, since `CD_PROP_BYTE_COLOR` is also an array type. Maybe "Handle float array types"?
Joseph Eagar
commented
I has an if statement for that. I admit the comment isn't clear, it applies to the three if statements (for 4,2,1 alignments). I has an if statement for that. I admit the comment isn't clear, it applies to the three if statements (for 4,2,1 alignments).
Hans Goudey
commented
Ah I see. I don't think the comment is necessary honestly Ah I see. I don't think the comment is necessary honestly
|
||||
{
|
||||
/* Handle array types. */
|
||||
|
||||
/* Float and integer arrays. */
|
||||
if (ELEM(type,
|
||||
CD_PROP_FLOAT2,
|
||||
CD_PROP_FLOAT3,
|
||||
|
@ -2558,10 +2562,12 @@ static int customData_get_alignment(eCustomDataType type)
|
|||
return 4;
|
||||
}
|
||||
|
||||
/* Short arrays. */
|
||||
if (ELEM(type, CD_TESSLOOPNORMAL)) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
/* Byte arrays. */
|
||||
if (type == CD_PROP_BYTE_COLOR) {
|
||||
return 1;
|
||||
}
|
||||
|
@ -2585,26 +2591,21 @@ static int customData_get_alignment(eCustomDataType type)
|
|||
/* Update BMesh block offsets, respects alignment. */
|
||||
static void customData_update_offsets(CustomData *data)
|
||||
{
|
||||
const LayerTypeInfo *typeInfo;
|
||||
|
||||
if (data->totlayer == 0) {
|
||||
data->totsize = 0;
|
||||
return;
|
||||
}
|
||||
JosephEagar marked this conversation as resolved
Outdated
Hans Goudey
commented
`std::array` should work here, a bit nicer IMO
|
||||
|
||||
const std::array<int, 4> aligns = {8, 4, 2, 1};
|
||||
int max_alignment = 1;
|
||||
|
||||
int aligns[] = {8, 4, 2, 1};
|
||||
int offset = 0;
|
||||
JosephEagar marked this conversation as resolved
Outdated
Hans Goudey
commented
Declare variables const Declare variables const
|
||||
for (int align : aligns) {
|
||||
for (int i = 0; i < data->totlayer; i++) {
|
||||
CustomDataLayer *layer = data->layers + i;
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE(aligns) + 1; i++) {
|
||||
for (int j = 0; j < data->totlayer; j++) {
|
||||
CustomDataLayer *layer = data->layers + j;
|
||||
|
||||
int align = customData_get_alignment(eCustomDataType(layer->type));
|
||||
max_alignment = max_ii(max_alignment, align);
|
||||
|
||||
if (align != aligns[i]) {
|
||||
int layer_align = customData_get_alignment(eCustomDataType(layer->type));
|
||||
if (layer_align != align) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -2616,6 +2617,7 @@ static void customData_update_offsets(CustomData *data)
|
|||
}
|
||||
|
||||
offset += size;
|
||||
max_alignment = max_ii(max_alignment, align);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Unnecessary change