Merge remote-tracking branch 'origin/blender-v3.1-release'
This commit is contained in:
@@ -592,6 +592,67 @@ void draw_subdiv_cache_free(DRWSubdivCache *cache)
|
||||
SUBDIV_COARSE_FACE_FLAG_ACTIVE) \
|
||||
<< SUBDIV_COARSE_FACE_FLAG_OFFSET)
|
||||
|
||||
static uint32_t compute_coarse_face_flag(BMFace *f, BMFace *efa_act)
|
||||
{
|
||||
if (f == nullptr) {
|
||||
/* May happen during mapped extraction. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t flag = 0;
|
||||
if (BM_elem_flag_test(f, BM_ELEM_SMOOTH)) {
|
||||
flag |= SUBDIV_COARSE_FACE_FLAG_SMOOTH;
|
||||
}
|
||||
if (BM_elem_flag_test(f, BM_ELEM_SELECT)) {
|
||||
flag |= SUBDIV_COARSE_FACE_FLAG_SELECT;
|
||||
}
|
||||
if (f == efa_act) {
|
||||
flag |= SUBDIV_COARSE_FACE_FLAG_ACTIVE;
|
||||
}
|
||||
const int loopstart = BM_elem_index_get(f->l_first);
|
||||
return (uint)(loopstart) | (flag << SUBDIV_COARSE_FACE_FLAG_OFFSET);
|
||||
}
|
||||
|
||||
static void draw_subdiv_cache_extra_coarse_face_data_bm(BMesh *bm,
|
||||
BMFace *efa_act,
|
||||
uint32_t *flags_data)
|
||||
{
|
||||
BMFace *f;
|
||||
BMIter iter;
|
||||
|
||||
BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
|
||||
const int index = BM_elem_index_get(f);
|
||||
flags_data[index] = compute_coarse_face_flag(f, efa_act);
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_subdiv_cache_extra_coarse_face_data_mesh(Mesh *mesh, uint32_t *flags_data)
|
||||
{
|
||||
for (int i = 0; i < mesh->totpoly; i++) {
|
||||
uint32_t flag = 0;
|
||||
if ((mesh->mpoly[i].flag & ME_SMOOTH) != 0) {
|
||||
flag = SUBDIV_COARSE_FACE_FLAG_SMOOTH;
|
||||
}
|
||||
flags_data[i] = (uint)(mesh->mpoly[i].loopstart) | (flag << SUBDIV_COARSE_FACE_FLAG_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_subdiv_cache_extra_coarse_face_data_mapped(Mesh *mesh,
|
||||
BMesh *bm,
|
||||
MeshRenderData *mr,
|
||||
uint32_t *flags_data)
|
||||
{
|
||||
if (bm == nullptr) {
|
||||
draw_subdiv_cache_extra_coarse_face_data_mesh(mesh, flags_data);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < mesh->totpoly; i++) {
|
||||
BMFace *f = bm_original_face_get(mr, i);
|
||||
flags_data[i] = compute_coarse_face_flag(f, mr->efa_act);
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_subdiv_cache_update_extra_coarse_face_data(DRWSubdivCache *cache,
|
||||
Mesh *mesh,
|
||||
MeshRenderData *mr)
|
||||
@@ -611,56 +672,13 @@ static void draw_subdiv_cache_update_extra_coarse_face_data(DRWSubdivCache *cach
|
||||
uint32_t *flags_data = (uint32_t *)(GPU_vertbuf_get_data(cache->extra_coarse_face_data));
|
||||
|
||||
if (mr->extract_type == MR_EXTRACT_BMESH) {
|
||||
BMesh *bm = cache->bm;
|
||||
BMFace *f;
|
||||
BMIter iter;
|
||||
|
||||
/* Ensure all current elements follow new customdata layout. */
|
||||
BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
|
||||
const int index = BM_elem_index_get(f);
|
||||
uint32_t flag = 0;
|
||||
if (BM_elem_flag_test(f, BM_ELEM_SMOOTH)) {
|
||||
flag |= SUBDIV_COARSE_FACE_FLAG_SMOOTH;
|
||||
}
|
||||
if (BM_elem_flag_test(f, BM_ELEM_SELECT)) {
|
||||
flag |= SUBDIV_COARSE_FACE_FLAG_SELECT;
|
||||
}
|
||||
if (f == mr->efa_act) {
|
||||
flag |= SUBDIV_COARSE_FACE_FLAG_ACTIVE;
|
||||
}
|
||||
const int loopstart = BM_elem_index_get(f->l_first);
|
||||
flags_data[index] = (uint)(loopstart) | (flag << SUBDIV_COARSE_FACE_FLAG_OFFSET);
|
||||
}
|
||||
draw_subdiv_cache_extra_coarse_face_data_bm(cache->bm, mr->efa_act, flags_data);
|
||||
}
|
||||
else if (mr->extract_type == MR_EXTRACT_MAPPED) {
|
||||
for (int i = 0; i < mesh->totpoly; i++) {
|
||||
BMFace *f = bm_original_face_get(mr, i);
|
||||
uint32_t flag = 0;
|
||||
|
||||
if (f) {
|
||||
if (BM_elem_flag_test(f, BM_ELEM_SMOOTH)) {
|
||||
flag |= SUBDIV_COARSE_FACE_FLAG_SMOOTH;
|
||||
}
|
||||
if (BM_elem_flag_test(f, BM_ELEM_SELECT)) {
|
||||
flag |= SUBDIV_COARSE_FACE_FLAG_SELECT;
|
||||
}
|
||||
if (f == mr->efa_act) {
|
||||
flag |= SUBDIV_COARSE_FACE_FLAG_ACTIVE;
|
||||
}
|
||||
const int loopstart = BM_elem_index_get(f->l_first);
|
||||
flag = (uint)(loopstart) | (flag << SUBDIV_COARSE_FACE_FLAG_OFFSET);
|
||||
}
|
||||
flags_data[i] = flag;
|
||||
}
|
||||
draw_subdiv_cache_extra_coarse_face_data_mapped(mesh, cache->bm, mr, flags_data);
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < mesh->totpoly; i++) {
|
||||
uint32_t flag = 0;
|
||||
if ((mesh->mpoly[i].flag & ME_SMOOTH) != 0) {
|
||||
flag = SUBDIV_COARSE_FACE_FLAG_SMOOTH;
|
||||
}
|
||||
flags_data[i] = (uint)(mesh->mpoly[i].loopstart) | (flag << SUBDIV_COARSE_FACE_FLAG_OFFSET);
|
||||
}
|
||||
draw_subdiv_cache_extra_coarse_face_data_mesh(mesh, flags_data);
|
||||
}
|
||||
|
||||
/* Make sure updated data is re-uploaded. */
|
||||
|
||||
@@ -153,10 +153,10 @@ static void extract_weights_iter_poly_mesh(const MeshRenderData *mr,
|
||||
}
|
||||
|
||||
static void extract_weights_init_subdiv(const DRWSubdivCache *subdiv_cache,
|
||||
const MeshRenderData *UNUSED(mr),
|
||||
const MeshRenderData *mr,
|
||||
struct MeshBatchCache *cache,
|
||||
void *buffer,
|
||||
void *UNUSED(data))
|
||||
void *_data)
|
||||
{
|
||||
Mesh *coarse_mesh = subdiv_cache->mesh;
|
||||
GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buffer);
|
||||
@@ -168,28 +168,20 @@ static void extract_weights_init_subdiv(const DRWSubdivCache *subdiv_cache,
|
||||
GPU_vertbuf_init_build_on_device(vbo, &format, subdiv_cache->num_subdiv_loops);
|
||||
|
||||
GPUVertBuf *coarse_weights = GPU_vertbuf_calloc();
|
||||
GPU_vertbuf_init_with_format(coarse_weights, &format);
|
||||
GPU_vertbuf_data_alloc(coarse_weights, coarse_mesh->totloop);
|
||||
float *coarse_weights_data = static_cast<float *>(GPU_vertbuf_get_data(coarse_weights));
|
||||
extract_weights_init(mr, cache, coarse_weights, _data);
|
||||
|
||||
const DRW_MeshWeightState *wstate = &cache->weight_state;
|
||||
const MDeformVert *dverts = static_cast<const MDeformVert *>(
|
||||
CustomData_get_layer(&coarse_mesh->vdata, CD_MDEFORMVERT));
|
||||
|
||||
for (int i = 0; i < coarse_mesh->totpoly; i++) {
|
||||
const MPoly *mpoly = &coarse_mesh->mpoly[i];
|
||||
|
||||
for (int loop_index = mpoly->loopstart; loop_index < mpoly->loopstart + mpoly->totloop;
|
||||
loop_index++) {
|
||||
const MLoop *ml = &coarse_mesh->mloop[loop_index];
|
||||
|
||||
if (dverts != nullptr) {
|
||||
const MDeformVert *dvert = &dverts[ml->v];
|
||||
coarse_weights_data[loop_index] = evaluate_vertex_weight(dvert, wstate);
|
||||
}
|
||||
else {
|
||||
coarse_weights_data[loop_index] = evaluate_vertex_weight(nullptr, wstate);
|
||||
}
|
||||
if (mr->extract_type != MR_EXTRACT_BMESH) {
|
||||
for (int i = 0; i < coarse_mesh->totpoly; i++) {
|
||||
const MPoly *mpoly = &coarse_mesh->mpoly[i];
|
||||
extract_weights_iter_poly_mesh(mr, mpoly, i, _data);
|
||||
}
|
||||
}
|
||||
else {
|
||||
BMIter f_iter;
|
||||
BMFace *efa;
|
||||
int face_index = 0;
|
||||
BM_ITER_MESH_INDEX (efa, &f_iter, mr->bm, BM_FACES_OF_MESH, face_index) {
|
||||
extract_weights_iter_poly_bm(mr, efa, face_index, _data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user