Trait demo_vk::demo::Demo

source ·
pub trait Demo {
    type Args: Sized + Parser;

    const FRAMES_IN_FLIGHT_COUNT: usize = 3usize;
    const INITIAL_WINDOW_SIZE: (i32, i32) = _;
    const FRAMES_PER_SECOND: u32 = 120u32;

    // Required method
    fn new(window: &mut Window, gfx: &mut Graphics<Self::Args>) -> Result<Self>
       where Self: Sized;

    // Provided methods
    fn handle_event(
        &mut self,
        window: &mut Window,
        gfx: &mut Graphics<Self::Args>,
        event: WindowEvent,
    ) -> Result<()> { ... }
    fn update(
        &mut self,
        window: &mut Window,
        gfx: &mut Graphics<Self::Args>,
    ) -> Result<()> { ... }
    fn draw(
        &mut self,
        window: &mut Window,
        gfx: &mut Graphics<Self::Args>,
        frame: &Frame,
    ) -> Result<()> { ... }
    fn rebuild_swapchain_resources(
        &mut self,
        window: &mut Window,
        gfx: &mut Graphics<Self::Args>,
    ) -> Result<()> { ... }
    fn paused(
        &mut self,
        window: &mut Window,
        gfx: &mut Graphics<Self::Args>,
    ) -> Result<()> { ... }
    fn unpaused(
        &mut self,
        window: &mut Window,
        gfx: &mut Graphics<Self::Args>,
    ) -> Result<()> { ... }
}
Expand description

A demo is an opinionated application that automatically creates the VulkanContext, Swapchain, FramesInFlight and other common utilities.

The demo splits the application’s update() function into two parts:

  • update(): update the application’s state
  • draw(): build the frame’s command buffer

Draw is separate because update() does not wait for the next swapchain image. There are some operations that may not depend on the swapchain and can reasonably be started before the frame’s command buffer is ready to be recorded. (ticking a physics simulation, etc…)

Required Associated Types§

Provided Associated Constants§

Required Methods§

source

fn new(window: &mut Window, gfx: &mut Graphics<Self::Args>) -> Result<Self>
where Self: Sized,

Creates a new instance of the demo. The application is allowed to modify the window based on its own requirements. This includes modifying the polling state, fullscreen status, size, etc…

Provided Methods§

source

fn handle_event( &mut self, window: &mut Window, gfx: &mut Graphics<Self::Args>, event: WindowEvent, ) -> Result<()>

Handles a single GLFW event.

This function is called in a loop to consume any pending events before every call to update().

source

fn update( &mut self, window: &mut Window, gfx: &mut Graphics<Self::Args>, ) -> Result<()>

Called in a loop after all pending events have been processed.

This is a good place for rendering logic. This method blocks event processing, so it should be kept as responsive as possible.

source

fn draw( &mut self, window: &mut Window, gfx: &mut Graphics<Self::Args>, frame: &Frame, ) -> Result<()>

Build the command buffer for the next frame.

Called after update() once the Frame is started.

source

fn rebuild_swapchain_resources( &mut self, window: &mut Window, gfx: &mut Graphics<Self::Args>, ) -> Result<()>

Rebuild any of the demo’s swapchain-dependent resources.

All pending frames in flight are guaranteed to have completed by the time this function is called. E.G. any previously-recorded Frame command buffers are guaranteed to be finished.

source

fn paused( &mut self, window: &mut Window, gfx: &mut Graphics<Self::Args>, ) -> Result<()>

Called when the application is paused.

The application is paused automatically any time the framebuffer has size of 0. This occurs when the application is minimized, etc..

source

fn unpaused( &mut self, window: &mut Window, gfx: &mut Graphics<Self::Args>, ) -> Result<()>

Called when the application is unpaused.

Object Safety§

This trait is not object safe.

Implementors§