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 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 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 always draws 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 internal image (and output). Clears every texture and forgets the previous
frame (m_nFramesSinceResize = 0). Noise and user textures are kept.
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 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 a cfg.width x cfg.height texture of cfg.output_format.
Fails with RenderError::Invalid (recording nothing) if input.warp_uv does not match the mesh or
input.md2_blend is set without Compat::MilkDrop2.
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.