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 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 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 always draws 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 internal image (and output). Clears every texture and forgets the previous frame (m_nFramesSinceResize = 0). Noise and user textures are kept.

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

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§

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,