Seregon/StratoSDK

StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.

Rust/27.3 KB/No license
crates/strato-renderer/src/backend/mod.rs
1use self::commands::RenderCommand;
2use anyhow::Result;
3use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
4 
5pub mod commands;
6pub mod wgpu;
7 
8pub use wgpu::WgpuBackend;
9 
10/// Trait that all rendering backends must implement.
11/// This decouples the engine from specific graphics APIs (wgpu, vulkan, etc.).
12use async_trait::async_trait;
13 
14#[async_trait]
15pub trait Backend: Send + Sync {
16 /// Resize the backend surface
17 fn resize(&mut self, width: u32, height: u32);
18 
19 /// Set the scale factor (DPI)
20 fn set_scale_factor(&mut self, scale_factor: f64);
21 
22 /// Begin a new frame
23 fn begin_frame(&mut self) -> Result<()>;
24 
25 /// End the current frame and present
26 fn end_frame(&mut self) -> Result<()>;
27 
28 /// Submit a list of render commands to be executed
29 fn submit(&mut self, commands: &[RenderCommand]) -> Result<()>;
30 
31 /// Submit a render batch for execution (optimized path)
32 fn submit_batch(&mut self, _batch: &crate::batch::RenderBatch) -> Result<()> {
33 // Default implementation falls back to submit if possible, or errors?
34 // Since RenderBatch contains DrawCommands which are not exactly RenderCommands (DrawCommand vs RenderCommand),
35 // we can't easily fallback without conversion logic.
36 // Let's make it mandatory or return logic error.
37 Err(anyhow::anyhow!(
38 "submit_batch not implemented for this backend"
39 ))
40 }
41}
42