Refactor: Nodes: precompute node extra info rows
Previously, the extra info rows were computed twice per node on each redraw. Now, they are only computed once. Pull Request: https://projects.blender.org/blender/blender/pulls/139708
This commit is contained in:
@@ -153,6 +153,12 @@ struct TreeDrawContext {
|
||||
* Label for reroute nodes that is derived from upstream reroute nodes.
|
||||
*/
|
||||
Map<const bNode *, StringRef> reroute_auto_labels;
|
||||
|
||||
/**
|
||||
* Precomputed extra info rows for each node. This avoids having to compute them multiple times
|
||||
* during drawing. The array is indexed by `bNode::index()`.
|
||||
*/
|
||||
Array<Vector<NodeExtraInfoRow>> extra_info_rows_per_node;
|
||||
};
|
||||
|
||||
float grid_size_get()
|
||||
@@ -3266,7 +3272,8 @@ static void node_draw_extra_info_panel(const bContext &C,
|
||||
/* If the preview has an non-drawable size, just don't draw it. */
|
||||
preview = nullptr;
|
||||
}
|
||||
Vector<NodeExtraInfoRow> extra_info_rows = node_get_extra_info(C, tree_draw_ctx, snode, node);
|
||||
const Span<NodeExtraInfoRow> extra_info_rows =
|
||||
tree_draw_ctx.extra_info_rows_per_node[node.index()];
|
||||
if (extra_info_rows.is_empty() && !preview) {
|
||||
return;
|
||||
}
|
||||
@@ -4159,7 +4166,7 @@ static rctf calc_node_frame_dimensions(const bContext &C,
|
||||
* This has to get the full extra_rows information (including all the text strings), even
|
||||
* though all that's actually needed is the count of how many info_rows there are. */
|
||||
if (snode.overlay.flag & SN_OVERLAY_SHOW_OVERLAYS) {
|
||||
extra_row_padding = node_get_extra_info(C, tree_draw_ctx, snode, node).size() *
|
||||
extra_row_padding = tree_draw_ctx.extra_info_rows_per_node[node.index()].size() *
|
||||
EXTRA_INFO_ROW_HEIGHT;
|
||||
}
|
||||
|
||||
@@ -5282,6 +5289,7 @@ static void draw_nodetree(const bContext &C,
|
||||
tree_draw_ctx.scene = CTX_data_scene(&C);
|
||||
tree_draw_ctx.region = CTX_wm_region(&C);
|
||||
tree_draw_ctx.depsgraph = CTX_data_depsgraph_pointer(&C);
|
||||
tree_draw_ctx.extra_info_rows_per_node.reinitialize(nodes.size());
|
||||
|
||||
BLI_SCOPED_DEFER([&]() { ntree.runtime->sockets_on_active_gizmo_paths.clear(); });
|
||||
if (ntree.type == NTREE_GEOMETRY) {
|
||||
@@ -5312,6 +5320,12 @@ static void draw_nodetree(const bContext &C,
|
||||
tree_draw_ctx.nested_group_infos = get_nested_previews(C, *snode);
|
||||
}
|
||||
|
||||
for (const int i : nodes.index_range()) {
|
||||
const bNode &node = *nodes[i];
|
||||
tree_draw_ctx.extra_info_rows_per_node[node.index()] = node_get_extra_info(
|
||||
C, tree_draw_ctx, *snode, node);
|
||||
}
|
||||
|
||||
node_update_nodetree(C, tree_draw_ctx, ntree, nodes, blocks);
|
||||
node_draw_zones_and_frames(region, *snode, ntree);
|
||||
node_draw_nodetree(C, tree_draw_ctx, region, *snode, ntree, nodes, blocks, parent_key);
|
||||
|
||||
Reference in New Issue
Block a user