Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc
| Show All 12 Lines | |||||
| #include "BLI_bitmap.h" | #include "BLI_bitmap.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_task.h" | #include "BLI_task.h" | ||||
| #include "BKE_attribute.hh" | #include "BKE_attribute.hh" | ||||
| #include "BKE_editmesh.h" | #include "BKE_editmesh.h" | ||||
| #include "BKE_editmesh_cache.h" | #include "BKE_editmesh_cache.h" | ||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| #include "BKE_mesh_runtime.h" | |||||
| #include "GPU_batch.h" | #include "GPU_batch.h" | ||||
| #include "ED_mesh.h" | #include "ED_mesh.h" | ||||
| #include "mesh_extractors/extract_mesh.hh" | #include "mesh_extractors/extract_mesh.hh" | ||||
| /* ---------------------------------------------------------------------- */ | /* ---------------------------------------------------------------------- */ | ||||
| ▲ Show 20 Lines • Show All 295 Lines • ▼ Show 20 Lines | |||||
| /* ---------------------------------------------------------------------- */ | /* ---------------------------------------------------------------------- */ | ||||
| /** \name Mesh/BMesh Interface (indirect, partially cached access to complex data). | /** \name Mesh/BMesh Interface (indirect, partially cached access to complex data). | ||||
| * \{ */ | * \{ */ | ||||
| void mesh_render_data_update_looptris(MeshRenderData *mr, | void mesh_render_data_update_looptris(MeshRenderData *mr, | ||||
| const eMRIterType iter_type, | const eMRIterType iter_type, | ||||
| const eMRDataType data_flag) | const eMRDataType data_flag) | ||||
| { | { | ||||
| Mesh *me = mr->me; | |||||
| if (mr->extract_type != MR_EXTRACT_BMESH) { | if (mr->extract_type != MR_EXTRACT_BMESH) { | ||||
| /* Mesh */ | /* Mesh */ | ||||
| if ((iter_type & MR_ITER_LOOPTRI) || (data_flag & MR_DATA_LOOPTRI)) { | if ((iter_type & MR_ITER_LOOPTRI) || (data_flag & MR_DATA_LOOPTRI)) { | ||||
| /* NOTE(@campbellbarton): It's possible to skip allocating tessellation, | mr->mlooptri = BKE_mesh_runtime_looptri_ensure(mr->me); | ||||
| * the tessellation can be calculated as part of the iterator, see: P2188. | |||||
| * The overall advantage is small (around 1%), so keep this as-is. */ | |||||
| mr->mlooptri = static_cast<MLoopTri *>( | |||||
| MEM_mallocN(sizeof(*mr->mlooptri) * mr->tri_len, "MR_DATATYPE_LOOPTRI")); | |||||
| if (mr->poly_normals != nullptr) { | |||||
| BKE_mesh_recalc_looptri_with_normals(mr->mloop, | |||||
| mr->mpoly, | |||||
| mr->mvert, | |||||
| me->totloop, | |||||
| me->totpoly, | |||||
| mr->mlooptri, | |||||
| mr->poly_normals); | |||||
| } | |||||
| else { | |||||
| BKE_mesh_recalc_looptri( | |||||
| mr->mloop, mr->mpoly, mr->mvert, me->totloop, me->totpoly, mr->mlooptri); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* #BMesh */ | /* #BMesh */ | ||||
| if ((iter_type & MR_ITER_LOOPTRI) || (data_flag & MR_DATA_LOOPTRI)) { | if ((iter_type & MR_ITER_LOOPTRI) || (data_flag & MR_DATA_LOOPTRI)) { | ||||
| /* Edit mode ensures this is valid, no need to calculate. */ | /* Edit mode ensures this is valid, no need to calculate. */ | ||||
| BLI_assert((mr->bm->totloop == 0) || (mr->edit_bmesh->looptris != nullptr)); | BLI_assert((mr->bm->totloop == 0) || (mr->edit_bmesh->looptris != nullptr)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 238 Lines • ▼ Show 20 Lines | #endif | ||||
| retrieve_active_attribute_names(*mr, *object, *me); | retrieve_active_attribute_names(*mr, *object, *me); | ||||
| return mr; | return mr; | ||||
| } | } | ||||
| void mesh_render_data_free(MeshRenderData *mr) | void mesh_render_data_free(MeshRenderData *mr) | ||||
| { | { | ||||
| MEM_SAFE_FREE(mr->mlooptri); | |||||
| MEM_SAFE_FREE(mr->loop_normals); | MEM_SAFE_FREE(mr->loop_normals); | ||||
| /* Loose geometry are owned by #MeshBufferCache. */ | /* Loose geometry are owned by #MeshBufferCache. */ | ||||
| mr->ledges = nullptr; | mr->ledges = nullptr; | ||||
| mr->lverts = nullptr; | mr->lverts = nullptr; | ||||
| MEM_freeN(mr); | MEM_freeN(mr); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||