use crate::{
core::{color::Color, math::Rect, sstorage::ImmutableString},
renderer::{
bundle::{BundleRenderContext, RenderDataBundleStorage},
cache::{shader::ShaderCache, texture::TextureCache, uniform::UniformMemoryAllocator},
framework::{
error::FrameworkError, framebuffer::FrameBuffer, gpu_texture::GpuTexture,
server::GraphicsServer,
},
FallbackResources, GeometryCache, QualitySettings, RenderPassStatistics,
},
scene::mesh::RenderPath,
};
use std::{cell::RefCell, rc::Rc};
pub(crate) struct ForwardRenderer {
render_pass_name: ImmutableString,
}
pub(crate) struct ForwardRenderContext<'a> {
pub state: &'a dyn GraphicsServer,
pub geom_cache: &'a mut GeometryCache,
pub texture_cache: &'a mut TextureCache,
pub shader_cache: &'a mut ShaderCache,
pub bundle_storage: &'a RenderDataBundleStorage,
pub framebuffer: &'a mut dyn FrameBuffer,
pub viewport: Rect<i32>,
pub quality_settings: &'a QualitySettings,
pub fallback_resources: &'a FallbackResources,
pub scene_depth: Rc<RefCell<dyn GpuTexture>>,
pub ambient_light: Color,
pub uniform_memory_allocator: &'a mut UniformMemoryAllocator,
}
impl ForwardRenderer {
pub(crate) fn new() -> Self {
Self {
render_pass_name: ImmutableString::new("Forward"),
}
}
pub(crate) fn render(
&self,
args: ForwardRenderContext,
) -> Result<RenderPassStatistics, FrameworkError> {
let mut statistics = RenderPassStatistics::default();
let ForwardRenderContext {
state,
geom_cache,
texture_cache,
shader_cache,
bundle_storage,
framebuffer,
viewport,
quality_settings,
fallback_resources,
scene_depth,
ambient_light,
uniform_memory_allocator,
} = args;
statistics += bundle_storage.render_to_frame_buffer(
state,
geom_cache,
shader_cache,
|bundle| bundle.render_path == RenderPath::Forward,
|_| true,
BundleRenderContext {
texture_cache,
render_pass_name: &self.render_pass_name,
frame_buffer: framebuffer,
viewport,
uniform_memory_allocator,
use_pom: quality_settings.use_parallax_mapping,
light_position: &Default::default(),
fallback_resources,
ambient_light,
scene_depth: Some(&scene_depth),
},
)?;
Ok(statistics)
}
}