Skip to content

Commit 76ecdc8

Browse files
authored
Fix the 'Upload Texture' node (#2680)
* Fix upload texture node * Feature gate gpu node implemenations
1 parent 4d2e1d5 commit 76ecdc8

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1781,7 +1781,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
17811781
nodes: [
17821782
DocumentNode {
17831783
inputs: vec![NodeInput::scope("editor-api")],
1784-
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IntoNode")),
1784+
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IntoNode<&WgpuExecutor>")),
17851785
..Default::default()
17861786
},
17871787
DocumentNode {

node-graph/gcore/src/graphic_element/renderer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ impl GraphicElementRendered for RasterFrame {
925925
fn render_svg(&self, render: &mut SvgRender, render_params: &RenderParams) {
926926
match self {
927927
RasterFrame::ImageFrame(image) => image.render_svg(render, render_params),
928-
RasterFrame::TextureFrame(_) => unimplemented!(),
928+
RasterFrame::TextureFrame(_) => log::warn!("tried to render texture as an svg"),
929929
}
930930
}
931931

node-graph/interpreted-executor/src/node_registry.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,19 @@ use graphene_core::{fn_type_fut, future};
1313
use graphene_std::Context;
1414
use graphene_std::GraphicElement;
1515
use graphene_std::any::{ComposeTypeErased, DowncastBothNode, DynAnyNode, IntoTypeErasedNode};
16-
use graphene_std::application_io::ImageTexture;
16+
use graphene_std::application_io::{ImageTexture, TextureFrameTable};
1717
use graphene_std::wasm_application_io::*;
1818
use node_registry_macros::{async_node, into_node};
1919
use once_cell::sync::Lazy;
2020
use std::collections::HashMap;
2121
use std::sync::Arc;
2222
#[cfg(feature = "gpu")]
2323
use wgpu_executor::ShaderInputFrame;
24-
use wgpu_executor::{WgpuSurface, WindowHandle};
24+
use wgpu_executor::{WgpuExecutor, WgpuSurface, WindowHandle};
2525

2626
// TODO: turn into hashmap
2727
fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeConstructor>> {
2828
let node_types: Vec<(ProtoNodeIdentifier, NodeConstructor, NodeIOTypes)> = vec![
29-
into_node!(from: f64, to: f64),
3029
into_node!(from: f64, to: f64),
3130
into_node!(from: u32, to: f64),
3231
into_node!(from: u8, to: u32),
@@ -113,6 +112,12 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
113112
#[cfg(feature = "gpu")]
114113
async_node!(graphene_core::memo::ImpureMemoNode<_, _, _>, input: Context, fn_params: [Context => ShaderInputFrame]),
115114
#[cfg(feature = "gpu")]
115+
async_node!(graphene_core::memo::ImpureMemoNode<_, _, _>, input: Context, fn_params: [Context => TextureFrameTable]),
116+
#[cfg(feature = "gpu")]
117+
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => TextureFrameTable]),
118+
#[cfg(feature = "gpu")]
119+
into_node!(from: &WasmEditorApi, to: &WgpuExecutor),
120+
#[cfg(feature = "gpu")]
116121
(
117122
ProtoNodeIdentifier::new(stringify!(wgpu_executor::CreateGpuSurfaceNode<_>)),
118123
|args| {

node-graph/wgpu-executor/src/lib.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub use executor::GpuExecutor;
88
use futures::Future;
99
use glam::{DAffine2, UVec2};
1010
use gpu_executor::{ComputePassDimensions, GPUConstant, StorageBufferOptions, TextureBufferOptions, TextureBufferType, ToStorageBuffer, ToUniformBuffer};
11-
use graphene_core::application_io::{ApplicationIo, EditorApi, ImageTexture, SurfaceHandle};
11+
use graphene_core::application_io::{ApplicationIo, EditorApi, ImageTexture, SurfaceHandle, TextureFrameTable};
1212
use graphene_core::raster::image::ImageFrameTable;
1313
use graphene_core::raster::{Image, SRGBA8};
1414
use graphene_core::transform::{Footprint, Transform};
@@ -910,14 +910,14 @@ async fn render_texture<'a: 'n>(
910910
}
911911

912912
#[node_macro::node(category(""))]
913-
async fn upload_texture<'a: 'n>(_: impl ExtractFootprint + Ctx, input: ImageFrameTable<Color>, executor: &'a WgpuExecutor) -> ImageTexture {
913+
async fn upload_texture<'a: 'n>(_: impl ExtractFootprint + Ctx, input: ImageFrameTable<Color>, executor: &'a WgpuExecutor) -> TextureFrameTable {
914914
// let new_data: Vec<RGBA16F> = input.image.data.into_iter().map(|c| c.into()).collect();
915915

916-
let input = input.one_instance_ref().instance;
917-
let new_data: Vec<SRGBA8> = input.data.iter().map(|x| (*x).into()).collect();
916+
let image = input.one_instance_ref().instance;
917+
let new_data: Vec<SRGBA8> = image.data.iter().map(|x| (*x).into()).collect();
918918
let new_image = Image {
919-
width: input.width,
920-
height: input.height,
919+
width: image.width,
920+
height: image.height,
921921
data: new_data,
922922
base64_string: None,
923923
};
@@ -929,10 +929,18 @@ async fn upload_texture<'a: 'n>(_: impl ExtractFootprint + Ctx, input: ImageFram
929929
_ => unreachable!("Unsupported ShaderInput type"),
930930
};
931931

932-
ImageTexture {
932+
let texture = ImageTexture {
933933
texture: texture.into(),
934934
// TODO: Find an alternate way to encode the transform and alpha_blend now that these fields have been moved up out of ImageTexture
935935
// transform: input.transform,
936936
// alpha_blend: Default::default(),
937-
}
937+
};
938+
let mut result_table = TextureFrameTable::empty();
939+
result_table.push(graphene_core::instances::Instance {
940+
instance: texture,
941+
transform: input.transform(),
942+
alpha_blending: *input.one_instance_ref().alpha_blending,
943+
source_node_id: *input.one_instance_ref().source_node_id,
944+
});
945+
result_table
938946
}

0 commit comments

Comments
 (0)