pub struct GpuRenderer {
gl: Arc<Context>,
vao: VertexArray,
vert: Shader,
programs: Programs,
pool: Pool,
textures: HashMap<u64, LayerTex>,
blank: Texture,
loaned: Vec<Target>,
pub text: Option<Arc<Mutex<TextRasterizer>>>,
}Expand description
The renderer. One per app; lives on the UI thread.
Fields§
§gl: Arc<Context>§vao: VertexArray§vert: Shader§programs: Programs§pool: Pool§textures: HashMap<u64, LayerTex>Uploaded layer textures by caller key.
blank: Texture1×1 white texture, bound where a sampler is unused.
loaned: Vec<Target>Targets handed to the caller; recycled at the start of the next frame.
text: Option<Arc<Mutex<TextRasterizer>>>What NodeKind::Text rasterises with — the app hands over the same one the player and export
use, so fonts and the glyph cache are shared. None = Text nodes render nothing.
Implementations§
Source§impl GpuRenderer
impl GpuRenderer
Sourcepub fn new(gl: Arc<Context>) -> Result<Self, String>
pub fn new(gl: Arc<Context>) -> Result<Self, String>
Compile the shader set. Err (with the GLSL log) when the driver rejects something — the caller falls back to the CPU compositor and shows the message once.
Sourcepub fn upload(&mut self, key: u64, frame: &Frame) -> Texture
pub fn upload(&mut self, key: u64, frame: &Frame) -> Texture
Upload/refresh a decoded layer as a texture keyed by (clip id, source time bucket). Returns the
texture to use; re-uploads only when the frame actually changed (Frame pointer/pts).
Sourcepub fn render_to_texture(
&mut self,
project: &Project,
t: f64,
w: u32,
h: u32,
quality: f32,
layers: &LayerSet,
) -> Option<Texture>
pub fn render_to_texture( &mut self, project: &Project, t: f64, w: u32, h: u32, quality: f32, layers: &LayerSet, ) -> Option<Texture>
Render the whole timeline at time t into an off-screen target and return it, so the preview can
paint it with eframe::Frame::register_native_glow_texture. quality (0.25..1.0) scales the
internal resolution (see render_size); the texture is always presented at w×h.
Sourcepub fn render_frame(
&mut self,
project: &Project,
t: f64,
w: u32,
h: u32,
layers: &LayerSet,
out: &mut Frame,
)
pub fn render_frame( &mut self, project: &Project, t: f64, w: u32, h: u32, layers: &LayerSet, out: &mut Frame, )
Same, but read back into out (export / export-frame / MCP render.frame).
Sourcepub fn render_preview_texture(
&mut self,
project: &Project,
t: f64,
w: u32,
h: u32,
layers: &LayerSet,
) -> Option<(Texture, u32, u32)>
pub fn render_preview_texture( &mut self, project: &Project, t: f64, w: u32, h: u32, layers: &LayerSet, ) -> Option<(Texture, u32, u32)>
Apply one effect to a texture (used by the effect-thumbnail grid and the node editor previews).
Render the timeline into an off-screen texture the caller can paint directly (zero-copy preview).
The texture stays owned by the renderer and is valid until the next call; reclaim() recycles it
on the following frame, so the caller must paint it in the same frame it asked for it.
Sourcepub fn effect_preview(
&mut self,
src: &Frame,
effect: &Effect,
t: f64,
out: &mut Frame,
) -> bool
pub fn effect_preview( &mut self, src: &Frame, effect: &Effect, t: f64, out: &mut Frame, ) -> bool
Render effect over src and read the result back into out (catalogue thumbnails).
t is the clip-local time to sample animated parameters at. False when the effect has no GPU body.
pub fn apply_effect( &mut self, src: Texture, size: (u32, u32), effect: &Effect, t: f64, ) -> Option<Texture>
Sourcepub fn mask_texture(
&mut self,
mask: &Mask,
size: (u32, u32),
t: f64,
project_w: u32,
) -> Option<Texture>
pub fn mask_texture( &mut self, mask: &Mask, size: (u32, u32), t: f64, project_w: u32, ) -> Option<Texture>
Rasterise a mask into a single-channel texture (also used by the mask editor overlay).
Sourcepub fn eval_graph(
&mut self,
graph: &NodeGraph,
clip: &Clip,
t: f64,
fps: f64,
layers: &LayerSet,
) -> Option<Texture>
pub fn eval_graph( &mut self, graph: &NodeGraph, clip: &Clip, t: f64, fps: f64, layers: &LayerSet, ) -> Option<Texture>
Evaluate a node graph, returning the output texture.
Sourcepub fn invalidate(&mut self, key: Option<u64>)
pub fn invalidate(&mut self, key: Option<u64>)
Drop cached textures for a clip/asset (source replaced, project closed).
pub fn scaler_supported(&self, _s: Scaler) -> bool
Sourcepub fn last_error(&self) -> Option<&str>
pub fn last_error(&self) -> Option<&str>
The GLSL log of the last program that failed to compile, if any.
Sourcepub fn shader_error(&self, src: &str) -> Option<&str>
pub fn shader_error(&self, src: &str) -> Option<&str>
The GLSL log this user shader body was rejected with, if it ever was.
Sourcepub fn check_shader(&mut self, src: &str) -> Result<(), String>
pub fn check_shader(&mut self, src: &str) -> Result<(), String>
Compile + link a user shader body without rendering anything, so the editor can show the log before the effect is applied. The program lands in the cache the renderer reads.
Sourcefn host_fbo(&self) -> Option<Framebuffer>
fn host_fbo(&self) -> Option<Framebuffer>
The framebuffer eframe/egui had bound when it called us.
Sourcefn restore(&self, host: Option<Framebuffer>)
fn restore(&self, host: Option<Framebuffer>)
Put back the GL state egui assumes (its framebuffer, unit 0, no program bound).
fn acquire(&mut self, w: u32, h: u32) -> Option<Target>
fn clear(&self, t: &Target, c: [f32; 4])
Sourcefn ensure(&mut self, key: u64) -> Result<(), String>
fn ensure(&mut self, key: u64) -> Result<(), String>
Ensure a program is compiled and cached. Err carries the GLSL log.
fn link(&mut self, key: u64, src: &str) -> Result<(), String>
Sourcefn effect_program(&mut self, effect: &Effect) -> Option<u64>
fn effect_program(&mut self, effect: &Effect) -> Option<u64>
Compile (once) the program for an effect; None when the kind has no GPU body.
Sourcefn draw(
&self,
key: u64,
dst: &Target,
tex: Texture,
mask: Option<Texture>,
set: impl Fn(&Prog),
)
fn draw( &self, key: u64, dst: &Target, tex: Texture, mask: Option<Texture>, set: impl Fn(&Prog), )
Bind prog, point the fixed sampler units at tex/mask, size uniforms, and draw the triangle.
Sourcefn copy_to(&mut self, src: Texture, size: (u32, u32)) -> Option<Target>
fn copy_to(&mut self, src: Texture, size: (u32, u32)) -> Option<Target>
Copy src (stretched to the target) into a fresh target.
Sourcefn run_effect(
&mut self,
src: Texture,
size: (u32, u32),
effect: &Effect,
t: f64,
scale: f32,
mask: Option<Texture>,
motion: Option<(Texture, Texture, f32)>,
blob: Option<(f64, f64, f64)>,
) -> Option<Target>
fn run_effect( &mut self, src: Texture, size: (u32, u32), effect: &Effect, t: f64, scale: f32, mask: Option<Texture>, motion: Option<(Texture, Texture, f32)>, blob: Option<(f64, f64, f64)>, ) -> Option<Target>
One effect pass: src -> a new target of the same size. None when the effect has no GPU body.
motion is the (prev, next, count) sampler set a needs_motion kind wants; anything else
passes None.
Sourcefn track_blob(
&self,
effect: &Effect,
clip: u64,
t: f64,
layers: &LayerSet,
) -> Option<(f64, f64, f64)>
fn track_blob( &self, effect: &Effect, clip: u64, t: f64, layers: &LayerSet, ) -> Option<(f64, f64, f64)>
BlobTrack: find the target colour’s centroid on the clip’s decoded frame. The tracking runs on
the CPU copy the decoder already produced, so no readback is needed; the shader only draws it.
Sourcefn motion_texs(&mut self, id: u64, layers: &LayerSet) -> (Texture, Texture, f32)
fn motion_texs(&mut self, id: u64, layers: &LayerSet) -> (Texture, Texture, f32)
The neighbouring frames a needs_motion effect wants: (prev, next, how many are real).
LayerSet::motion carries whatever the decoder managed to produce — 0, 1 or 2 samples.
Sourcefn render_mask(
&mut self,
mask: &Mask,
size: (u32, u32),
t: f64,
scale: f32,
centre: (f32, f32),
) -> Option<Target>
fn render_mask( &mut self, mask: &Mask, size: (u32, u32), t: f64, scale: f32, centre: (f32, f32), ) -> Option<Target>
Rasterise mask at size; scale is canvas px per project px and centre the shape origin.
Sourcefn composite(
&mut self,
canvas: Target,
layer: Texture,
layer_size: (u32, u32),
inv: [[f32; 3]; 3],
mode: BlendMode,
opacity: f32,
scaler: Scaler,
mask: Option<Texture>,
) -> Target
fn composite( &mut self, canvas: Target, layer: Texture, layer_size: (u32, u32), inv: [[f32; 3]; 3], mode: BlendMode, opacity: f32, scaler: Scaler, mask: Option<Texture>, ) -> Target
Composite layer onto canvas through inv (canvas px -> layer uv). Consumes and returns the
canvas (ping-pong: you cannot sample the framebuffer you are drawing into).
Sourcefn render_canvas(
&mut self,
project: &Project,
t: f64,
w: u32,
h: u32,
layers: &LayerSet,
) -> Option<Target>
fn render_canvas( &mut self, project: &Project, t: f64, w: u32, h: u32, layers: &LayerSet, ) -> Option<Target>
The whole timeline at t into a fresh canvas target.
Sourcefn draw_transition(
&mut self,
project: &Project,
tr: &Transition,
left: Option<&Clip>,
right: Option<&Clip>,
p: f32,
t: f64,
canvas: Target,
layers: &LayerSet,
) -> Target
fn draw_transition( &mut self, project: &Project, tr: &Transition, left: Option<&Clip>, right: Option<&Clip>, p: f32, t: f64, canvas: Target, layers: &LayerSet, ) -> Target
Both sides of a transition, per kind (mirrors compose::render_transition). Edge transitions
have one side missing (In: no left, Out: no right): that side is nothing — the black canvas.
Sourcefn fill_canvas(&mut self, canvas: Target, color: [u8; 4], f: f32) -> Target
fn fill_canvas(&mut self, canvas: Target, color: [u8; 4], f: f32) -> Target
Mix the whole canvas towards color by f (FadeToColor).
Sourcefn draw_subtitles(
&mut self,
project: &Project,
sub: &Arc<Frame>,
canvas: Target,
) -> Target
fn draw_subtitles( &mut self, project: &Project, sub: &Arc<Frame>, canvas: Target, ) -> Target
The subtitle bitmap, bottom-centre (mirrors compose::render).
Sourcefn draw_clip(
&mut self,
project: &Project,
clip: &Clip,
t: f64,
canvas: Target,
layers: &LayerSet,
extra: Extra,
) -> Target
fn draw_clip( &mut self, project: &Project, clip: &Clip, t: f64, canvas: Target, layers: &LayerSet, extra: Extra, ) -> Target
One clip: layer -> chain -> composite. Returns the (possibly new) canvas.
Sourcefn run_chain(
&mut self,
clip: &Clip,
t: f64,
fps: f64,
layers: &LayerSet,
src: Texture,
size: (u32, u32),
scale: f32,
) -> Option<Target>
fn run_chain( &mut self, clip: &Clip, t: f64, fps: f64, layers: &LayerSet, src: Texture, size: (u32, u32), scale: f32, ) -> Option<Target>
The clip’s effect chain (node graph when it has one, else the linear stack). None = unchanged.
Sourcefn eval_graph_on(
&mut self,
graph: &NodeGraph,
clip: &Clip,
t: f64,
fps: f64,
layers: &LayerSet,
input: Option<Texture>,
size: (u32, u32),
scale: f32,
) -> Option<Target>
fn eval_graph_on( &mut self, graph: &NodeGraph, clip: &Clip, t: f64, fps: f64, layers: &LayerSet, input: Option<Texture>, size: (u32, u32), scale: f32, ) -> Option<Target>
Walk graph in evaluation order, one target per node. Missing inputs are transparent.
Sourcefn finish_graph(
&mut self,
done: Vec<(u64, Target)>,
out_id: u64,
) -> Option<Target>
fn finish_graph( &mut self, done: Vec<(u64, Target)>, out_id: u64, ) -> Option<Target>
Keep the output node’s target, recycle the rest.
fn transparent(&mut self, size: (u32, u32)) -> Option<Target>
Sourcefn text_node(
&mut self,
id: u64,
style: &TextStyle,
t: f64,
lt: f64,
fps: f64,
scale: f32,
size: (u32, u32),
) -> Option<Target>
fn text_node( &mut self, id: u64, style: &TextStyle, t: f64, lt: f64, fps: f64, scale: f32, size: (u32, u32), ) -> Option<Target>
A Text node: expand the format, rasterise it (shared TextRasterizer) and centre it on an
otherwise transparent canvas. A counter re-rasterises every frame — that is what it is for.
fn matte( &mut self, a: Texture, b: Texture, size: (u32, u32), invert: bool, use_alpha: bool, ) -> Option<Target>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GpuRenderer
impl RefUnwindSafe for GpuRenderer
impl Send for GpuRenderer
impl Sync for GpuRenderer
impl Unpin for GpuRenderer
impl UnwindSafe for GpuRenderer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more