Sculpt Drawing: reduce redundant color conversion

Also replace macro with for loop.
This commit is contained in:
Campbell Barton 2017-05-11 07:34:56 +10:00
parent b82954f6f4
commit 722bcb554f

@ -1036,7 +1036,7 @@ void GPU_update_mesh_pbvh_buffers(
const int (*face_vert_indices)[3], bool show_diffuse_color) const int (*face_vert_indices)[3], bool show_diffuse_color)
{ {
VertexBufferFormat *vert_data; VertexBufferFormat *vert_data;
int i, j; int i;
buffers->vmask = vmask; buffers->vmask = vmask;
buffers->show_diffuse_color = show_diffuse_color; buffers->show_diffuse_color = show_diffuse_color;
@ -1057,6 +1057,9 @@ void GPU_update_mesh_pbvh_buffers(
copy_v4_v4(buffers->diffuse_color, diffuse_color); copy_v4_v4(buffers->diffuse_color, diffuse_color);
uchar diffuse_color_ub[4];
rgba_float_to_uchar(diffuse_color_ub, diffuse_color);
/* Build VBO */ /* Build VBO */
if (buffers->vert_buf) if (buffers->vert_buf)
GPU_buffer_free(buffers->vert_buf); GPU_buffer_free(buffers->vert_buf);
@ -1076,28 +1079,20 @@ void GPU_update_mesh_pbvh_buffers(
memcpy(out->no, v->no, sizeof(short) * 3); memcpy(out->no, v->no, sizeof(short) * 3);
} }
#define UPDATE_VERTEX(face, vertex, index, diffuse_color) \
{ \
VertexBufferFormat *out = vert_data + face_vert_indices[face][index]; \
if (vmask) \
gpu_color_from_mask_copy(vmask[vertex], diffuse_color, out->color); \
else \
rgb_float_to_uchar(out->color, diffuse_color); \
} (void)0
for (i = 0; i < buffers->face_indices_len; i++) { for (i = 0; i < buffers->face_indices_len; i++) {
const MLoopTri *lt = &buffers->looptri[buffers->face_indices[i]]; const MLoopTri *lt = &buffers->looptri[buffers->face_indices[i]];
const unsigned int vtri[3] = { for (uint j = 0; j < 3; j++) {
buffers->mloop[lt->tri[0]].v, VertexBufferFormat *out = vert_data + face_vert_indices[i][j];
buffers->mloop[lt->tri[1]].v,
buffers->mloop[lt->tri[2]].v,
};
UPDATE_VERTEX(i, vtri[0], 0, diffuse_color); if (vmask) {
UPDATE_VERTEX(i, vtri[1], 1, diffuse_color); uint v_index = buffers->mloop[lt->tri[j]].v;
UPDATE_VERTEX(i, vtri[2], 2, diffuse_color); gpu_color_from_mask_copy(vmask[v_index], diffuse_color, out->color);
}
else {
copy_v3_v3_uchar(out->color, diffuse_color_ub);
}
}
} }
#undef UPDATE_VERTEX
} }
else { else {
/* calculate normal for each polygon only once */ /* calculate normal for each polygon only once */
@ -1112,8 +1107,6 @@ void GPU_update_mesh_pbvh_buffers(
buffers->mloop[lt->tri[2]].v, buffers->mloop[lt->tri[2]].v,
}; };
float fmask;
if (paint_is_face_hidden(lt, mvert, buffers->mloop)) if (paint_is_face_hidden(lt, mvert, buffers->mloop))
continue; continue;
@ -1126,23 +1119,22 @@ void GPU_update_mesh_pbvh_buffers(
mpoly_prev = lt->poly; mpoly_prev = lt->poly;
} }
uchar color_ub[3];
if (vmask) { if (vmask) {
fmask = (vmask[vtri[0]] + float fmask = (vmask[vtri[0]] + vmask[vtri[1]] + vmask[vtri[2]]) / 3.0f;
vmask[vtri[1]] + gpu_color_from_mask_copy(fmask, diffuse_color, color_ub);
vmask[vtri[2]]) / 3.0f; }
else {
copy_v3_v3_uchar(color_ub, diffuse_color_ub);
} }
for (j = 0; j < 3; j++) { for (uint j = 0; j < 3; j++) {
const MVert *v = &mvert[vtri[j]]; const MVert *v = &mvert[vtri[j]];
VertexBufferFormat *out = vert_data; VertexBufferFormat *out = vert_data;
copy_v3_v3(out->co, v->co); copy_v3_v3(out->co, v->co);
copy_v3_v3_short(out->no, no); copy_v3_v3_short(out->no, no);
copy_v3_v3_uchar(out->color, color_ub);
if (vmask)
gpu_color_from_mask_copy(fmask, diffuse_color, out->color);
else
rgb_float_to_uchar(out->color, diffuse_color);
vert_data++; vert_data++;
} }