110 lines
2.9 KiB
Rust
110 lines
2.9 KiB
Rust
use anyhow::Result;
|
|
|
|
use glfw::PWindow;
|
|
|
|
use crate::cataclysm::Cataclysm;
|
|
|
|
#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
|
|
pub mod vulkan;
|
|
|
|
#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
|
|
pub mod vulkan_gc;
|
|
|
|
#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
|
|
pub mod opengl;
|
|
|
|
#[cfg(target_family = "wasm")] pub mod webgpu;
|
|
|
|
#[cfg(target_os = "macos")] pub mod metal;
|
|
|
|
#[cfg(target_os = "windows")] pub mod directx;
|
|
|
|
#[cfg(target_os = "vita")] pub mod gxm;
|
|
|
|
type Vec2f = cgmath::Vector2<f32>;
|
|
type Vec3f = cgmath::Vector3<f32>;
|
|
type Vec4f = cgmath::Vector4<f32>;
|
|
|
|
type Vec2d = cgmath::Vector2<f64>;
|
|
type Vec3d = cgmath::Vector3<f64>;
|
|
type Vec4d = cgmath::Vector4<f64>;
|
|
|
|
type Mat2f = cgmath::Matrix2<f32>;
|
|
type Mat3f = cgmath::Matrix3<f32>;
|
|
type Mat4f = cgmath::Matrix4<f32>;
|
|
|
|
type Mat2d = cgmath::Matrix2<f64>;
|
|
type Mat3d = cgmath::Matrix3<f64>;
|
|
type Mat4d = cgmath::Matrix4<f64>;
|
|
|
|
#[repr(C)]
|
|
#[derive(Debug, Clone, Default)]
|
|
pub struct VertexData {
|
|
pub verts: Box<[Vertex]>,
|
|
pub indices:Box<[u32]>,
|
|
}
|
|
|
|
#[repr(C)]
|
|
#[derive(Copy, Clone, Debug)]
|
|
pub struct Vertex {
|
|
pub pos: Vec2f,
|
|
pub color:Vec3f,
|
|
}
|
|
|
|
impl Vertex {
|
|
pub const fn new(pos:Vec2f, color:Vec3f) -> Self { Self { pos, color } }
|
|
}
|
|
|
|
#[allow(unused)]
|
|
pub trait GraphicsCommander {
|
|
/// Used to halt all render calls and calculations
|
|
/// May deallocate graphics memory
|
|
fn suspend_rendering(&mut self);
|
|
/// Used to resume all render calls and calculations
|
|
/// May allocate graphics memory
|
|
fn resume_rendering(&mut self);
|
|
|
|
/// The first called function, used to register self to window and collect needed info from the system
|
|
fn initialize_controller_system(&mut self, window: &mut PWindow);
|
|
|
|
/// Returns a formatted multiline string detailing various aspects of the render system, meant to be immediately presented to the user through the engine
|
|
fn get_renderer_information(&self) -> String;
|
|
|
|
/// Used to load and potentially compile a shader
|
|
fn load_shader_program(&mut self);
|
|
|
|
// TODO cataclysm render object
|
|
|
|
// will need a reference to game engine objects
|
|
// replace with generic draw call? draw call will draw instructions to image, image may be framebuffer or not, allows gpu accelerated dynamic texture stuff
|
|
fn render(&mut self, window:&mut PWindow, cataclysm:&mut Cataclysm) -> Result<()>;
|
|
|
|
fn create_vxos(&mut self, data:&[VertexData]);
|
|
fn destroy_vxos(&mut self);
|
|
// make generic for assets?
|
|
fn register_texture(&mut self);
|
|
fn destroy_texture(&mut self);
|
|
|
|
// cleans up all data from memory, used when exiting or switching graphics backends
|
|
//fn cleanup(&mut self);
|
|
fn exit(&mut self);
|
|
}
|
|
|
|
#[repr(C)]
|
|
#[derive(Copy, Clone, Debug)]
|
|
struct UniformBufferObject {
|
|
model:Mat4f,
|
|
view: Mat4f,
|
|
proj: Mat4f,
|
|
}
|
|
|
|
#[allow(unused)]
|
|
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
|
pub enum GMode {
|
|
Vulkan,
|
|
OpenGL,
|
|
#[cfg(target_os = "macos")]
|
|
Metal,
|
|
#[cfg(target_os = "windows")]
|
|
DirectX,
|
|
}
|