Differential D14365 Diff 59272 source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_uv.cc
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_uv.cc
| Show All 11 Lines | |||||
| namespace blender::draw { | namespace blender::draw { | ||||
| /* ---------------------------------------------------------------------- */ | /* ---------------------------------------------------------------------- */ | ||||
| /** \name Extract Face-dots UV | /** \name Extract Face-dots UV | ||||
| * \{ */ | * \{ */ | ||||
| struct MeshExtract_FdotUV_Data { | struct MeshExtract_FdotUV_Data { | ||||
| float (*vbo_data)[2]; | float (*vbo_data)[2]; | ||||
| const MLoopUV *uv_data; | const float (*uv_data)[2]; | ||||
| int cd_ofs; | int cd_ofs; | ||||
| }; | }; | ||||
| static void extract_fdots_uv_init(const MeshRenderData *mr, | static void extract_fdots_uv_init(const MeshRenderData *mr, | ||||
| MeshBatchCache * /*cache*/, | MeshBatchCache * /*cache*/, | ||||
| void *buf, | void *buf, | ||||
| void *tls_data) | void *tls_data) | ||||
| { | { | ||||
| Show All 12 Lines | if (!mr->use_subsurf_fdots) { | ||||
| /* Clear so we can accumulate on it. */ | /* Clear so we can accumulate on it. */ | ||||
| memset(GPU_vertbuf_get_data(vbo), 0x0, mr->poly_len * GPU_vertbuf_get_format(vbo)->stride); | memset(GPU_vertbuf_get_data(vbo), 0x0, mr->poly_len * GPU_vertbuf_get_format(vbo)->stride); | ||||
| } | } | ||||
| MeshExtract_FdotUV_Data *data = static_cast<MeshExtract_FdotUV_Data *>(tls_data); | MeshExtract_FdotUV_Data *data = static_cast<MeshExtract_FdotUV_Data *>(tls_data); | ||||
| data->vbo_data = (float(*)[2])GPU_vertbuf_get_data(vbo); | data->vbo_data = (float(*)[2])GPU_vertbuf_get_data(vbo); | ||||
| if (mr->extract_type == MR_EXTRACT_BMESH) { | if (mr->extract_type == MR_EXTRACT_BMESH) { | ||||
| data->cd_ofs = CustomData_get_offset(&mr->bm->ldata, CD_MLOOPUV); | data->cd_ofs = CustomData_get_offset(&mr->bm->ldata, CD_PROP_FLOAT2); | ||||
| } | } | ||||
| else { | else { | ||||
| data->uv_data = (const MLoopUV *)CustomData_get_layer(&mr->me->ldata, CD_MLOOPUV); | data->uv_data = (const float(*)[2])CustomData_get_layer(&mr->me->ldata, CD_PROP_FLOAT2); | ||||
| } | } | ||||
| } | } | ||||
| static void extract_fdots_uv_iter_poly_bm(const MeshRenderData * /*mr*/, | static void extract_fdots_uv_iter_poly_bm(const MeshRenderData * /*mr*/, | ||||
| const BMFace *f, | const BMFace *f, | ||||
| const int /*f_index*/, | const int /*f_index*/, | ||||
| void *_data) | void *_data) | ||||
| { | { | ||||
| MeshExtract_FdotUV_Data *data = static_cast<MeshExtract_FdotUV_Data *>(_data); | MeshExtract_FdotUV_Data *data = static_cast<MeshExtract_FdotUV_Data *>(_data); | ||||
| BMLoop *l_iter, *l_first; | BMLoop *l_iter, *l_first; | ||||
| l_iter = l_first = BM_FACE_FIRST_LOOP(f); | l_iter = l_first = BM_FACE_FIRST_LOOP(f); | ||||
| do { | do { | ||||
| float w = 1.0f / float(f->len); | float w = 1.0f / float(f->len); | ||||
| const MLoopUV *luv = (const MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_iter, data->cd_ofs); | const float *luv = BM_ELEM_CD_GET_FLOAT_P(l_iter, data->cd_ofs); | ||||
| madd_v2_v2fl(data->vbo_data[BM_elem_index_get(f)], luv->uv, w); | madd_v2_v2fl(data->vbo_data[BM_elem_index_get(f)], luv, w); | ||||
| } while ((l_iter = l_iter->next) != l_first); | } while ((l_iter = l_iter->next) != l_first); | ||||
| } | } | ||||
| static void extract_fdots_uv_iter_poly_mesh(const MeshRenderData *mr, | static void extract_fdots_uv_iter_poly_mesh(const MeshRenderData *mr, | ||||
| const MPoly *mp, | const MPoly *mp, | ||||
| const int mp_index, | const int mp_index, | ||||
| void *_data) | void *_data) | ||||
| { | { | ||||
| MeshExtract_FdotUV_Data *data = static_cast<MeshExtract_FdotUV_Data *>(_data); | MeshExtract_FdotUV_Data *data = static_cast<MeshExtract_FdotUV_Data *>(_data); | ||||
| const BLI_bitmap *facedot_tags = mr->me->runtime->subsurf_face_dot_tags; | const BLI_bitmap *facedot_tags = mr->me->runtime->subsurf_face_dot_tags; | ||||
| const MLoop *mloop = mr->mloop; | const MLoop *mloop = mr->mloop; | ||||
| const int ml_index_end = mp->loopstart + mp->totloop; | const int ml_index_end = mp->loopstart + mp->totloop; | ||||
| for (int ml_index = mp->loopstart; ml_index < ml_index_end; ml_index += 1) { | for (int ml_index = mp->loopstart; ml_index < ml_index_end; ml_index += 1) { | ||||
| const MLoop *ml = &mloop[ml_index]; | const MLoop *ml = &mloop[ml_index]; | ||||
| if (mr->use_subsurf_fdots) { | if (mr->use_subsurf_fdots) { | ||||
| if (BLI_BITMAP_TEST(facedot_tags, ml->v)) { | if (BLI_BITMAP_TEST(facedot_tags, ml->v)) { | ||||
| copy_v2_v2(data->vbo_data[mp_index], data->uv_data[ml_index].uv); | copy_v2_v2(data->vbo_data[mp_index], data->uv_data[ml_index]); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| float w = 1.0f / float(mp->totloop); | float w = 1.0f / float(mp->totloop); | ||||
| madd_v2_v2fl(data->vbo_data[mp_index], data->uv_data[ml_index].uv, w); | madd_v2_v2fl(data->vbo_data[mp_index], data->uv_data[ml_index], w); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| constexpr MeshExtract create_extractor_fdots_uv() | constexpr MeshExtract create_extractor_fdots_uv() | ||||
| { | { | ||||
| MeshExtract extractor = {nullptr}; | MeshExtract extractor = {nullptr}; | ||||
| extractor.init = extract_fdots_uv_init; | extractor.init = extract_fdots_uv_init; | ||||
| Show All 14 Lines | |||||