use downcast::{Any, downcast};
pub mod imports;
pub use imports::*;
pub mod primitive_shapes;
pub use crate::camera::{Camera, CameraContainer, Projection};
pub use crate::definition::{
Pipeline, PipelineData, ShaderSettings, TextureData, TextureMode, VertexBuffers,
pixel_to_cartesian,
};
pub use crate::engine::{Engine, EngineSettings};
pub use crate::objects::{
Instance, InstanceRaw, Object, ObjectSettings, ObjectStorage, RotateAmount, RotateAxis,
};
pub use crate::render::Renderer;
#[cfg(all(feature = "window", not(feature = "headless")))]
pub use crate::window::Window;
#[cfg(not(feature = "u32"))]
pub type UnsignedIntType = u16;
#[cfg(feature = "u32")]
pub type UnsignedIntType = u32;
pub mod macros {
macro_rules! impl_deref {
($struct:ty,$type:ty) => {
impl std::ops::Deref for $struct {
type Target = $type;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl std::ops::DerefMut for $struct {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
};
}
macro_rules! impl_deref_field {
($struct:ty,$type:ty,$field:ident) => {
impl std::ops::Deref for $struct {
type Target = $type;
fn deref(&self) -> &Self::Target {
&self.$field
}
}
impl std::ops::DerefMut for $struct {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.$field
}
}
};
}
pub(crate) use impl_deref;
pub(crate) use impl_deref_field;
}
#[repr(C)]
#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
pub struct Vertex {
pub position: [f32; 3],
pub uv: [f32; 2],
pub normal: [f32; 3],
}
impl Vertex {
pub(crate) fn desc<'a>() -> wgpu::VertexBufferLayout<'a> {
wgpu::VertexBufferLayout {
array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &[
wgpu::VertexAttribute {
offset: 0,
shader_location: 0,
format: wgpu::VertexFormat::Float32x3,
},
wgpu::VertexAttribute {
offset: std::mem::size_of::<[f32; 3]>() as wgpu::BufferAddress,
shader_location: 1,
format: wgpu::VertexFormat::Float32x2,
},
wgpu::VertexAttribute {
offset: std::mem::size_of::<[f32; 5]>() as wgpu::BufferAddress,
shader_location: 2,
format: wgpu::VertexFormat::Float32x3,
},
],
}
}
}
unsafe impl Send for Vertex {}
unsafe impl Sync for Vertex {}
pub trait Signal: Any {
#[allow(clippy::too_many_arguments)]
fn init(&mut self, _engine: &mut crate::Engine) {}
#[allow(clippy::too_many_arguments)]
#[cfg(all(feature = "window", not(feature = "headless")))]
fn device_events(&mut self, _engine: &mut crate::Engine, _events: &crate::DeviceEvent) {}
#[allow(clippy::too_many_arguments)]
#[cfg(all(feature = "window", not(feature = "headless")))]
fn window_events(&mut self, _engine: &mut crate::Engine, _events: &crate::WindowEvent) {}
#[allow(clippy::too_many_arguments)]
fn frame(
&mut self,
_engine: &mut crate::Engine,
_encoder: &mut crate::CommandEncoder,
_view: &crate::TextureView,
) {
}
}
downcast!(dyn Signal);
pub struct SignalStorage {
pub events: Vec<(String, Box<dyn Signal>)>,
}
pub type WindowSize = (u32, u32);