Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions editor/src/node_graph_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl NodeGraphExecutor {
},
time,
#[cfg(any(feature = "resvg", feature = "vello"))]
export_format: graphene_std::application_io::ExportFormat::Canvas,
export_format: graphene_std::application_io::ExportFormat::Raster,
#[cfg(not(any(feature = "resvg", feature = "vello")))]
export_format: graphene_std::application_io::ExportFormat::Svg,
render_mode: document.render_mode,
Expand Down Expand Up @@ -190,10 +190,10 @@ impl NodeGraphExecutor {
let size = bounds[1] - bounds[0];
let transform = DAffine2::from_translation(bounds[0]).inverse();

let export_format = if export_config.file_type == FileType::Svg || cfg!(not(feature = "gpu")) {
let export_format = if export_config.file_type == FileType::Svg {
graphene_std::application_io::ExportFormat::Svg
} else {
graphene_std::application_io::ExportFormat::Texture
graphene_std::application_io::ExportFormat::Raster
};

let render_config = RenderConfig {
Expand Down
16 changes: 14 additions & 2 deletions editor/src/node_graph_executor/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use graph_craft::graphene_compiler::Compiler;
use graph_craft::proto::GraphErrors;
use graph_craft::wasm_application_io::EditorPreferences;
use graph_craft::{ProtoNodeIdentifier, concrete};
use graphene_std::application_io::{ApplicationIo, ImageTexture, NodeGraphUpdateMessage, NodeGraphUpdateSender, RenderConfig};
use graphene_std::application_io::{ApplicationIo, ExportFormat, ImageTexture, NodeGraphUpdateMessage, NodeGraphUpdateSender, RenderConfig};
use graphene_std::bounds::RenderBoundingBox;
use graphene_std::memo::IORecord;
use graphene_std::ops::Convert;
Expand Down Expand Up @@ -212,7 +212,19 @@ impl NodeRuntime {

self.sender.send_generation_response(CompilationResponse { result, node_graph_errors });
}
GraphRuntimeRequest::ExecutionRequest(ExecutionRequest { execution_id, render_config, .. }) => {
GraphRuntimeRequest::ExecutionRequest(ExecutionRequest { execution_id, mut render_config, .. }) => {
// There are cases where we want to export via the svg pipeline eventhough raster was requested.
if matches!(render_config.export_format, ExportFormat::Raster) {
let vello_available = self.editor_api.application_io.as_ref().unwrap().gpu_executor().is_some();
let use_vello = vello_available && self.editor_api.editor_preferences.use_vello();

// On web when the user has disabled vello rendering in the preferences or we are exporting.
// And on all platforms when vello is not supposed to be used.
if !use_vello || cfg!(target_family = "wasm") && render_config.for_export {
render_config.export_format = ExportFormat::Svg;
}
}

let result = self.execute_network(render_config).await;
let mut responses = VecDeque::new();
// TODO: Only process monitor nodes if the graph has changed, not when only the Footprint changes
Expand Down
3 changes: 1 addition & 2 deletions node-graph/gapplication-io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ pub trait GetEditorPreferences {
pub enum ExportFormat {
#[default]
Svg,
Canvas,
Texture,
Raster,
}

#[derive(Debug, Default, Clone, Copy, PartialEq, DynAny, serde::Serialize, serde::Deserialize)]
Expand Down
57 changes: 20 additions & 37 deletions node-graph/gstd/src/render_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ async fn render_intermediate<'a: 'n, T: 'static + Render + WasmNotSend + Send +
Context -> Table<GradientStops>,
)]
data: impl Node<Context<'static>, Output = T>,
editor_api: impl Node<Context<'static>, Output = &'a WasmEditorApi>,
) -> RenderIntermediate {
let render_params = ctx
.vararg(0)
Expand All @@ -58,39 +57,29 @@ async fn render_intermediate<'a: 'n, T: 'static + Render + WasmNotSend + Send +
data.collect_metadata(&mut metadata, footprint, None);
let contains_artboard = data.contains_artboard();

let use_vello = {
#[cfg(target_family = "wasm")]
{
let editor_api = editor_api.eval(None).await;
!render_params.for_export && editor_api.editor_preferences.use_vello() && matches!(render_params.render_output_type, graphene_svg_renderer::RenderOutputType::Vello)
}
#[cfg(not(target_family = "wasm"))]
{
let _ = editor_api;
matches!(render_params.render_output_type, graphene_svg_renderer::RenderOutputType::Vello)
}
};

if use_vello {
let mut scene = vello::Scene::new();
match &render_params.render_output_type {
RenderOutputTypeRequest::Vello => {
let mut scene = vello::Scene::new();

let mut context = wgpu_executor::RenderContext::default();
data.render_to_vello(&mut scene, Default::default(), &mut context, render_params);
let mut context = wgpu_executor::RenderContext::default();
data.render_to_vello(&mut scene, Default::default(), &mut context, render_params);

RenderIntermediate {
ty: RenderIntermediateType::Vello(Arc::new((scene, context))),
metadata,
contains_artboard,
RenderIntermediate {
ty: RenderIntermediateType::Vello(Arc::new((scene, context))),
metadata,
contains_artboard,
}
}
} else {
let mut render = SvgRender::new();
RenderOutputTypeRequest::Svg => {
let mut render = SvgRender::new();

data.render_svg(&mut render, render_params);
data.render_svg(&mut render, render_params);

RenderIntermediate {
ty: RenderIntermediateType::Svg(Arc::new((render.svg.to_svg_string(), render.image_data, render.svg_defs.clone()))),
metadata,
contains_artboard,
RenderIntermediate {
ty: RenderIntermediateType::Svg(Arc::new((render.svg.to_svg_string(), render.image_data, render.svg_defs.clone()))),
metadata,
contains_artboard,
}
}
}
}
Expand All @@ -105,8 +94,7 @@ async fn create_context<'a: 'n>(

let render_output_type = match render_config.export_format {
ExportFormat::Svg => RenderOutputTypeRequest::Svg,
ExportFormat::Texture => RenderOutputTypeRequest::Vello,
ExportFormat::Canvas => RenderOutputTypeRequest::Vello,
ExportFormat::Raster => RenderOutputTypeRequest::Vello,
};

let render_params = RenderParams {
Expand Down Expand Up @@ -154,12 +142,7 @@ async fn render<'a: 'n>(
None
};

let mut output_format = render_params.render_output_type;
// TODO: Actually request the right thing upfront
if let RenderIntermediateType::Svg(_) = ty {
output_format = RenderOutputTypeRequest::Svg;
}
let data = match (output_format, &ty) {
let data = match (render_params.render_output_type, &ty) {
(RenderOutputTypeRequest::Svg, RenderIntermediateType::Svg(svg_data)) => {
let mut svg_renderer = SvgRender::new();
if !contains_artboard && !render_params.hide_artboards {
Expand Down
5 changes: 1 addition & 4 deletions node-graph/interpreted-executor/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ pub fn wrap_network_in_scope(mut network: NodeNetwork, editor_api: Arc<WasmEdito
},
DocumentNode {
call_argument: concrete!(Context),
inputs: vec![
NodeInput::import(graphene_core::Type::Fn(Box::new(concrete!(Context)), Box::new(generic!(T))), 0),
NodeInput::scope("editor-api"),
],
inputs: vec![NodeInput::import(graphene_core::Type::Fn(Box::new(concrete!(Context)), Box::new(generic!(T))), 0)],
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::render_node::render_intermediate::IDENTIFIER),
context_features: graphene_std::ContextDependencies {
extract: ContextFeatures::VARARGS,
Expand Down