pub mod brdf_lut;
mod camera_viewport;
#[cfg(feature = "hdr")]
pub mod envmap_filter;
mod execution;
pub mod frame;
pub mod glyph_atlas;
#[cfg(feature = "hdr")]
pub mod hdr;
pub mod ibl;
mod initialization;
pub mod lights;
pub mod material_texture_arrays;
pub mod mip_generator;
pub mod pass_access;
pub mod pass_sync;
pub mod passes;
pub mod picking;
pub mod presentation;
pub mod render_configs;
mod surface;
pub mod texture_uploads;
pub mod view;
pub use crate::rendergraph;
pub mod shader_compose;
mod stagger;
pub mod texture_cache;
pub mod ui_texture_array;
pub use ::wgpu::*;
#[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::config::EffectiveShading>,
pub last_settings_version: u64,
pub last_render_frame: u64,
pub last_camera_world_transform: Option<nalgebra_glm::Mat4>,
}
pub const DEPTH_PICK_SAMPLE_SIZE: u32 = 5;
pub struct WgpuRenderer {
pub surface: wgpu::Surface<'static>,
pub device: wgpu::Device,
pub queue: wgpu::Queue,
pub surface_config: wgpu::SurfaceConfiguration,
pub surface_format: wgpu::TextureFormat,
pub supported_present_modes: Vec<wgpu::PresentMode>,
pub graph: rendergraph::RenderGraph<crate::wgpu::render_configs::RenderInputs>,
pub targets: RenderTargets,
pub spotlight_shadow_atlas_texture: wgpu::Texture,
pub spotlight_shadow_atlas_view: wgpu::TextureView,
pub ui_image_pass: Option<Box<passes::UiImagePass>>,
pub glyph_atlas: glyph_atlas::GlyphAtlas,
pub camera_viewports: std::collections::HashMap<crate::entity::RenderEntity, CameraViewport>,
pub _brdf_lut_texture: wgpu::Texture,
pub brdf_lut_view: wgpu::TextureView,
pub material_texture_arrays: material_texture_arrays::MaterialTextureArrays,
pub ui_texture_array: ui_texture_array::UiTextureArray,
pub mip_generator: mip_generator::MipGenerator,
pub depth_pick: DepthPickState,
#[cfg(not(target_arch = "wasm32"))]
pub screenshot: ScreenshotState,
pub render_buffer_size: (u32, u32),
pub window_render_state: WindowRenderState,
pub frame_state: FrameState,
pub gpu_profile: crate::config::GpuProfile,
pub ibl_views: crate::config::IblViews,
}
pub struct RenderTargets {
pub depth: rendergraph::ResourceId,
pub scene_color: rendergraph::ResourceId,
pub compute_output: rendergraph::ResourceId,
pub aa_output: rendergraph::ResourceId,
pub swapchain: rendergraph::ResourceId,
pub viewport_resource: rendergraph::ResourceId,
pub ui_depth: rendergraph::ResourceId,
pub entity_id: rendergraph::ResourceId,
pub view_normals: rendergraph::ResourceId,
pub velocity: rendergraph::ResourceId,
pub ssao_raw: rendergraph::ResourceId,
pub ssao: rendergraph::ResourceId,
pub ssgi_raw: rendergraph::ResourceId,
pub ssgi: rendergraph::ResourceId,
pub ssr_raw: rendergraph::ResourceId,
pub ssr: rendergraph::ResourceId,
pub spotlight_shadow_atlas: rendergraph::ResourceId,
}
pub struct DepthPickState {
pub compute_pipeline: wgpu::ComputePipeline,
pub bind_group_layout: wgpu::BindGroupLayout,
pub storage_buffer: wgpu::Buffer,
pub uniform_buffer: wgpu::Buffer,
pub staging_buffer: wgpu::Buffer,
pub bind_group: Option<wgpu::BindGroup>,
pub pending: bool,
pub map_complete: std::sync::Arc<std::sync::atomic::AtomicBool>,
pub center: (u32, u32),
pub texture_size: (u32, u32),
pub camera: Option<crate::entity::RenderEntity>,
}
#[cfg(not(target_arch = "wasm32"))]
pub struct ScreenshotState {
pub staging_buffer: wgpu::Buffer,
pub pending: bool,
pub map_complete: std::sync::Arc<std::sync::atomic::AtomicBool>,
pub path: Option<std::path::PathBuf>,
pub width: u32,
pub height: u32,
pub max_dimension: Option<u32>,
}
pub struct FrameState {
pub index: u64,
pub last_settings_signature: Option<u64>,
pub text_mesh_signatures: std::collections::HashMap<crate::entity::RenderEntity, u64>,
pub captured_ibl_atmosphere: Option<crate::config::Atmosphere>,
pub captured_ibl_hour: f32,
pub captured_day_night_snapshots: 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
}