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§
const FRAMES_IN_FLIGHT_COUNT: usize = 3usize
const INITIAL_WINDOW_SIZE: (i32, i32) = _
const FRAMES_PER_SECOND: u32 = 120u32
Required Methods§
Provided Methods§
sourcefn handle_event(
&mut self,
window: &mut Window,
gfx: &mut Graphics<Self::Args>,
event: WindowEvent,
) -> Result<()>
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().
sourcefn update(
&mut self,
window: &mut Window,
gfx: &mut Graphics<Self::Args>,
) -> Result<()>
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.
sourcefn draw(
&mut self,
window: &mut Window,
gfx: &mut Graphics<Self::Args>,
frame: &Frame,
) -> Result<()>
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.
sourcefn rebuild_swapchain_resources(
&mut self,
window: &mut Window,
gfx: &mut Graphics<Self::Args>,
) -> Result<()>
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.