TriangleSelector - some memory optimization.

Don't store traingle normal, but reference the source triangle,
which stores its normal.
This commit is contained in:
Vojtech Bubnik 2021-06-11 12:27:58 +02:00
parent 74ab3e108e
commit 6bade1b24a
5 changed files with 49 additions and 59 deletions

View file

@ -76,19 +76,21 @@ protected:
public:
// Use TriangleSelector::push_triangle to create a new triangle.
// It increments/decrements reference counter on vertices.
Triangle(int a, int b, int c, const Vec3f& normal_, const EnforcerBlockerType init_state)
Triangle(int a, int b, int c, int source_triangle, const EnforcerBlockerType init_state)
: verts_idxs{a, b, c},
normal{normal_},
state{init_state},
number_of_splits{0},
special_side_idx{0},
old_number_of_splits{0}
{}
source_triangle{source_triangle},
state{init_state}
{
// Initialize bit fields. Default member initializers are not supported by C++17.
m_selected_by_seed_fill = false;
m_valid = true;
old_number_of_splits = 0;
}
// Indices into m_vertices.
std::array<int, 3> verts_idxs;
// Triangle normal (a shader might need it).
Vec3f normal;
// Index of the source triangle at the initial (unsplit) mesh.
int source_triangle;
// Children triangles.
std::array<int, 4> children;
@ -118,16 +120,20 @@ protected:
private:
friend TriangleSelector;
int number_of_splits;
int special_side_idx;
// Packing the rest of member variables into 4 bytes, aligned to 4 bytes boundary.
char number_of_splits { 0 };
// Index of a vertex opposite to the split edge (for number_of_splits == 1)
// or index of a vertex shared by the two split edges (for number_of_splits == 2).
// For number_of_splits == 3, special_side_idx is always zero.
char special_side_idx { 0 };
EnforcerBlockerType state;
bool m_selected_by_seed_fill = false;
bool m_selected_by_seed_fill : 1;
// Is this triangle valid or marked to be removed?
bool m_valid{true};
bool m_valid : 1;
// How many children were spawned during last split?
// Is not reset on remerging the triangle.
int old_number_of_splits;
char old_number_of_splits : 2;
};
struct Vertex {
@ -185,7 +191,7 @@ private:
void remove_useless_children(int facet_idx); // No hidden meaning. Triangles are meant.
bool is_pointer_in_triangle(int facet_idx) const;
bool is_edge_inside_cursor(int facet_idx) const;
void push_triangle(int a, int b, int c, const Vec3f &normal, const EnforcerBlockerType state = EnforcerBlockerType{0});
void push_triangle(int a, int b, int c, int source_triangle, const EnforcerBlockerType state = EnforcerBlockerType{0});
void perform_split(int facet_idx, EnforcerBlockerType old_state);
};