#![cfg_attr(not(debug_assertions), deny(warnings))]
#![deny(clippy::all, rust_2018_idioms)]
#![warn(
missing_docs,
missing_debug_implementations,
trivial_casts,
trivial_numeric_casts,
unsafe_code,
unstable_features,
unused_import_braces,
unused_qualifications
)]
use bytemuck::{Pod, Zeroable};
use image::DynamicImage;
use monstertruck_gpu::{wgpu::*, *};
use std::sync::Arc;
pub mod polymesh {
pub use monstertruck_mesh::*;
}
pub use polymesh::*;
#[derive(Debug, Clone, Copy)]
pub struct Material {
pub albedo: Vector4,
pub roughness: f64,
pub reflectance: f64,
pub ambient_ratio: f64,
pub background_ratio: f64,
pub alpha_blend: bool,
}
#[derive(Clone, Debug)]
pub struct PolygonState {
pub matrix: Matrix4,
pub material: Material,
pub texture: Option<Arc<Texture>>,
pub backface_culling: bool,
}
#[derive(Clone, Debug)]
pub struct WireFrameState {
pub matrix: Matrix4,
pub color: Vector4,
}
#[derive(Debug, Clone)]
pub struct PolygonShaders {
vertex_module: Arc<ShaderModule>,
vertex_entry: &'static str,
fragment_module: Arc<ShaderModule>,
fragment_entry: &'static str,
tex_fragment_module: Arc<ShaderModule>,
tex_fragment_entry: &'static str,
}
#[derive(Debug, Clone)]
pub struct WireShaders {
vertex_module: Arc<ShaderModule>,
vertex_entry: &'static str,
fragment_module: Arc<ShaderModule>,
fragment_entry: &'static str,
}
#[derive(Debug)]
pub struct PolygonInstance {
polygon: (Arc<BufferHandler>, Arc<BufferHandler>),
state: PolygonState,
shaders: PolygonShaders,
id: RenderId,
}
#[derive(Debug)]
pub struct WireFrameInstance {
vertices: Arc<BufferHandler>,
strips: Arc<BufferHandler>,
state: WireFrameState,
shaders: WireShaders,
id: RenderId,
}
#[derive(Debug, Clone)]
pub struct InstanceCreator {
handler: DeviceHandler,
polygon_shaders: PolygonShaders,
wire_shaders: WireShaders,
}
pub trait CreatorCreator {
fn instance_creator(&self) -> InstanceCreator;
}
pub trait CreateBuffers {
fn buffers(
&self,
vertex_usage: BufferUsages,
index_usage: BufferUsages,
device: &Device,
) -> (BufferHandler, BufferHandler);
}
pub trait ToInstance<I: Instance> {
type State;
fn to_instance(&self, handler: &DeviceHandler, shaders: &I::Shaders, desc: &Self::State) -> I;
}
pub trait Instance {
#[doc(hidden)]
type Shaders;
#[doc(hidden)]
fn standard_shaders(creator: &InstanceCreator) -> Self::Shaders;
}
#[repr(C)]
#[derive(Debug, Clone, Copy, Zeroable, Pod)]
struct AttrVertex {
pub position: [f32; 3],
pub uv_coord: [f32; 2],
pub normal: [f32; 3],
}
pub mod image2texture;
mod instance_creator;
mod instance_descriptor;
mod polygon_instance;
mod polyrend;
mod wireframe_instance;