use crate::egl::{ContextRef, CurrentContext, Dimensions, Texture};
use crate::raw;
use glium::{program, uniform};
use std::error::Error;
use super::Shader;
pub struct Passthrough;
impl Passthrough {
pub fn new(facade: &impl glium::backend::Facade, dims: (u32, u32))
-> Result<Shader<Self>, Box<dyn Error>>
{
Shader::<Self>::new_with_facade(facade, dims)
}
}
impl Shader<Passthrough> {
fn new_with_facade<F: glium::backend::Facade>(
facade: &F,
size: (u32, u32),
) -> Result<Self, Box<dyn Error>> {
let (vertices, indices) = super::covering_vertices(facade, size)?;
Ok(Self {
program: program!(facade,
120 => {
vertex: include_str!("passthrough/vert.glsl"),
fragment: include_str!("passthrough/frag.glsl"),
}
)?,
vertices,
indices,
_data: Default::default(),
})
}
pub fn convert<F: glium::backend::Facade>(
&self,
facade: &F,
source_tex: Texture,
target: &mut impl glium::Surface,
) -> Result<(), Box<dyn Error>>{
let Dimensions { width, height } = source_tex.dimensions();
if (width, height) != target.get_dimensions() {
Err(super::Error::BadDimensions("Source and target dimensions must be equal"))?;
}
self.draw_any(
facade,
source_tex,
target,
uniform! {},
)
}
}