text rendering
This commit is contained in:
@@ -6,14 +6,18 @@ mod shadow;
|
||||
mod types;
|
||||
|
||||
pub mod billboard;
|
||||
pub mod font_atlas;
|
||||
pub mod snow;
|
||||
pub mod snow_light;
|
||||
pub mod text_pipeline;
|
||||
|
||||
pub use billboard::{BillboardDrawCall, BillboardPipeline};
|
||||
pub use font_atlas::FontAtlas;
|
||||
pub use global::{
|
||||
aspect_ratio, init, init_snow_light_accumulation, render, set_selected_entity, set_snow_depth,
|
||||
set_terrain_data, update_spotlights, with_device, with_queue, with_surface_format,
|
||||
set_terrain_data, update_spotlights, with_device, with_font_atlas, with_queue, with_surface_format,
|
||||
};
|
||||
pub use text_pipeline::TextVertex;
|
||||
pub use types::{DrawCall, Pipeline, Spotlight, SpotlightRaw, Uniforms, MAX_SPOTLIGHTS};
|
||||
|
||||
use crate::entity::EntityHandle;
|
||||
@@ -38,6 +42,7 @@ pub struct Renderer
|
||||
pub config: wgpu::SurfaceConfiguration,
|
||||
|
||||
framebuffer: LowResFramebuffer,
|
||||
fullres_depth_view: wgpu::TextureView,
|
||||
|
||||
standard_pipeline: wgpu::RenderPipeline,
|
||||
snow_clipmap_pipeline: wgpu::RenderPipeline,
|
||||
@@ -45,6 +50,8 @@ pub struct Renderer
|
||||
debug_lines_pipeline: Option<wgpu::RenderPipeline>,
|
||||
debug_overlay: Option<debug_overlay::DebugOverlay>,
|
||||
billboard_pipeline: BillboardPipeline,
|
||||
font_atlas: font_atlas::FontAtlas,
|
||||
text_pipeline: text_pipeline::TextPipeline,
|
||||
wireframe_supported: bool,
|
||||
|
||||
uniform_buffer: wgpu::Buffer,
|
||||
@@ -148,6 +155,23 @@ impl Renderer
|
||||
let framebuffer =
|
||||
LowResFramebuffer::new(&device, low_res_width, low_res_height, config.format);
|
||||
|
||||
let fullres_depth_texture = device.create_texture(&wgpu::TextureDescriptor {
|
||||
label: Some("Full Res Depth Texture"),
|
||||
size: wgpu::Extent3d {
|
||||
width: config.width,
|
||||
height: config.height,
|
||||
depth_or_array_layers: 1,
|
||||
},
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: wgpu::TextureFormat::Depth32Float,
|
||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||
view_formats: &[],
|
||||
});
|
||||
let fullres_depth_view =
|
||||
fullres_depth_texture.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
|
||||
let uniform_buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: Some("Uniform Buffer"),
|
||||
size: (std::mem::size_of::<Uniforms>() * MAX_DRAW_CALLS) as wgpu::BufferAddress,
|
||||
@@ -502,6 +526,8 @@ impl Renderer
|
||||
));
|
||||
|
||||
let billboard_pipeline = BillboardPipeline::new(&device, config.format);
|
||||
let font_atlas = font_atlas::FontAtlas::load(&device, &queue);
|
||||
let text_pipeline = text_pipeline::TextPipeline::new(&device, config.format, &font_atlas);
|
||||
|
||||
let debug_overlay = Some(debug_overlay::DebugOverlay::new(&device, config.format));
|
||||
|
||||
@@ -526,12 +552,15 @@ impl Renderer
|
||||
surface,
|
||||
config,
|
||||
framebuffer,
|
||||
fullres_depth_view,
|
||||
standard_pipeline,
|
||||
snow_clipmap_pipeline,
|
||||
wireframe_pipeline,
|
||||
debug_lines_pipeline,
|
||||
debug_overlay,
|
||||
billboard_pipeline,
|
||||
font_atlas,
|
||||
text_pipeline,
|
||||
wireframe_supported,
|
||||
uniform_buffer,
|
||||
bind_group_layout,
|
||||
@@ -576,6 +605,7 @@ impl Renderer
|
||||
player_position: glam::Vec3,
|
||||
draw_calls: &[DrawCall],
|
||||
billboard_calls: &[BillboardDrawCall],
|
||||
text_vertices: &[text_pipeline::TextVertex],
|
||||
time: f32,
|
||||
delta_time: f32,
|
||||
debug_mode: DebugMode,
|
||||
@@ -954,14 +984,6 @@ impl Renderer
|
||||
}
|
||||
}
|
||||
|
||||
self.billboard_pipeline.render(
|
||||
&mut encoder,
|
||||
&self.queue,
|
||||
&self.framebuffer.view,
|
||||
&self.framebuffer.depth_view,
|
||||
billboard_calls,
|
||||
);
|
||||
|
||||
self.queue.submit(std::iter::once(encoder.finish()));
|
||||
|
||||
let frame = match self.surface.get_current_texture()
|
||||
@@ -1012,6 +1034,50 @@ impl Renderer
|
||||
}
|
||||
|
||||
self.queue.submit(std::iter::once(blit_encoder.finish()));
|
||||
|
||||
let mut overlay_encoder =
|
||||
self.device
|
||||
.create_command_encoder(&wgpu::CommandEncoderDescriptor {
|
||||
label: Some("Dialog Overlay Encoder"),
|
||||
});
|
||||
|
||||
{
|
||||
let _depth_clear = overlay_encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
label: Some("Full Res Depth Clear"),
|
||||
color_attachments: &[],
|
||||
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
|
||||
view: &self.fullres_depth_view,
|
||||
depth_ops: Some(wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(1.0),
|
||||
store: wgpu::StoreOp::Store,
|
||||
}),
|
||||
stencil_ops: None,
|
||||
}),
|
||||
timestamp_writes: None,
|
||||
occlusion_query_set: None,
|
||||
multiview_mask: None,
|
||||
});
|
||||
}
|
||||
|
||||
self.billboard_pipeline.render(
|
||||
&mut overlay_encoder,
|
||||
&self.queue,
|
||||
&screen_view,
|
||||
&self.fullres_depth_view,
|
||||
billboard_calls,
|
||||
);
|
||||
|
||||
let view_proj = (*projection * *view).to_cols_array_2d();
|
||||
self.text_pipeline.render(
|
||||
&mut overlay_encoder,
|
||||
&self.queue,
|
||||
&screen_view,
|
||||
&self.fullres_depth_view,
|
||||
text_vertices,
|
||||
view_proj,
|
||||
);
|
||||
|
||||
self.queue.submit(std::iter::once(overlay_encoder.finish()));
|
||||
frame
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user