Skip to main content

Renderer

Struct Renderer 

Source
pub struct Renderer { /* private fields */ }
Expand description

The MilkDrop 2 frame renderer. See the crate docs for the pass order.

Implementations§

Source§

impl Renderer

Source

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

Source

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.

Source

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.

Source

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.

Source

pub fn config(&self) -> &RenderConfig

The configuration in use (size and mesh follow Renderer::resize / Renderer::set_mesh_size).

Source

pub fn mesh_geometry(&self) -> &MeshGeometry

The warp-mesh geometry (vertex positions, rad, ang) — what the engine needs to run per-pixel code.

Source

pub fn compat(&self) -> Compat

The reference behaviour followed where MilkDrop 2 and projectM differ.

Source

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.

Source

pub fn set_stroke_raster(&mut self, s: StrokeRaster)

Switch the line / point rasteriser (see StrokeRaster); takes effect on the next frame.

Source

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.

Source

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.

Source

pub fn render_scale(&self) -> f32

The render scale in effect (Renderer::set_render_scale).

Source

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.

Source

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).

Source

pub fn keep_feedback_on_resize(&self) -> bool

Whether the feedback image survives a resize (Renderer::set_keep_feedback_on_resize).

Source

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.

Source

pub fn capture_warped(&self) -> bool

Whether the warped stage is captured (Renderer::set_capture_warped).

Source

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.

Source

pub fn flash_limit(&self) -> Option<f32>

The flash limit in effect (Renderer::set_flash_limit).

Source

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.

Source

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.

Source

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.

Source

pub fn set_warp_shader( &mut self, shader: Option<CompiledShader>, ) -> Result<(), RenderError>

Install (or remove, None = MD2 WarpedBlit_NoShaders) the warp shader.

Source

pub fn set_comp_shader( &mut self, shader: Option<CompiledShader>, ) -> Result<(), RenderError>

Install (or remove, None = MD2 ShowToUser_NoShaders) the composite shader.

Source

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.

Source

pub fn restore_shader_state(&mut self, state: ShaderState)

Reinstall a state taken with Renderer::take_shader_state (replacing whatever is installed).

Source

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).

Source

pub fn has_old_shaders(&self) -> bool

Whether old shaders are being kept for a preset blend.

Source

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).

Source

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.

Source

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.

Source

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.

Source

pub fn clear_sprite_images(&mut self)

Forget every sprite image.

Source

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.

Source

pub fn has_sprite_image(&self, id: u32) -> bool

Whether an image is registered under id.

Source

pub fn remove_sprite_image(&mut self, id: u32)

Forget the image registered under id, if any.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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().

Source

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.

Auto Trait Implementations§

§

impl !Freeze for Renderer

§

impl !RefUnwindSafe for Renderer

§

impl !Sync for Renderer

§

impl !UnwindSafe for Renderer

§

impl Forget for Renderer

§

impl Move for Renderer

§

impl Send for Renderer
where DispatchDevice: Send, Arc<Mutex<RawMutex, HashSet<WeakMapContext>>>: Send, DispatchQueue: Send, RawVecInner: Send, DispatchBuffer: Send, Arc<Mutex<RawMutex, MapContext>>: Send, RefCell<[Option<BindGroup>; 3]>: Send, DispatchRenderPipeline: Send, DispatchBindGroupLayout: Send, DispatchTexture: Send, DispatchTextureView: Send, RefCell<Vec<Option<([[f32; 4]; 6], BindGroup)>>>: Send, Arc<Pipelines>: Send, RawTable<(String, UserTex)>: Send, RawTable<(u32, SpriteImage)>: Send, DispatchBindGroup: Send,

§

impl Unpin for Renderer

§

impl UnsafeUnpin for Renderer
where *const ArcInner<Device> is !null: UnsafeUnpin, PhantomData<ArcInner<Device>>: UnsafeUnpin, *const ArcInner<Mutex<RawMutex, HashSet<WeakMapContext>>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<RawMutex, HashSet<WeakMapContext>>>>: UnsafeUnpin, *const ArcInner<Queue> is !null: UnsafeUnpin, PhantomData<ArcInner<Queue>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<f32>: UnsafeUnpin, PhantomData<([f32; 2], f32, f32)>: UnsafeUnpin, *const ArcInner<Buffer> is !null: UnsafeUnpin, PhantomData<ArcInner<Buffer>>: UnsafeUnpin, *const ArcInner<Mutex<RawMutex, MapContext>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<RawMutex, MapContext>>>: UnsafeUnpin, *const ArcInner<BindGroup> is !null: UnsafeUnpin, PhantomData<ArcInner<BindGroup>>: UnsafeUnpin, *const ArcInner<RenderPipeline> is !null: UnsafeUnpin, PhantomData<ArcInner<RenderPipeline>>: UnsafeUnpin, *const ArcInner<BindGroupLayout> is !null: UnsafeUnpin, PhantomData<ArcInner<BindGroupLayout>>: UnsafeUnpin, *const ArcInner<Texture> is !null: UnsafeUnpin, PhantomData<ArcInner<Texture>>: UnsafeUnpin, *const ArcInner<TextureView> is !null: UnsafeUnpin, PhantomData<ArcInner<TextureView>>: UnsafeUnpin, PhantomData<Option<([[f32; 4]; 6], BindGroup)>>: UnsafeUnpin, *const ArcInner<Pipelines> is !null: UnsafeUnpin, PhantomData<ArcInner<Pipelines>>: UnsafeUnpin, PhantomData<Tex>: UnsafeUnpin, PhantomData<(String, UserTex)>: UnsafeUnpin, PhantomData<(u32, SpriteImage)>: UnsafeUnpin, PhantomData<TextureBinding>: UnsafeUnpin, PhantomData<TexSource>: UnsafeUnpin, PhantomData<[f32; 2]>: UnsafeUnpin, PhantomData<VertexVars>: UnsafeUnpin, PhantomData<[f32; 4]>: UnsafeUnpin, PhantomData<WfVertex>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WasmNotSend for T
where T: Send,