pub struct Renderer { /* private fields */ }Expand description
The MilkDrop 2 frame renderer. See the crate docs for the pass order.
Implementations§
Source§impl Renderer
impl Renderer
Sourcepub fn burn_texture(
&mut self,
rgba8: &[u8],
w: u32,
h: u32,
rect: [i32; 4],
) -> Result<(), RenderError>
pub fn burn_texture( &mut self, rgba8: &[u8], w: u32, h: u32, rect: [i32; 4], ) -> Result<(), RenderError>
ProjectM::BurnInTexture: draws rgba8 (w x h, row 0 = top, straight alpha ignored) as one quad over the
image the next frame’s warp reads, opaque and without blending. rect = [left, top, width, height] in
target pixels, with projectM’s placement arithmetic (see [quad]); a rectangle of zero size draws nothing.
Unlike projectM’s OpenGL texture id the pixels are copied in, so the caller keeps its buffer.
Source§impl Renderer
impl Renderer
Sourcepub fn new(
device: &Device,
queue: &Queue,
cfg: RenderConfig,
) -> Result<Self, RenderError>
pub fn new( device: &Device, queue: &Queue, cfg: RenderConfig, ) -> Result<Self, RenderError>
Create a renderer. Textures are cleared to black; noise textures are generated from
cfg.seed (MD2 algorithm). device/queue are cloned handles (cheap).
§Errors
RenderError::Invalid if the size is zero or the mesh is not an even grid of at least 2x2 cells.
Sourcepub fn sibling(&self) -> Self
pub fn sibling(&self) -> Self
A second renderer with the same configuration that shares this one’s pipelines and
(immutable) noise textures but has its own images, shaders and user textures: what the
engine needs to run two presets at once while they transition. Cheaper than
Renderer::new (no pipeline compilation, no noise generation), but it still allocates the render targets.
Sourcepub fn sibling_with_compat(&self, compat: Compat) -> Self
pub fn sibling_with_compat(&self, compat: Compat) -> Self
Renderer::sibling that follows another compatibility mode: same size, mesh, stroke setting, shared
pipelines and noise (neither depends on the mode), but its own images, shaders and textures, and the rules of
compat. What the engine builds into when an automatically selected mode changes.
Sourcepub fn config(&self) -> &RenderConfig
pub fn config(&self) -> &RenderConfig
The configuration in use (size and mesh follow Renderer::resize / Renderer::set_mesh_size).
Sourcepub fn mesh_geometry(&self) -> &MeshGeometry
pub fn mesh_geometry(&self) -> &MeshGeometry
The warp-mesh geometry (vertex positions, rad, ang) — what the engine needs to run per-pixel code.
Sourcepub fn compat(&self) -> Compat
pub fn compat(&self) -> Compat
The reference behaviour followed where MilkDrop 2 and projectM differ.
Sourcepub fn stroke_raster(&self) -> StrokeRaster
pub fn stroke_raster(&self) -> StrokeRaster
The rasteriser actually used for lines and points: the configured one, except that
Compat::MilkDrop2 / Compat::MilkDrop3 always draw D3D9-style thin quads.
Sourcepub fn set_stroke_raster(&mut self, s: StrokeRaster)
pub fn set_stroke_raster(&mut self, s: StrokeRaster)
Switch the line / point rasteriser (see StrokeRaster); takes effect on the next frame.
Sourcepub fn resize(&mut self, width: u32, height: u32) -> Result<(), RenderError>
pub fn resize(&mut self, width: u32, height: u32) -> Result<(), RenderError>
Resize the output to width x height and the internal image to that times the render scale
(Renderer::set_render_scale). Clears every texture and forgets the previous frame
(m_nFramesSinceResize = 0), except that with Renderer::set_keep_feedback_on_resize the previous main
image is resampled into the new size. Noise and user textures are kept; an active flash limit
(Renderer::set_flash_limit) fades in from black again.
Sourcepub fn set_render_scale(&mut self, scale: f32) -> Result<(), RenderError>
pub fn set_render_scale(&mut self, scale: f32) -> Result<(), RenderError>
Render the feedback chain (main, warped, blur and final images) at scale times the output size and
upsample the composite to the host target when blitting (bilinear). 1.0 (the default) renders at the output
size and blits as before. scale is clamped to 0.25..=2.0; NaN is an error. Changing the scale reallocates
every image like Renderer::resize; Renderer::config reports the internal size from then on
(Renderer::output_size stays the target’s).
Fails with RenderError::Invalid (changing nothing) for NaN or when the internal size exceeds the device’s
texture limit.
Sourcepub fn render_scale(&self) -> f32
pub fn render_scale(&self) -> f32
The render scale in effect (Renderer::set_render_scale).
Sourcepub fn output_size(&self) -> (u32, u32)
pub fn output_size(&self) -> (u32, u32)
Size of the host target render_frame blits to. Equals config().width x config().height at render scale 1.
Sourcepub fn set_keep_feedback_on_resize(&mut self, keep: bool)
pub fn set_keep_feedback_on_resize(&mut self, keep: bool)
Keep the feedback image across Renderer::resize / Renderer::set_render_scale: the previous main
image is resampled (bilinear) into the new size instead of starting from black, so the picture does not
restart when a window is dragged. Off by default (MilkDrop 2 and projectM clear everything).
Sourcepub fn keep_feedback_on_resize(&self) -> bool
pub fn keep_feedback_on_resize(&self) -> bool
Whether the feedback image survives a resize (Renderer::set_keep_feedback_on_resize).
Sourcepub fn set_capture_warped(&mut self, capture: bool)
pub fn set_capture_warped(&mut self, capture: bool)
Keep a copy of the image right after the warp pass so Stage::Warped can be read back. Off by default
(the copy costs a full-image GPU copy every frame) and on with the diagnostics feature. While off,
read_stage(Stage::Warped) fails with RenderError::Invalid; the other stages are unaffected. Takes effect
on the next frame.
Sourcepub fn capture_warped(&self) -> bool
pub fn capture_warped(&self) -> bool
Whether the warped stage is captured (Renderer::set_capture_warped).
Sourcepub fn set_flash_limit(&mut self, limit: Option<f32>) -> Result<(), RenderError>
pub fn set_flash_limit(&mut self, limit: Option<f32>) -> Result<(), RenderError>
Limit how fast every colour channel of every pixel of the picture render_frame blits can change
(photosensitivity): Some(max_change_per_second) in units of the full 0..1 range, None (the default) off.
The rate uses FrameInput::time differences, so it does not depend on the frame rate: a channel flashing at
f Hz swings by at most limit / (2 f) (0.6 keeps flashes of 3 Hz or more within 10 % of the range);
slow changes pass unchanged. The picture fades in from black when the limit is switched on or the size changes.
This reduces the risk of a reaction; it is no guarantee.
Only render_frame’s blit is limited: not render_frame_to_output / Renderer::output_view (hosts that
blend presets limit their blend with a FlashLimiter) and not sprites drawn onto the target afterwards.
Off, the pass, its images and its pipeline do not exist. Changing the limit while on keeps the shown frame.
Fails with RenderError::Invalid for a limit that is not a positive finite number, or when the images
cannot be allocated.
Sourcepub fn flash_limit(&self) -> Option<f32>
pub fn flash_limit(&self) -> Option<f32>
The flash limit in effect (Renderer::set_flash_limit).
Sourcepub fn set_mesh_size(&mut self, mesh: [u32; 2]) -> Result<(), RenderError>
pub fn set_mesh_size(&mut self, mesh: [u32; 2]) -> Result<(), RenderError>
Change the warp-mesh resolution (cells per axis; the caller applies projectM’s clamping, see
lactea::Engine::set_mesh_size). The previous frame’s warp grid and the motion-vector state
belong to the old mesh and are forgotten; the images are kept.
Sourcepub fn set_texel_offset(&mut self, offset: [f32; 2])
pub fn set_texel_offset(&mut self, offset: [f32; 2])
Change the sub-texel offset added to warp UVs (projectm_set_texel_offset); takes effect on
the next frame.
Sourcepub fn reset_images(&mut self)
pub fn reset_images(&mut self)
Start a preset from a black frame (projectM start_clean): clears every image and
forgets the previous frame’s warp grid; drops all user textures (the next preset
registers its own). Noise textures are kept.
Sourcepub fn set_warp_shader(
&mut self,
shader: Option<CompiledShader>,
) -> Result<(), RenderError>
pub fn set_warp_shader( &mut self, shader: Option<CompiledShader>, ) -> Result<(), RenderError>
Install (or remove, None = MD2 WarpedBlit_NoShaders) the warp shader.
Sourcepub fn set_comp_shader(
&mut self,
shader: Option<CompiledShader>,
) -> Result<(), RenderError>
pub fn set_comp_shader( &mut self, shader: Option<CompiledShader>, ) -> Result<(), RenderError>
Install (or remove, None = MD2 ShowToUser_NoShaders) the composite shader.
Sourcepub fn take_shader_state(&mut self) -> ShaderState
pub fn take_shader_state(&mut self) -> ShaderState
Detach the installed warp / composite shaders and the user textures (MD2’s m_shaders), leaving the renderer
without any. The engine uses this to build the next preset’s shaders next to the running ones during a preset
blend (Renderer::set_old_shader_state) and to put the old ones back when that load fails.
Sourcepub fn restore_shader_state(&mut self, state: ShaderState)
pub fn restore_shader_state(&mut self, state: ShaderState)
Reinstall a state taken with Renderer::take_shader_state (replacing whatever is installed).
Sourcepub fn set_old_shader_state(&mut self, state: Option<ShaderState>)
pub fn set_old_shader_state(&mut self, state: Option<ShaderState>)
MD2’s m_OldShaders: keep state (the outgoing preset’s shaders and textures) alive for the old half of a
preset blend; None releases them (m_OldShaders.*.Clear() when the blend ends).
Sourcepub fn has_old_shaders(&self) -> bool
pub fn has_old_shaders(&self) -> bool
Whether old shaders are being kept for a preset blend.
Sourcepub fn shader_flags(&self) -> ((bool, bool), (bool, bool))
pub fn shader_flags(&self) -> ((bool, bool), (bool, bool))
(warp, composite): whether the installed shaders are user / default pixel shaders (m_nWarpPSVersion > 0
style flags of the new preset and of the old one, if one is kept).
Sourcepub fn set_user_texture(
&mut self,
name: &str,
w: u32,
h: u32,
rgba8: &[u8],
) -> Result<(), RenderError>
pub fn set_user_texture( &mut self, name: &str, w: u32, h: u32, rgba8: &[u8], ) -> Result<(), RenderError>
Register a user texture (sampler_<name>): RGBA8, row 0 = top, with a CPU mip chain.
name is matched case-insensitively against TexSource::User.
Sourcepub fn set_user_animation(
&mut self,
name: &str,
w: u32,
h: u32,
frames: &[&[u8]],
delays: &[f64],
) -> Result<(), RenderError>
pub fn set_user_animation( &mut self, name: &str, w: u32, h: u32, frames: &[&[u8]], delays: &[f64], ) -> Result<(), RenderError>
Register an animated user texture (an animated GIF as sampler_<name>, Compat::MilkDrop3): frames are
w * h * 4 RGBA8 images (row 0 = top), delays their durations in seconds. Every draw shows the frame
gif_frame_index picks for the time of the frame being rendered. No mip chain.
Sourcepub fn set_sprite_image(
&mut self,
id: u32,
w: u32,
h: u32,
frames: &[&[u8]],
mips: bool,
) -> Result<(), RenderError>
pub fn set_sprite_image( &mut self, id: u32, w: u32, h: u32, frames: &[&[u8]], mips: bool, ) -> Result<(), RenderError>
Register the image of an MD3 sprite under id (SpriteDraw::image), replacing
any image with that id. frames are w * h * 4 RGBA8 images (row 0 = top, straight alpha, colour key already
applied); a static image has one frame and mips (full chain, trilinear sampling), a GIF has no mips.
Sourcepub fn clear_sprite_images(&mut self)
pub fn clear_sprite_images(&mut self)
Forget every sprite image.
Sourcepub fn clear_user_textures(&mut self)
pub fn clear_user_textures(&mut self)
Forget every user texture (set_user_texture / set_user_animation); shaders sampling one see the
placeholder until it is registered again.
Sourcepub fn has_sprite_image(&self, id: u32) -> bool
pub fn has_sprite_image(&self, id: u32) -> bool
Whether an image is registered under id.
Sourcepub fn remove_sprite_image(&mut self, id: u32)
pub fn remove_sprite_image(&mut self, id: u32)
Forget the image registered under id, if any.
Sourcepub fn draw_sprites(
&self,
encoder: &mut CommandEncoder,
target: &TextureView,
draws: &[SpriteDraw],
)
pub fn draw_sprites( &self, encoder: &mut CommandEncoder, target: &TextureView, draws: &[SpriteDraw], )
Draw sprites (any layer value) onto target, an Rgba8Unorm view: the sprite pass on its own, for hosts
that composite themselves and for tests. Draws whose image or frame is not registered are skipped.
Sourcepub fn burn_sprites(&self, encoder: &mut CommandEncoder, draws: &[SpriteDraw])
pub fn burn_sprites(&self, encoder: &mut CommandEncoder, draws: &[SpriteDraw])
Draw draws into the image the next frame’s warp reads (projectM’s burn), the ones with burn set only:
call after Renderer::render_frame_to_output, when that image is the one just produced.
Sourcepub fn draw_sprites_to_output(
&self,
encoder: &mut CommandEncoder,
target: &TextureView,
draws: &[SpriteDraw],
)
pub fn draw_sprites_to_output( &self, encoder: &mut CommandEncoder, target: &TextureView, draws: &[SpriteDraw], )
Draw draws onto target, a view of the host’s output (RenderConfig::output_format), loaded not cleared:
sprites over a finished frame, e.g. over a soft cut’s blend.
Sourcepub fn read_stage(
&self,
stage: Stage,
) -> Result<(u32, u32, Vec<u8>), RenderError>
pub fn read_stage( &self, stage: Stage, ) -> Result<(u32, u32, Vec<u8>), RenderError>
Read a stage back as (width, height, RGBA8) (row 0 = top). The command buffers of the
frame must have been submitted. Stage::Main is the image the next frame’s warp samples;
Warped the image right after the warp pass; Blur1..3 the user-visible blur levels
(blur textures 1, 3, 5); Final the composite output.
Sourcepub fn blur_levels_required(&self) -> u8
pub fn blur_levels_required(&self) -> u8
Highest blur level (0..=3) the installed shaders require (including the old preset’s while a preset blend
keeps them: MD2’s ApplyShaderParams counts every pass it applies, also m_OldShaders).
Sourcepub fn render_frame(
&mut self,
encoder: &mut CommandEncoder,
input: &FrameInput,
target: &TextureView,
) -> Result<(), RenderError>
pub fn render_frame( &mut self, encoder: &mut CommandEncoder, input: &FrameInput, target: &TextureView, ) -> Result<(), RenderError>
Record one frame into encoder, ending with the composite blitted to target.
All per-frame GPU data is baked into buffers at record time, so frames may be recorded in
any order, but the encoder must be submitted before Renderer::read_stage is called.
target must be a view of an Renderer::output_size texture of cfg.output_format (the internal image is
upsampled to it when the render scale is not 1).
Fails with RenderError::Invalid (recording nothing) if input.warp_uv does not match the mesh or
input.md2_blend is set without Compat::MilkDrop2 / Compat::MilkDrop3 or its vert_alpha does not match
the mesh.
Sourcepub fn render_frame_to_output(
&mut self,
encoder: &mut CommandEncoder,
input: &FrameInput,
) -> Result<(), RenderError>
pub fn render_frame_to_output( &mut self, encoder: &mut CommandEncoder, input: &FrameInput, ) -> Result<(), RenderError>
Like Renderer::render_frame but stops after the composite: the finished image stays in
the renderer (Renderer::output_view) and nothing is written to a host target. Used for
presets that are blended into the frame by a transition.
Sourcepub fn output_view(&self) -> &TextureView
pub fn output_view(&self) -> &TextureView
The composited image of the last rendered frame (Rgba8Unorm, row 0 = top, the final
stage): projectM’s Preset::OutputTexture().
Sourcepub fn draw_initial_image(
&mut self,
encoder: &mut CommandEncoder,
src: &Renderer,
) -> Result<(), RenderError>
pub fn draw_initial_image( &mut self, encoder: &mut CommandEncoder, src: &Renderer, ) -> Result<(), RenderError>
Start this preset from src’s composited image instead of black (projectM
DrawInitialImage, used when start_clean is off): the image the first warp samples.
src must have the same size. Call after Renderer::reset_images.
Fails with RenderError::Invalid if the two renderers differ in size.