pub mod brdf_lut;
mod camera_viewport;
#[cfg(feature = "assets")]
pub mod envmap_filter;
mod execution;
mod frame;
pub mod glyph_atlas;
#[cfg(feature = "assets")]
pub mod hdr;
mod initialization;
pub mod material_texture_arrays;
pub mod mip_generator;
pub mod passes;
pub mod rendergraph;
pub mod shader_compose;
pub mod text_mesh;
pub mod texture_cache;
pub mod ui_texture_array;
#[derive(Default, Clone)]
pub struct WindowRenderState {
pub recent_buffer_sizes: Vec<(u32, u32)>,
pub last_settings_version: Option<u64>,
}
const RECENT_BUFFER_SIZE_CAPACITY: usize = 8;
pub struct CameraViewport {
pub texture: wgpu::Texture,
pub view: wgpu::TextureView,
pub size: (u32, u32),
pub has_rendered_at_least_once: bool,
pub last_active_view: Option<crate::ecs::camera::components::EffectiveShading>,
pub last_settings_version: u64,
pub last_render_frame: u64,
pub last_camera_world_transform: Option<nalgebra_glm::Mat4>,
}
const DEPTH_PICK_SAMPLE_SIZE: u32 = 5;
pub struct WgpuRenderer {
surface: wgpu::Surface<'static>,
device: wgpu::Device,
queue: wgpu::Queue,
surface_config: wgpu::SurfaceConfiguration,
surface_format: wgpu::TextureFormat,
supported_present_modes: Vec<wgpu::PresentMode>,
graph: rendergraph::RenderGraph<crate::ecs::world::World>,
targets: RenderTargets,
spotlight_shadow_atlas_texture: wgpu::Texture,
spotlight_shadow_atlas_view: wgpu::TextureView,
ui_image_pass: Option<Box<passes::UiImagePass>>,
pub(super) glyph_atlas: glyph_atlas::GlyphAtlas,
camera_viewports: std::collections::HashMap<freecs::Entity, CameraViewport>,
_brdf_lut_texture: wgpu::Texture,
brdf_lut_view: wgpu::TextureView,
material_texture_arrays: material_texture_arrays::MaterialTextureArrays,
pub(super) ui_texture_array: ui_texture_array::UiTextureArray,
mip_generator: mip_generator::MipGenerator,
depth_pick: DepthPickState,
#[cfg(not(target_arch = "wasm32"))]
screenshot: ScreenshotState,
render_buffer_size: (u32, u32),
window_render_state: WindowRenderState,
frame_state: FrameState,
gpu_profile: crate::ecs::graphics::resources::GpuProfile,
}
struct RenderTargets {
depth: rendergraph::ResourceId,
scene_color: rendergraph::ResourceId,
compute_output: rendergraph::ResourceId,
fxaa_output: rendergraph::ResourceId,
swapchain: rendergraph::ResourceId,
viewport_resource: rendergraph::ResourceId,
ui_depth: rendergraph::ResourceId,
entity_id: rendergraph::ResourceId,
view_normals: rendergraph::ResourceId,
ssao_raw: rendergraph::ResourceId,
ssao: rendergraph::ResourceId,
ssgi_raw: rendergraph::ResourceId,
ssgi: rendergraph::ResourceId,
ssr_raw: rendergraph::ResourceId,
ssr: rendergraph::ResourceId,
spotlight_shadow_atlas: rendergraph::ResourceId,
}
struct DepthPickState {
compute_pipeline: wgpu::ComputePipeline,
bind_group_layout: wgpu::BindGroupLayout,
storage_buffer: wgpu::Buffer,
uniform_buffer: wgpu::Buffer,
staging_buffer: wgpu::Buffer,
bind_group: Option<wgpu::BindGroup>,
pending: bool,
map_complete: std::sync::Arc<std::sync::atomic::AtomicBool>,
center: (u32, u32),
texture_size: (u32, u32),
camera: Option<freecs::Entity>,
}
#[cfg(not(target_arch = "wasm32"))]
struct ScreenshotState {
staging_buffer: wgpu::Buffer,
pending: bool,
map_complete: std::sync::Arc<std::sync::atomic::AtomicBool>,
path: Option<std::path::PathBuf>,
width: u32,
height: u32,
max_dimension: Option<u32>,
}
struct FrameState {
index: u64,
last_settings_signature: Option<u64>,
text_meshes_prepared_for_frame: u64,
extract_dirty_done_for_frame: u64,
text_mesh_signatures: std::collections::HashMap<freecs::Entity, u64>,
glyph_atlas_initialized: bool,
}
pub async fn create_wgpu_renderer<W>(
window_handle: W,
initial_width: u32,
initial_height: u32,
) -> Result<WgpuRenderer, Box<dyn std::error::Error>>
where
W: Into<wgpu::SurfaceTarget<'static>>,
{
WgpuRenderer::new_async(window_handle, initial_width, initial_height).await
}