diff options
author | Hans Goudey <h.goudey@me.com> | 2022-09-23 16:23:35 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-09-23 16:23:35 +0300 |
commit | 0d7d8c73cf5c5c5f05c6a56951e4e5cd24871c12 (patch) | |
tree | eb4462fdebcef4afca161d1257ecb7a78d298cec /source/blender/draw | |
parent | 060a5341419412fd7996cf99a56db1f581a4c30c (diff) |
Mesh: Use cached looptris in draw cache extraction
The mesh's triangulation cache is often created for other operations
besides the drawing code, but during the mesh draw cache extraction
it is recalculated on every single time. It is simpler and faster to use
the existing MLoopTri array. It can also save memory if the cache
already exists by avoiding allocating a duplicate array. For a 4 million
face quad mesh, that is already 128 MB.
Also use face normals for mesh triangulation if they aren't dirty,
which should provide a general speedup when they're both necessary.
Recently 54182e4925de made this more reliable, since the triangulation
cache is invalidated properly when the mesh is deformed.
Fixes T98073
Differential Revision: https://developer.blender.org/D15550
Diffstat (limited to 'source/blender/draw')
-rw-r--r-- | source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc | 22 | ||||
-rw-r--r-- | source/blender/draw/intern/mesh_extractors/extract_mesh.hh | 4 |
2 files changed, 4 insertions, 22 deletions
diff --git a/source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc b/source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc index eea19cbebf3..2fc54da774d 100644 --- a/source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc +++ b/source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc @@ -18,6 +18,7 @@ #include "BKE_editmesh.h" #include "BKE_editmesh_cache.h" #include "BKE_mesh.h" +#include "BKE_mesh_runtime.h" #include "GPU_batch.h" @@ -329,28 +330,10 @@ void mesh_render_data_update_looptris(MeshRenderData *mr, const eMRIterType iter_type, const eMRDataType data_flag) { - Mesh *me = mr->me; if (mr->extract_type != MR_EXTRACT_BMESH) { /* Mesh */ if ((iter_type & MR_ITER_LOOPTRI) || (data_flag & MR_DATA_LOOPTRI)) { - /* NOTE(@campbellbarton): It's possible to skip allocating tessellation, - * 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); - } + mr->mlooptri = BKE_mesh_runtime_looptri_ensure(mr->me); } } else { @@ -605,7 +588,6 @@ MeshRenderData *mesh_render_data_create(Object *object, void mesh_render_data_free(MeshRenderData *mr) { - MEM_SAFE_FREE(mr->mlooptri); MEM_SAFE_FREE(mr->loop_normals); /* Loose geometry are owned by #MeshBufferCache. */ diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh.hh b/source/blender/draw/intern/mesh_extractors/extract_mesh.hh index 10b94291e35..2a8b7332cc5 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh.hh +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh.hh @@ -78,8 +78,8 @@ struct MeshRenderData { BMEdge *eed_act; BMFace *efa_act; BMFace *efa_act_uv; - /* Data created on-demand (usually not for #BMesh based data). */ - MLoopTri *mlooptri; + /* The triangulation of #Mesh polygons, owned by the mesh. */ + const MLoopTri *mlooptri; const int *material_indices; const float (*vert_normals)[3]; const float (*poly_normals)[3]; |