pub struct Engine {
pub renderer: Renderer,
pub scene_manager: SceneManager,
pub assets: AssetServer,
pub input: Input,
/* private fields */
}Expand description
The core engine instance that orchestrates all rendering subsystems.
Engine is a pure engine implementation without window management,
making it suitable for integration with various windowing systems and platforms.
§Components
renderer: The rendering subsystem handling GPU operationsscene_manager: Manages multiple scenes and active scene selectionassets: Central asset storage for geometries, materials, textures, etc.input: Unified input state (keyboard, mouse, touch)
§Lifecycle
- Create with
Engine::neworEngine::default - Initialize GPU with
Engine::init - Update each frame with
Engine::update - Render using
Renderer::begin_frame
Fields§
§renderer: Renderer§scene_manager: SceneManager§assets: AssetServer§input: InputImplementations§
Source§impl Engine
impl Engine
Sourcepub fn new(
init_config: RendererInitConfig,
settings: RendererSettings,
) -> Engine
pub fn new( init_config: RendererInitConfig, settings: RendererSettings, ) -> Engine
Sourcepub async fn init<W>(
&mut self,
window: W,
width: u32,
height: u32,
) -> Result<(), Error>
pub async fn init<W>( &mut self, window: W, width: u32, height: u32, ) -> Result<(), Error>
Initializes GPU resources with the given window.
This method must be called before any rendering can occur. It accepts any type that implements the raw window handle traits, making it compatible with various windowing libraries.
§Arguments
window- A window that provides display and window handleswidth- Initial surface width in pixelsheight- Initial surface height in pixels
§Errors
Returns an error if GPU initialization fails due to:
- No compatible GPU adapter found
- Device request failed (unsupported features/limits)
- Surface configuration failed
Sourcepub async fn init_headless(
&mut self,
width: u32,
height: u32,
format: Option<PixelFormat>,
) -> Result<(), Error>
pub async fn init_headless( &mut self, width: u32, height: u32, format: Option<PixelFormat>, ) -> Result<(), Error>
Initializes the GPU context in headless (offscreen) mode.
No window or surface is created. An offscreen render target of the specified dimensions is allocated instead, suitable for server-side rendering, automated testing, and GPU readback.
§Arguments
width— Render target width in pixels.height— Render target height in pixels.format— Desired pixel format. PassNonefor the defaultRgba8Unorm(sRGB). UseSome(Rgba16Float)for HDR readback.
§Errors
Returns an error if GPU initialization fails.
Sourcepub fn readback_pixels(&mut self) -> Result<Vec<u8>, Error>
pub fn readback_pixels(&mut self) -> Result<Vec<u8>, Error>
Reads back the current headless render target as raw pixel data.
The returned Vec<u8> contains tightly-packed pixel data whose byte
count per pixel matches the headless texture format. A staging buffer
is cached internally to avoid per-frame allocation.
§Errors
Returns an error if the renderer is not initialised or not in headless mode.
Sourcepub fn submit_to_stream(&self, stream: &mut ReadbackStream) -> Result<(), Error>
pub fn submit_to_stream(&self, stream: &mut ReadbackStream) -> Result<(), Error>
Submits the current headless frame to a ReadbackStream (non-blocking).
Returns [ReadbackError::RingFull] if all ring-buffer slots are
in-flight. The caller may skip the frame or drain with
ReadbackStream::try_recv first.
Sourcepub fn submit_to_stream_blocking(
&self,
stream: &mut ReadbackStream,
) -> Result<(), Error>
pub fn submit_to_stream_blocking( &self, stream: &mut ReadbackStream, ) -> Result<(), Error>
Submits the current headless frame to a ReadbackStream, blocking
when the ring buffer is full.
Completed frames are stashed internally and can be retrieved via
ReadbackStream::try_recv or ReadbackStream::try_recv_into.
max_stash_size caps the number of unconsumed stashed frames to
prevent unbounded memory growth.
Sourcepub fn flush_stream(
&self,
stream: &mut ReadbackStream,
) -> Result<Vec<ReadbackFrame>, Error>
pub fn flush_stream( &self, stream: &mut ReadbackStream, ) -> Result<Vec<ReadbackFrame>, Error>
Flushes a ReadbackStream, blocking until all in-flight frames are returned.
Sourcepub fn poll_device(&self)
pub fn poll_device(&self)
Drives pending GPU callbacks without blocking.
Call this once per frame in a readback-stream loop so that
map_async callbacks fire and frames become available.
pub fn frame_time(&self) -> FrameTime
Sourcepub fn frame_count(&self) -> u64
pub fn frame_count(&self) -> u64
Returns the total number of frames rendered since startup.
Sourcepub fn size(&self) -> (u32, u32)
pub fn size(&self) -> (u32, u32)
Returns the current surface/window size in pixels as (width, height).
Sourcepub fn resize(&mut self, width: u32, height: u32)
pub fn resize(&mut self, width: u32, height: u32)
Handles window resize events.
This method should be called whenever the window size changes. It updates the renderer’s surface configuration and camera aspect ratios.
§Arguments
width- New width in pixelsheight- New height in pixels
Sourcepub fn update(&mut self, dt: f32)
pub fn update(&mut self, dt: f32)
Updates the engine state for the current frame.
This method should be called once per frame before rendering. It:
- Processes completed background asset loads
- Updates the total elapsed time and frame counter
- Runs scene logic and animations
- Resets per-frame input state
§Arguments
dt- Delta time since the last frame in seconds
Sourcepub fn maybe_prune(&mut self)
pub fn maybe_prune(&mut self)
Performs periodic resource cleanup.
This method should be called after each frame to release unused GPU resources and prevent memory leaks. It uses internal heuristics to avoid expensive cleanup operations on every frame.
Sourcepub fn render_active_scene(&mut self) -> bool
pub fn render_active_scene(&mut self) -> bool
Renders the active scene using the active camera.
This is a convenience method that combines scene lookup, camera extraction, and frame rendering into a single call. It avoids the split-borrow issues that arise when accessing the renderer and scene manager separately.
Returns true if a frame was successfully rendered, false if rendering
was skipped (no active scene, no active camera, etc.).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Engine
impl !RefUnwindSafe for Engine
impl !Send for Engine
impl !Sync for Engine
impl Unpin for Engine
impl UnsafeUnpin for Engine
impl !UnwindSafe for Engine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().