Cleanup: Remove unnecessary PBVH attribute pointer
Material indices are only used when the structure is built. It's simpler not to keep a longer-term reference available if it isn't needed.
This commit is contained in:
@@ -155,13 +155,13 @@ static void update_node_vb(PBVH *pbvh, PBVHNode *node)
|
||||
// BB_expand(&node->vb, co);
|
||||
//}
|
||||
|
||||
static bool face_materials_match(const PBVH *pbvh,
|
||||
static bool face_materials_match(const int *material_indices,
|
||||
const bool *sharp_faces,
|
||||
const int a,
|
||||
const int b)
|
||||
{
|
||||
if (pbvh->material_indices) {
|
||||
if (pbvh->material_indices[a] != pbvh->material_indices[b]) {
|
||||
if (material_indices) {
|
||||
if (material_indices[a] != material_indices[b]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -241,7 +241,8 @@ static int partition_indices_grids(int *prim_indices,
|
||||
}
|
||||
|
||||
/* Returns the index of the first element on the right of the partition */
|
||||
static int partition_indices_material(PBVH *pbvh, const bool *sharp_faces, int lo, int hi)
|
||||
static int partition_indices_material(
|
||||
PBVH *pbvh, const int *material_indices, const bool *sharp_faces, int lo, int hi)
|
||||
{
|
||||
const MLoopTri *looptri = pbvh->looptri;
|
||||
const DMFlagMat *flagmats = pbvh->grid_flag_mats;
|
||||
@@ -251,10 +252,12 @@ static int partition_indices_material(PBVH *pbvh, const bool *sharp_faces, int l
|
||||
for (;;) {
|
||||
if (pbvh->looptri) {
|
||||
const int first = looptri[pbvh->prim_indices[lo]].poly;
|
||||
for (; face_materials_match(pbvh, sharp_faces, first, looptri[indices[i]].poly); i++) {
|
||||
for (; face_materials_match(material_indices, sharp_faces, first, looptri[indices[i]].poly);
|
||||
i++) {
|
||||
/* pass */
|
||||
}
|
||||
for (; !face_materials_match(pbvh, sharp_faces, first, looptri[indices[j]].poly); j--) {
|
||||
for (; !face_materials_match(material_indices, sharp_faces, first, looptri[indices[j]].poly);
|
||||
j--) {
|
||||
/* pass */
|
||||
}
|
||||
}
|
||||
@@ -462,7 +465,8 @@ static void build_leaf(PBVH *pbvh, int node_index, BBC *prim_bbc, int offset, in
|
||||
|
||||
/* Return zero if all primitives in the node can be drawn with the
|
||||
* same material (including flat/smooth shading), non-zero otherwise */
|
||||
static bool leaf_needs_material_split(PBVH *pbvh, const bool *sharp_faces, int offset, int count)
|
||||
static bool leaf_needs_material_split(
|
||||
PBVH *pbvh, const int *material_indices, const bool *sharp_faces, int offset, int count)
|
||||
{
|
||||
if (count <= 1) {
|
||||
return false;
|
||||
@@ -472,7 +476,8 @@ static bool leaf_needs_material_split(PBVH *pbvh, const bool *sharp_faces, int o
|
||||
const MLoopTri *first = &pbvh->looptri[pbvh->prim_indices[offset]];
|
||||
for (int i = offset + count - 1; i > offset; i--) {
|
||||
int prim = pbvh->prim_indices[i];
|
||||
if (!face_materials_match(pbvh, sharp_faces, first->poly, pbvh->looptri[prim].poly)) {
|
||||
if (!face_materials_match(
|
||||
material_indices, sharp_faces, first->poly, pbvh->looptri[prim].poly)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -551,6 +556,7 @@ static void test_face_boundaries(PBVH *pbvh)
|
||||
*/
|
||||
|
||||
static void build_sub(PBVH *pbvh,
|
||||
const int *material_indices,
|
||||
const bool *sharp_faces,
|
||||
int node_index,
|
||||
BB *cb,
|
||||
@@ -570,7 +576,7 @@ static void build_sub(PBVH *pbvh,
|
||||
/* Decide whether this is a leaf or not */
|
||||
const bool below_leaf_limit = count <= pbvh->leaf_limit || depth >= STACK_FIXED_DEPTH - 1;
|
||||
if (below_leaf_limit) {
|
||||
if (!leaf_needs_material_split(pbvh, sharp_faces, offset, count)) {
|
||||
if (!leaf_needs_material_split(pbvh, material_indices, sharp_faces, offset, count)) {
|
||||
build_leaf(pbvh, node_index, prim_bbc, offset, count);
|
||||
|
||||
if (node_index == 0) {
|
||||
@@ -623,11 +629,13 @@ static void build_sub(PBVH *pbvh,
|
||||
}
|
||||
else {
|
||||
/* Partition primitives by material */
|
||||
end = partition_indices_material(pbvh, sharp_faces, offset, offset + count - 1);
|
||||
end = partition_indices_material(
|
||||
pbvh, material_indices, sharp_faces, offset, offset + count - 1);
|
||||
}
|
||||
|
||||
/* Build children */
|
||||
build_sub(pbvh,
|
||||
material_indices,
|
||||
sharp_faces,
|
||||
pbvh->nodes[node_index].children_offset,
|
||||
nullptr,
|
||||
@@ -637,6 +645,7 @@ static void build_sub(PBVH *pbvh,
|
||||
prim_scratch,
|
||||
depth + 1);
|
||||
build_sub(pbvh,
|
||||
material_indices,
|
||||
sharp_faces,
|
||||
pbvh->nodes[node_index].children_offset + 1,
|
||||
nullptr,
|
||||
@@ -651,7 +660,12 @@ static void build_sub(PBVH *pbvh,
|
||||
}
|
||||
}
|
||||
|
||||
static void pbvh_build(PBVH *pbvh, const bool *sharp_faces, BB *cb, BBC *prim_bbc, int totprim)
|
||||
static void pbvh_build(PBVH *pbvh,
|
||||
const int *material_indices,
|
||||
const bool *sharp_faces,
|
||||
BB *cb,
|
||||
BBC *prim_bbc,
|
||||
int totprim)
|
||||
{
|
||||
if (totprim != pbvh->totprim) {
|
||||
pbvh->totprim = totprim;
|
||||
@@ -674,7 +688,7 @@ static void pbvh_build(PBVH *pbvh, const bool *sharp_faces, BB *cb, BBC *prim_bb
|
||||
}
|
||||
|
||||
pbvh->totnode = 1;
|
||||
build_sub(pbvh, sharp_faces, 0, cb, prim_bbc, 0, totprim, nullptr, 0);
|
||||
build_sub(pbvh, material_indices, sharp_faces, 0, cb, prim_bbc, 0, totprim, nullptr, 0);
|
||||
}
|
||||
|
||||
static void pbvh_draw_args_init(PBVH *pbvh, PBVH_GPU_Args *args, PBVHNode *node)
|
||||
@@ -839,8 +853,6 @@ void BKE_pbvh_update_mesh_pointers(PBVH *pbvh, Mesh *mesh)
|
||||
pbvh->vert_positions = BKE_mesh_vert_positions_for_write(mesh);
|
||||
}
|
||||
|
||||
pbvh->material_indices = static_cast<const int *>(
|
||||
CustomData_get_layer_named(&mesh->pdata, CD_PROP_INT32, "material_index"));
|
||||
pbvh->hide_poly = static_cast<bool *>(CustomData_get_layer_named_for_write(
|
||||
&mesh->pdata, CD_PROP_BOOL, ".hide_poly", mesh->totpoly));
|
||||
pbvh->hide_vert = static_cast<bool *>(CustomData_get_layer_named_for_write(
|
||||
@@ -919,9 +931,11 @@ void BKE_pbvh_build_mesh(PBVH *pbvh, Mesh *mesh)
|
||||
}
|
||||
|
||||
if (looptri_num) {
|
||||
const int *material_indices = static_cast<const int *>(
|
||||
CustomData_get_layer_named(&mesh->pdata, CD_PROP_INT32, "material_index"));
|
||||
const bool *sharp_faces = (const bool *)CustomData_get_layer_named(
|
||||
&mesh->pdata, CD_PROP_BOOL, "sharp_face");
|
||||
pbvh_build(pbvh, sharp_faces, &cb, prim_bbc, looptri_num);
|
||||
pbvh_build(pbvh, material_indices, sharp_faces, &cb, prim_bbc, looptri_num);
|
||||
|
||||
#ifdef TEST_PBVH_FACE_SPLIT
|
||||
test_face_boundaries(pbvh);
|
||||
@@ -1008,9 +1022,11 @@ void BKE_pbvh_build_grids(PBVH *pbvh,
|
||||
}
|
||||
|
||||
if (totgrid) {
|
||||
const int *material_indices = static_cast<const int *>(
|
||||
CustomData_get_layer_named(&me->pdata, CD_PROP_INT32, "material_index"));
|
||||
const bool *sharp_faces = (const bool *)CustomData_get_layer_named(
|
||||
&me->pdata, CD_PROP_BOOL, "sharp_face");
|
||||
pbvh_build(pbvh, sharp_faces, &cb, prim_bbc, totgrid);
|
||||
pbvh_build(pbvh, material_indices, sharp_faces, &cb, prim_bbc, totgrid);
|
||||
|
||||
#ifdef TEST_PBVH_FACE_SPLIT
|
||||
test_face_boundaries(pbvh);
|
||||
|
||||
@@ -157,8 +157,7 @@ struct PBVH {
|
||||
float (*vert_positions)[3];
|
||||
blender::OffsetIndices<int> polys;
|
||||
bool *hide_poly;
|
||||
/** Material indices. Only valid for polygon meshes. */
|
||||
const int *material_indices;
|
||||
/** Only valid for polygon meshes. */
|
||||
const int *corner_verts;
|
||||
/* Owned by the #PBVH, because after deformations they have to be recomputed. */
|
||||
const MLoopTri *looptri;
|
||||
|
||||
Reference in New Issue
Block a user