diff --git a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs index b6e2eed189..c0ad82aa3c 100644 --- a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs +++ b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs @@ -1222,14 +1222,16 @@ impl<'a> MessageHandler> for NodeG // Alt-click sets the clicked node as previewed if alt_click - && !read_only && let Some(clicked_node) = clicked_id + && !read_only + && let Some(clicked_node) = clicked_id { self.preview_on_mouse_up = Some(clicked_node); } // The second press of a double-click on a connector with wires drags a redirect dot out of it, once the pointer moves far enough to place the dot if is_double_press - && !read_only && let Some(source) = Self::dot_drag_out_source(clicked_input, clicked_output, network_interface, selection_network_path) + && !read_only + && let Some(source) = Self::dot_drag_out_source(clicked_input, clicked_output, network_interface, selection_network_path) { self.dot_drag_out = Some((source, node_graph_point)); self.double_click_used_by_press = true; @@ -1352,7 +1354,8 @@ impl<'a> MessageHandler> for NodeG // The second press of a double-click on a wire splits it with a redirect dot, which the press goes on to drag if is_double_press - && !read_only && let Some(input_connector) = Self::wire_at_point(node_graph_point, network_interface, preferences.graph_wire_style, selection_network_path) + && !read_only + && let Some(input_connector) = Self::wire_at_point(node_graph_point, network_interface, preferences.graph_wire_style, selection_network_path) { let dot = NodeId::new(); let center = (node_graph_point / GRID_SIZE as f64).round().as_ivec2(); diff --git a/editor/src/messages/portfolio/document/utility_types/network_interface/characterization_tests.rs b/editor/src/messages/portfolio/document/utility_types/network_interface/characterization_tests.rs index 1769b7895e..6bb57e7430 100644 --- a/editor/src/messages/portfolio/document/utility_types/network_interface/characterization_tests.rs +++ b/editor/src/messages/portfolio/document/utility_types/network_interface/characterization_tests.rs @@ -3,6 +3,7 @@ use super::{ NodeTemplate, NodeTemplateImplementation, NodeTypePersistentMetadata, OutputConnector, Previewing, RootNode, TransactionStatus, }; use crate::consts::{GRID_SIZE, LAYER_INDENT_OFFSET, STACK_VERTICAL_GAP, WIRE_DRAG_NODE_EXPAND_DELAY_MILLISECONDS}; +use crate::messages::input_mapper::utility_types::pointer::EditorPointerState; use crate::messages::portfolio::document::node_graph::document_node_definitions::resolve_proto_node_type; use crate::messages::portfolio::document::node_graph::utility_types::{ContextMenuData, Direction}; use crate::messages::portfolio::document::utility_types::misc::GroupFolderType; diff --git a/editor/src/node_graph_executor/runtime.rs b/editor/src/node_graph_executor/runtime.rs index 608c516c3c..8435fa808c 100644 --- a/editor/src/node_graph_executor/runtime.rs +++ b/editor/src/node_graph_executor/runtime.rs @@ -84,10 +84,11 @@ pub struct NodeRuntime { /// Whether the overlays or the artwork changed since the overlays were last rendered. overlays_stale: bool, overlays_canvas: VelloCanvas, - /// The latest rendered overlays. overlays_texture: Option, + overlays_redrawn: bool, graph_ui_scene: GraphUiScene, + graph_ui_stale: bool, graph_ui_output: OutputHandle, graph_ui_network_hash: Option, graph_ui_texture: Option, @@ -199,8 +200,10 @@ impl NodeRuntime { overlays_stale: false, overlays_canvas: VelloCanvas::default(), overlays_texture: None, + overlays_redrawn: false, graph_ui_scene: GraphUiScene::default(), + graph_ui_stale: false, graph_ui_output: OutputHandle::default(), graph_ui_network_hash: None, graph_ui_texture: None, @@ -302,9 +305,7 @@ impl NodeRuntime { { let mut responses = VecDeque::new(); let rendered = self.thumbnails.render_stale(&self.executor, &self.editor_api, &mut responses).await; - if rendered && let Some(request) = self.pending.filter(|request| request.graph_ui_config.is_some()) { - self.draw_graph_ui(request); - } + self.graph_ui_stale |= rendered; if !responses.is_empty() { self.sender.send(NodeGraphUpdate::Thumbnails { responses, document_id }).expect("Failed to send response"); } @@ -323,6 +324,11 @@ impl NodeRuntime { self.run_viewport(viewport).await; } + if let Some(request) = self.pending { + self.draw_overlays(&request); + self.draw_graph_ui(&request); + } + let texture = self.composite_viewport_frame(); (self.editor_wake)(); @@ -349,16 +355,41 @@ impl NodeRuntime { self.viewport_artwork = content; let path_contents = path_contents(&observations); self.rendered_layers = RenderedLayers::new(metadata, &path_contents, self.old_graph.as_ref()); - self.overlays_stale = true; } } self.respond(request, result, observations).await; - self.draw_graph_ui(request); + + self.overlays_stale = true; + self.graph_ui_stale = true; } - fn draw_graph_ui(&mut self, request: ExecutionRequest) { + fn draw_overlays(&mut self, request: &ExecutionRequest) { + if !std::mem::take(&mut self.overlays_stale) { + return; + } + self.overlays_redrawn = true; + if request.graph_ui_config.is_some() { + self.overlays_texture = None; + return; + } + + let Some(overlays) = &self.overlays else { return }; + let executor = self.editor_api.application_io.as_ref().and_then(|application_io| application_io.gpu_executor()); + if let Some(executor) = executor { + self.overlays_texture = executor + .render_vello_scene_on_canvas(&mut self.overlays_canvas, overlays.render(&self.rendered_layers)) + .inspect_err(|error| log::error!("Failed to render the overlays: {error:?}")) + .ok(); + } + } + + fn draw_graph_ui(&mut self, request: &ExecutionRequest) { + if !std::mem::take(&mut self.graph_ui_stale) { + return; + } self.graph_ui_redrawn = true; + let Some(mut config) = request.graph_ui_config else { self.graph_ui_texture = None; self.graph_ui_network_hash = None; @@ -407,7 +438,9 @@ impl NodeRuntime { } fn composite_viewport_frame(&mut self) -> Option { - if !std::mem::take(&mut self.graph_ui_redrawn) && !self.overlays_stale { + let graph_ui_redrawn = std::mem::take(&mut self.graph_ui_redrawn); + let overlays_redrawn = std::mem::take(&mut self.overlays_redrawn); + if !graph_ui_redrawn && !overlays_redrawn { return None; } if self.viewport_artwork.is_none() && self.graph_ui_texture.is_none() { @@ -415,26 +448,16 @@ impl NodeRuntime { } let executor = self.editor_api.application_io.as_ref().and_then(|application_io| application_io.gpu_executor())?; - if std::mem::take(&mut self.overlays_stale) - && let Some(overlays) = &self.overlays - { - self.overlays_texture = executor - .render_vello_scene_on_canvas(&mut self.overlays_canvas, overlays.render(&self.rendered_layers)) - .inspect_err(|error| log::error!("Failed to render the overlays: {error:?}")) - .ok(); - } - let artwork = match &self.viewport_artwork { Some(ViewportArtwork::Texture(artwork)) => Some(artwork), Some(ViewportArtwork::Svg) | None => None, }; - let overlays = self.overlays_texture.as_ref().filter(|_| self.graph_ui_texture.is_none()); - let frame = match (artwork, &self.graph_ui_texture, overlays) { + let frame = match (artwork, &self.graph_ui_texture, &self.overlays_texture) { (None, None, None) => return None, (Some(frame), None, None) | (None, Some(frame), None) | (None, None, Some(frame)) => frame.clone(), (artwork, graph_ui, overlays) => { // The node graph is drawn at the viewport's size, which artwork from before a resize doesn't have - let base = graph_ui.as_ref().or(artwork).or(overlays)?; + let base = graph_ui.as_ref().or(artwork).or(overlays.as_ref())?; let (width, height) = (base.width(), base.height()); let max_texture_size = executor.context().device.limits().max_texture_dimension_2d; diff --git a/editor/src/node_graph_executor/runtime/thumbnails.rs b/editor/src/node_graph_executor/runtime/thumbnails.rs index 5804de42bb..e59bf5311e 100644 --- a/editor/src/node_graph_executor/runtime/thumbnails.rs +++ b/editor/src/node_graph_executor/runtime/thumbnails.rs @@ -40,9 +40,9 @@ pub struct Thumbnails { sources: HashMap, /// The layers whose content changed since their thumbnail was last rendered. stale: HashSet, - unshown: HashSet, in_view: HashSet, in_layers_panel: HashSet, + stale_in_layers_panel: HashSet, /// The device pixel ratio thumbnails are rendered at. scale: f64, #[cfg(all(target_family = "wasm", feature = "wasm"))] @@ -59,7 +59,7 @@ impl Thumbnails { } pub fn set_in_view(&mut self, layers: HashSet, layers_panel: HashSet) { - self.stale.extend(self.unshown.extract_if(|layer| layers_panel.contains(layer))); + self.stale.extend(self.stale_in_layers_panel.extract_if(|layer| layers_panel.contains(layer))); self.in_view = layers; self.in_layers_panel = layers_panel; } @@ -91,7 +91,7 @@ impl Thumbnails { let changed = sources.iter().filter(|(layer, source)| self.sources.get(layer) != Some(source)); self.stale.extend(changed.map(|(layer, _)| *layer)); self.stale.retain(|layer| sources.contains_key(layer)); - self.unshown.retain(|layer| sources.contains_key(layer)); + self.stale_in_layers_panel.retain(|layer| sources.contains_key(layer)); self.sources = sources; } @@ -138,7 +138,7 @@ impl Thumbnails { if contents.is_empty() { return false; } - self.unshown.extend(contents.keys().filter(|layer| !self.in_layers_panel.contains(layer))); + self.stale_in_layers_panel.extend(contents.keys().filter(|layer| !self.in_layers_panel.contains(layer))); self.render_with_vello(&contents, editor_api, responses).await; true