From 76c55875319d1d41f01406bbaff17abde8e46a9b Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 19 Mar 2024 15:14:35 -0400 Subject: [PATCH] Cleanup: Rename mesh render SortedFaceData fields Try to add a bit more clarity and use more consistent wording. --- .../blender/draw/intern/draw_cache_extract.hh | 12 ++++---- .../draw_cache_extract_mesh_render_data.cc | 30 +++++++++---------- .../mesh_extractors/extract_mesh_ibo_tris.cc | 14 ++++----- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/source/blender/draw/intern/draw_cache_extract.hh b/source/blender/draw/intern/draw_cache_extract.hh index 694b967d43e..adecf90cb1c 100644 --- a/source/blender/draw/intern/draw_cache_extract.hh +++ b/source/blender/draw/intern/draw_cache_extract.hh @@ -217,12 +217,14 @@ struct MeshExtractLooseGeom { }; struct SortedFaceData { - /** The first triangle index for each polygon, sorted into slices by material. */ - Array tri_first_index; - /** The number of visible triangles assigned to each material. */ - Array mat_tri_len; - /* The total number of visible triangles (a sum of the values in #mat_tri_len). */ + /* The total number of visible triangles (a sum of the values in #mat_tri_counts). */ int visible_tris_num; + /** The number of visible triangles assigned to each material. */ + Array tris_num_by_material; + /** + * The first triangle index for each face, sorted into slices by material. + */ + Array face_tri_offsets; }; /** 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 2dfcc353e81..9e7234e0bc3 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 @@ -246,21 +246,21 @@ static Array mesh_render_data_mat_tri_len_build(const MeshRenderData &mr) accumululate_material_counts_mesh(mr, all_tri_counts); } - Array &mat_tri_len = all_tri_counts.local(); + Array &tris_num_by_material = all_tri_counts.local(); for (const Array &counts : all_tri_counts) { - if (&counts != &mat_tri_len) { - for (const int i : mat_tri_len.index_range()) { - mat_tri_len[i] += counts[i]; + if (&counts != &tris_num_by_material) { + for (const int i : tris_num_by_material.index_range()) { + tris_num_by_material[i] += counts[i]; } } } - return std::move(mat_tri_len); + return std::move(tris_num_by_material); } static void mesh_render_data_faces_sorted_build(MeshRenderData &mr, MeshBufferCache &cache) { - cache.face_sorted.mat_tri_len = mesh_render_data_mat_tri_len_build(mr); - const Span mat_tri_len = cache.face_sorted.mat_tri_len; + cache.face_sorted.tris_num_by_material = mesh_render_data_mat_tri_len_build(mr); + const Span tris_num_by_material = cache.face_sorted.tris_num_by_material; /* Apply offset. */ int visible_tris_num = 0; @@ -268,13 +268,13 @@ static void mesh_render_data_faces_sorted_build(MeshRenderData &mr, MeshBufferCa { for (int i = 0; i < mr.materials_num; i++) { mat_tri_offs[i] = visible_tris_num; - visible_tris_num += mat_tri_len[i]; + visible_tris_num += tris_num_by_material[i]; } } cache.face_sorted.visible_tris_num = visible_tris_num; - cache.face_sorted.tri_first_index.reinitialize(mr.faces_num); - MutableSpan tri_first_index = cache.face_sorted.tri_first_index; + cache.face_sorted.face_tri_offsets.reinitialize(mr.faces_num); + MutableSpan face_tri_offsets = cache.face_sorted.face_tri_offsets; /* Sort per material. */ int mat_last = mr.materials_num - 1; @@ -285,11 +285,11 @@ static void mesh_render_data_faces_sorted_build(MeshRenderData &mr, MeshBufferCa BM_ITER_MESH_INDEX (f, &iter, mr.bm, BM_FACES_OF_MESH, i) { if (!BM_elem_flag_test(f, BM_ELEM_HIDDEN)) { const int mat = clamp_i(f->mat_nr, 0, mat_last); - tri_first_index[i] = mat_tri_offs[mat]; + face_tri_offsets[i] = mat_tri_offs[mat]; mat_tri_offs[mat] += f->len - 2; } else { - tri_first_index[i] = -1; + face_tri_offsets[i] = -1; } } } @@ -299,11 +299,11 @@ static void mesh_render_data_faces_sorted_build(MeshRenderData &mr, MeshBufferCa const int mat = mr.material_indices.is_empty() ? 0 : clamp_i(mr.material_indices[i], 0, mat_last); - tri_first_index[i] = mat_tri_offs[mat]; + face_tri_offsets[i] = mat_tri_offs[mat]; mat_tri_offs[mat] += mr.faces[i].size() - 2; } else { - tri_first_index[i] = -1; + face_tri_offsets[i] = -1; } } } @@ -311,7 +311,7 @@ static void mesh_render_data_faces_sorted_build(MeshRenderData &mr, MeshBufferCa static void mesh_render_data_faces_sorted_ensure(MeshRenderData &mr, MeshBufferCache &cache) { - if (!cache.face_sorted.tri_first_index.is_empty()) { + if (!cache.face_sorted.face_tri_offsets.is_empty()) { return; } mesh_render_data_faces_sorted_build(mr, cache); diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_tris.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_tris.cc index 5e8ab4e60ba..5b3557e1ec0 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_tris.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_tris.cc @@ -41,8 +41,8 @@ static void extract_tris_iter_face_bm(const MeshRenderData &mr, const int f_index, void *_data) { - int tri_first_index = mr.face_sorted->tri_first_index[f_index]; - if (tri_first_index == -1) { + int tri_offset = mr.face_sorted->face_tri_offsets[f_index]; + if (tri_offset == -1) { return; } @@ -53,7 +53,7 @@ static void extract_tris_iter_face_bm(const MeshRenderData &mr, int tri_len = f->len - 2; for (int offs = 0; offs < tri_len; offs++) { BMLoop **elt = looptris[tri_first_index_real + offs]; - int tri_index = tri_first_index + offs; + int tri_index = tri_offset + offs; GPU_indexbuf_set_tri_verts(elb, tri_index, BM_elem_index_get(elt[0]), @@ -66,8 +66,8 @@ static void extract_tris_iter_face_mesh(const MeshRenderData &mr, const int face_index, void *_data) { - int tri_first_index = mr.face_sorted->tri_first_index[face_index]; - if (tri_first_index == -1) { + int tri_offset = mr.face_sorted->face_tri_offsets[face_index]; + if (tri_offset == -1) { return; } @@ -79,7 +79,7 @@ static void extract_tris_iter_face_mesh(const MeshRenderData &mr, int tri_len = face.size() - 2; for (int offs = 0; offs < tri_len; offs++) { const int3 &tri = mr.corner_tris[tri_first_index_real + offs]; - int tri_index = tri_first_index + offs; + int tri_index = tri_offset + offs; GPU_indexbuf_set_tri_verts(elb, tri_index, tri[0], tri[1], tri[2]); } } @@ -103,7 +103,7 @@ static void extract_tris_finish(const MeshRenderData &mr, if (cache.tris_per_mat[i] == nullptr) { cache.tris_per_mat[i] = GPU_indexbuf_calloc(); } - const int mat_tri_len = mr.face_sorted->mat_tri_len[i]; + const int mat_tri_len = mr.face_sorted->tris_num_by_material[i]; /* Multiply by 3 because these are triangle indices. */ const int start = mat_start * 3; const int len = mat_tri_len * 3;