macro_rules! impl_effect_body {
($inner:ident) => {
fn fragment_shader_source(
&self,
lights: &[&dyn Light],
color_texture: Option<ColorTexture>,
depth_texture: Option<DepthTexture>,
) -> String {
self.$inner()
.fragment_shader_source(lights, color_texture, depth_texture)
}
fn id(
&self,
color_texture: Option<ColorTexture>,
depth_texture: Option<DepthTexture>,
) -> u16 {
self.$inner().id(color_texture, depth_texture)
}
fn fragment_attributes(&self) -> FragmentAttributes {
self.$inner().fragment_attributes()
}
fn use_uniforms(
&self,
program: &Program,
camera: &Camera,
lights: &[&dyn Light],
color_texture: Option<ColorTexture>,
depth_texture: Option<DepthTexture>,
) {
self.$inner()
.use_uniforms(program, camera, lights, color_texture, depth_texture)
}
fn render_states(&self) -> RenderStates {
self.$inner().render_states()
}
};
}
mod fog;
#[doc(inline)]
pub use fog::*;
mod copy;
#[doc(inline)]
pub use copy::*;
mod full_screen;
#[doc(inline)]
pub use full_screen::*;
mod fxaa;
#[doc(inline)]
pub use fxaa::*;
mod water;
#[doc(inline)]
pub use water::*;
pub(crate) mod lighting_pass;
use crate::renderer::*;
use std::ops::Deref;
pub trait Effect {
fn fragment_shader_source(
&self,
lights: &[&dyn Light],
color_texture: Option<ColorTexture>,
depth_texture: Option<DepthTexture>,
) -> String;
fn id(&self, color_texture: Option<ColorTexture>, depth_texture: Option<DepthTexture>) -> u16;
fn fragment_attributes(&self) -> FragmentAttributes;
fn use_uniforms(
&self,
program: &Program,
camera: &Camera,
lights: &[&dyn Light],
color_texture: Option<ColorTexture>,
depth_texture: Option<DepthTexture>,
);
fn render_states(&self) -> RenderStates;
}
impl<T: Effect + ?Sized> Effect for &T {
impl_effect_body!(deref);
}
impl<T: Effect + ?Sized> Effect for &mut T {
impl_effect_body!(deref);
}
impl<T: Effect> Effect for Box<T> {
impl_effect_body!(as_ref);
}
impl<T: Effect> Effect for std::rc::Rc<T> {
impl_effect_body!(as_ref);
}
impl<T: Effect> Effect for std::sync::Arc<T> {
impl_effect_body!(as_ref);
}
impl<T: Effect> Effect for std::cell::RefCell<T> {
impl_effect_body!(borrow);
}
impl<T: Effect> Effect for std::sync::RwLock<T> {
fn fragment_shader_source(
&self,
lights: &[&dyn Light],
color_texture: Option<ColorTexture>,
depth_texture: Option<DepthTexture>,
) -> String {
self.read()
.unwrap()
.fragment_shader_source(lights, color_texture, depth_texture)
}
fn id(&self, color_texture: Option<ColorTexture>, depth_texture: Option<DepthTexture>) -> u16 {
self.read().unwrap().id(color_texture, depth_texture)
}
fn fragment_attributes(&self) -> FragmentAttributes {
self.read().unwrap().fragment_attributes()
}
fn use_uniforms(
&self,
program: &Program,
camera: &Camera,
lights: &[&dyn Light],
color_texture: Option<ColorTexture>,
depth_texture: Option<DepthTexture>,
) {
self.read()
.unwrap()
.use_uniforms(program, camera, lights, color_texture, depth_texture)
}
fn render_states(&self) -> RenderStates {
self.read().unwrap().render_states()
}
}