#![deny(missing_docs)] //! High-level rendering concepts for Gfx. Allow user code to work with //! materials, entities, and techniques, instead of batches. #[macro_use] extern crate log; extern crate gfx; extern crate draw_queue; extern crate hprof; mod mem; mod phase; use std::fmt::Debug; use std::hash::Hash; pub use self::phase::{Object, sort, FlushError, OrderFun, AbstractPhase, CachedPhase, Phase}; /// Abstract material. pub trait Material {} /// View information that can be transformed into depth. pub trait ToDepth { /// The type of the depth to convert to. type Depth: Copy + Debug + PartialOrd; /// Convert to depth. fn to_depth(&self) -> Self::Depth; } /// Resulting type of the technique compilation. pub type TechResult<'a, R, P> = ( &'a gfx::handle::Program, // program P, // parameters &'a gfx::DrawState, // state // instancing and additional attributes Option<(gfx::InstanceCount, &'a [gfx::Attribute])>, ); /// Technique is basically a `Fn(Entity) -> Option`. /// It processes a material, checks for the compatibility, adds a mesh /// to produce a shader program with associated data (state, parameters). pub trait Technique { /// The most important part of the entity, which is enough to decide /// which program or state to use on it. type Kernel: Copy + Debug + Eq + Hash; /// Associated shader parameters. type Params: gfx::shade::ShaderParam; /// Test if this mesh/material can be drawn using the technique. fn test(&self, &gfx::Mesh, &M) -> Option; /// Compile a given kernel by producing a program, parameter block, /// a draw state, and optional instancing data. fn compile<'a>(&'a self, Self::Kernel) -> TechResult<'a, R, Self::Params>; /// Fix the shader parameters, using an updated material and view info. /// Called every time before a batch is added to the draw queue. fn fix_params(&self, &M, &V, &mut Self::Params); }