opengl_sdk/src/backend/backend.rs

50 lines
1.3 KiB
Rust

use crate::{geometry, handles::{self, MeshHandle}, math};
use std::ffi::CString;
pub struct DrawCommand<'a> {
pub mesh: handles::MeshHandle,
pub shader: handles::ShaderHandle,
pub uniforms: &'a [Uniform],
pub textures: &'a [(u32, u32)],
}
#[derive(Clone, Debug)]
pub enum Uniform {
Float(CString, f32),
Vec2(CString, math::Vec2),
Vec3(CString, math::Vec3),
Vec4(CString, math::Vec4),
Mat4(CString, math::Mat4),
Int(CString, i32)
}
pub trait RenderBackend {
type ShaderSource: Default;
fn new() -> Self;
fn resume(&mut self, event_loop: &winit::event_loop::ActiveEventLoop);
fn resize(&mut self, width: u32, height: u32);
fn suspend(&mut self);
fn begin_frame(&mut self);
fn draw(&self, cmd: &DrawCommand);
fn end_frame(&self);
fn create_shader(&mut self, desc: &Self::ShaderSource) -> Result<handles::ShaderHandle, String>;
fn create_mesh(&mut self, mesh: &geometry::Mesh) -> Result<MeshHandle, String>;
// fn create_buffer(&mut self, data: &[u8], usage: BufferUsage) -> BufferHandle;
// fn create_texture(&mut self, desc: TextureDescriptor) -> TextureHandle;
fn set_target_fps(&mut self, fps: u32);
}
// pub struct FrameContext<'a> {
// backend: &'a mut dyn RenderBackend,
// }
//
// impl FrameContext<'_> {
// pub fn draw(&mut self, mesh: &Mesh, material: MaterialHandle, transform: Mat4);
// }