use soul_terminal_core::{Color, RenderCommand};
#[derive(Debug)]
pub enum RenderError {
SurfaceError(String),
DeviceError(String),
ShaderError(String),
TextureError(String),
}
impl std::fmt::Display for RenderError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::SurfaceError(e) => write!(f, "surface error: {e}"),
Self::DeviceError(e) => write!(f, "device error: {e}"),
Self::ShaderError(e) => write!(f, "shader error: {e}"),
Self::TextureError(e) => write!(f, "texture error: {e}"),
}
}
}
impl std::error::Error for RenderError {}
pub trait RenderBackend {
fn begin_frame(&mut self, clear_color: Color) -> Result<(), RenderError>;
fn submit(&mut self, commands: &[RenderCommand]) -> Result<(), RenderError>;
fn present(&mut self) -> Result<(), RenderError>;
fn resize(&mut self, width: u32, height: u32);
fn load_texture(&mut self, width: u32, height: u32, data: &[u8]) -> Result<u64, RenderError>;
fn size(&self) -> (u32, u32);
fn scale_factor(&self) -> f32;
}