1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#![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<R>, // program P, // parameters &'a gfx::DrawState, // state // instancing and additional attributes Option<(gfx::InstanceCount, &'a [gfx::Attribute<R>])>, ); /// Technique is basically a `Fn(Entity) -> Option<TechResult>`. /// It processes a material, checks for the compatibility, adds a mesh /// to produce a shader program with associated data (state, parameters). pub trait Technique<R: gfx::Resources, M: Material, V: ToDepth> { /// 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<Resources = R>; /// Test if this mesh/material can be drawn using the technique. fn test(&self, &gfx::Mesh<R>, &M) -> Option<Self::Kernel>; /// 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); }