Skip to content
Open
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
21 changes: 16 additions & 5 deletions desktop/src/render/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::window::Window;

use crate::wrapper::{Color, WgpuContext, WgpuExecutor};
use wgpu_executor::TargetTexture;

#[derive(derivative::Derivative)]
#[derivative(Debug)]
Expand All @@ -18,6 +19,7 @@ pub(crate) struct RenderState {
viewport_offset: [f32; 2],
viewport_texture: Option<wgpu::Texture>,
overlays_texture: Option<wgpu::Texture>,
overlays_target_texture: Option<TargetTexture>,
ui_texture: Option<wgpu::Texture>,
bind_group: Option<wgpu::BindGroup>,
#[derivative(Debug = "ignore")]
Expand Down Expand Up @@ -182,6 +184,7 @@ impl RenderState {
viewport_offset: [0.0, 0.0],
viewport_texture: None,
overlays_texture: None,
overlays_target_texture: None,
ui_texture: None,
bind_group: None,
overlays_scene: None,
Expand Down Expand Up @@ -236,12 +239,20 @@ impl RenderState {
return;
};
let size = glam::UVec2::new(viewport_texture.width(), viewport_texture.height());
let texture = futures::executor::block_on(self.executor.render_vello_scene_to_texture(&scene, size, &Default::default(), Color::TRANSPARENT));
let Ok(texture) = texture else {
tracing::error!("Error rendering overlays");
let result = futures::executor::block_on(
self.executor.render_vello_scene_to_target_texture(&scene, size, &Default::default(), Color::TRANSPARENT, &mut self.overlays_target_texture)
);
if let Err(e) = result {
tracing::error!("Error rendering overlays: {:?}", e);
return;
};
self.bind_overlays_texture(texture);
}
// Extract the texture from the cached TargetTexture
if let Some(target_texture) = &self.overlays_target_texture {
// Create a new texture reference - the actual GPU texture is reused
let texture_view = target_texture.texture.create_view(&wgpu::TextureViewDescriptor::default());
self.overlays_texture = Some(target_texture.texture.clone());
self.update_bindgroup();
}
}

pub(crate) fn render(&mut self, window: &Window) -> Result<(), RenderError> {
Expand Down
8 changes: 4 additions & 4 deletions node-graph/libraries/wgpu-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ pub struct Surface {
}

pub struct TargetTexture {
texture: wgpu::Texture,
view: wgpu::TextureView,
size: UVec2,
pub texture: wgpu::Texture,
pub view: wgpu::TextureView,
pub size: UVec2,
}

#[cfg(target_family = "wasm")]
Expand All @@ -72,7 +72,7 @@ impl WgpuExecutor {
Ok(output.unwrap().texture)
}

async fn render_vello_scene_to_target_texture(&self, scene: &Scene, size: UVec2, context: &RenderContext, background: Color, output: &mut Option<TargetTexture>) -> Result<()> {
pub async fn render_vello_scene_to_target_texture(&self, scene: &Scene, size: UVec2, context: &RenderContext, background: Color, output: &mut Option<TargetTexture>) -> Result<()> {
let size = size.max(UVec2::ONE);
let target_texture = if let Some(target_texture) = output
&& target_texture.size == size
Expand Down