#![deny(missing_docs)]
extern crate gfx_phase;
extern crate gfx;
extern crate cgmath;
extern crate collision;
extern crate hprof;
mod cull;
pub use gfx_phase::AbstractPhase;
pub use self::cull::{Culler, Frustum, Context};
#[derive(Debug)]
pub enum Error {
Batch(gfx::batch::Error),
Flush(gfx_phase::FlushError),
}
pub type Count = u32;
#[derive(Clone, Debug)]
pub struct Report {
pub calls_invisible: Count,
pub calls_culled: Count,
pub calls_rejected: Count,
pub calls_failed: Count,
pub calls_passed: Count,
pub primitives_rendered: Count,
}
impl Report {
pub fn new() -> Report {
Report {
calls_rejected: 0,
calls_failed: 0,
calls_culled: 0,
calls_invisible: 0,
calls_passed: 0,
primitives_rendered: 0,
}
}
pub fn get_calls_total(&self) -> Count {
self.calls_invisible + self.calls_culled +
self.calls_rejected + self.calls_failed +
self.calls_passed
}
pub fn get_calls_ratio(&self) -> f32 {
self.calls_passed as f32 / self.get_calls_total() as f32
}
}
pub trait AbstractScene<R: gfx::Resources> {
type ViewInfo: gfx_phase::ToDepth;
type Material;
type Camera;
type Status;
fn draw<H, S>(&self, &mut H, &Self::Camera, &mut S)
-> Result<Self::Status, Error> where
H: gfx_phase::AbstractPhase<R, Self::Material, Self::ViewInfo>,
S: gfx::Stream<R>;
}
#[derive(Clone, Debug)]
pub struct Fragment<R: gfx::Resources, M> {
pub material: M,
pub slice: gfx::Slice<R>,
}
impl<R: gfx::Resources, M> Fragment<R, M> {
pub fn new(mat: M, slice: gfx::Slice<R>) -> Fragment<R, M> {
Fragment {
material: mat,
slice: slice,
}
}
}
pub trait Node {
type Transform;
fn get_transform(&self) -> Self::Transform;
}
pub trait Entity<R: gfx::Resources, M>: Node {
type Bound;
fn is_visible(&self) -> bool { true }
fn get_bound(&self) -> Self::Bound;
fn get_mesh(&self) -> &gfx::Mesh<R>;
fn get_fragments(&self) -> &[Fragment<R, M>];
}
pub trait Camera<S>: Node {
type Projection: std::convert::Into<cgmath::Matrix4<S>>;
fn get_projection(&self) -> Self::Projection;
fn get_view_projection(&self) -> cgmath::Matrix4<S> where
S: cgmath::BaseFloat,
Self::Transform : cgmath::Transform3<S>
{
use cgmath::{Matrix, Transform};
let view = self.get_transform().invert().unwrap();
self.get_projection().into().mul_m(&view.into())
}
}
pub trait ViewInfo<S, T>: gfx_phase::ToDepth<Depth = S>
where S: Copy+PartialOrd+std::fmt::Debug
{
fn new(mvp: cgmath::Matrix4<S>, view: T, model: T) -> Self;
}