use crate::{
core::sstorage::ImmutableString,
renderer::framework::{
error::FrameworkError,
gpu_program::{GpuProgram, UniformLocation},
server::GraphicsServer,
},
};
pub struct AmbientLightShader {
pub program: Box<dyn GpuProgram>,
pub uniform_buffer_binding: usize,
pub diffuse_texture: UniformLocation,
pub ao_sampler: UniformLocation,
pub ambient_texture: UniformLocation,
}
impl AmbientLightShader {
pub fn new(server: &dyn GraphicsServer) -> Result<Self, FrameworkError> {
let fragment_source = include_str!("../shaders/ambient_light_fs.glsl");
let vertex_source = include_str!("../shaders/ambient_light_vs.glsl");
let program =
server.create_program("AmbientLightShader", vertex_source, fragment_source)?;
Ok(Self {
uniform_buffer_binding: program
.uniform_block_index(&ImmutableString::new("Uniforms"))?,
diffuse_texture: program.uniform_location(&ImmutableString::new("diffuseTexture"))?,
ao_sampler: program.uniform_location(&ImmutableString::new("aoSampler"))?,
ambient_texture: program.uniform_location(&ImmutableString::new("ambientTexture"))?,
program,
})
}
}