Trait RenderSystem

Source
pub trait RenderSystem:
    Debug
    + Send
    + Sync {
    // Required methods
    fn init(
        &mut self,
        window: &dyn KhoraWindow,
    ) -> Result<Vec<Arc<dyn ResourceMonitor>>, RenderError>;
    fn resize(&mut self, new_width: u32, new_height: u32);
    fn prepare_frame(&mut self, view_info: &ViewInfo);
    fn render(
        &mut self,
        renderables: &[RenderObject],
        view_info: &ViewInfo,
        settings: &RenderSettings,
    ) -> Result<RenderStats, RenderError>;
    fn get_last_frame_stats(&self) -> &RenderStats;
    fn supports_feature(&self, feature_name: &str) -> bool;
    fn get_adapter_info(&self) -> Option<RendererAdapterInfo>;
    fn graphics_device(&self) -> Arc<dyn GraphicsDevice>;
    fn shutdown(&mut self);
    fn as_any(&self) -> &dyn Any;
}
Expand description

A high-level trait representing the entire rendering subsystem.

This trait defines the primary interface for the engine to interact with the renderer. A concrete implementation of RenderSystem (likely in khora-infra) encapsulates all the state and logic needed to render a frame, including device management, swapchain handling, and the execution of render pipelines.

This can be considered the main “contract” for a RenderAgent to manage.

Required Methods§

Source

fn init( &mut self, window: &dyn KhoraWindow, ) -> Result<Vec<Arc<dyn ResourceMonitor>>, RenderError>

Initializes the rendering system with a given window.

This method sets up the graphics device, swapchain, and any other necessary backend resources. It should be called once at application startup.

§Returns

On success, it returns a Vec of ResourceMonitor trait objects that the telemetry system can use to track GPU-specific resources like VRAM.

Source

fn resize(&mut self, new_width: u32, new_height: u32)

Notifies the rendering system that the output window has been resized.

The implementation should handle recreating the swapchain and any other size-dependent resources (like depth textures).

Source

fn prepare_frame(&mut self, view_info: &ViewInfo)

Prepares for a new frame.

This is typically called once per frame before render. It can be used to update internal resources, like uniform buffers, based on the camera’s ViewInfo.

Source

fn render( &mut self, renderables: &[RenderObject], view_info: &ViewInfo, settings: &RenderSettings, ) -> Result<RenderStats, RenderError>

Renders a single frame.

This is the main workload function, responsible for executing all necessary render passes to draw the provided renderables to the screen.

§Arguments
  • renderables: A slice of RenderObjects representing the scene to be drawn.
  • view_info: Contains camera and projection information for the frame.
  • settings: Contains global rendering settings for the frame.
§Returns

On success, it returns RenderStats with performance metrics for the frame.

Source

fn get_last_frame_stats(&self) -> &RenderStats

Returns a reference to the statistics of the last successfully rendered frame.

Source

fn supports_feature(&self, feature_name: &str) -> bool

Checks if a specific, optional rendering feature is supported by the backend.

Source

fn get_adapter_info(&self) -> Option<RendererAdapterInfo>

Returns information about the active graphics adapter (GPU).

Source

fn graphics_device(&self) -> Arc<dyn GraphicsDevice>

Returns a shared, thread-safe reference to the underlying GraphicsDevice.

This allows other parts of the engine (e.g., the asset system) to create graphics resources like buffers and textures on the correct GPU device.

Source

fn shutdown(&mut self)

Cleans up and releases all graphics resources. This should be called once at application shutdown.

Source

fn as_any(&self) -> &dyn Any

Allows downcasting to a concrete RenderSystem type.

Implementors§