fix: WebGL frame rendering and opencut-wasm 0.2.8

This commit is contained in:
Maze Winther
2026-04-19 07:42:52 +02:00
parent 9da365bc01
commit 729d10592f
14 changed files with 338 additions and 127 deletions
+53
View File
@@ -288,6 +288,59 @@ impl Compositor {
self.textures.remove(id);
}
/// Composites all frame items into a texture and returns it.
/// Used on backends that cannot surface-render to an arbitrary canvas (e.g. WebGL).
pub fn render_frame_to_texture(
&mut self,
context: &GpuContext,
frame: &FrameDescriptor,
) -> Result<wgpu::Texture, CompositorError> {
self.texture_pool.recycle_frame();
let mut encoder =
context
.device()
.create_command_encoder(&wgpu::CommandEncoderDescriptor {
label: Some("compositor-frame-encoder"),
});
let mut scene = self.create_cleared_texture(
context,
&mut encoder,
frame.width,
frame.height,
frame.clear.color,
);
for item in &frame.items {
match item {
FrameItemDescriptor::Layer(layer) => {
let layer_texture = self.render_layer(context, &mut encoder, frame, layer)?;
scene = self.blend_texture(
context,
&mut encoder,
&scene,
&layer_texture,
layer.blend_mode,
frame.width,
frame.height,
)?;
}
FrameItemDescriptor::SceneEffect { effect_pass_groups } => {
scene = self.apply_effect_groups(
context,
&mut encoder,
&scene,
frame.width,
frame.height,
effect_pass_groups,
)?;
}
}
}
context.queue().submit([encoder.finish()]);
Ok(scene)
}
pub fn render_frame(
&mut self,
context: &GpuContext,
@@ -11,6 +11,7 @@ struct LayerUniforms {
opacity: f32,
flip_x: f32,
flip_y: f32,
_padding: vec2f,
}
@group(0) @binding(0) var source_texture: texture_2d<f32>;