improve error handling
This commit is contained in:
parent
aa22e85676
commit
f481dec62a
5 changed files with 112 additions and 54 deletions
|
@ -6,7 +6,7 @@ use std::time::Instant;
|
|||
use cgmath::{Deg, Matrix4, Point3, Rad, SquareMatrix, Vector3, perspective};
|
||||
use futures::executor::block_on;
|
||||
use thiserror::Error;
|
||||
use tracing::{error, info, trace};
|
||||
use tracing::{debug, error, info, trace};
|
||||
use wgpu::TextureUsages;
|
||||
use wgpu::{Backends, InstanceDescriptor, util::DeviceExt};
|
||||
use wgpu_text::glyph_brush::ab_glyph::FontRef;
|
||||
|
@ -333,7 +333,7 @@ struct FontState {
|
|||
impl<'window> Renderer<'window> {
|
||||
pub async fn new(window: Arc<Window>) -> Result<Self, RenderContextError> {
|
||||
let instance = wgpu::Instance::new(&InstanceDescriptor {
|
||||
backends: Backends::from_comma_list("dx12,metal,opengl,webgpu"),
|
||||
backends: Backends::from_comma_list("dx12,metal,opengl,webgpu,vulkan"),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
|
@ -458,23 +458,31 @@ impl<'window> Renderer<'window> {
|
|||
let camera = Camera::new(&device, &camera_bind_group_layout, width, height);
|
||||
|
||||
let surface_caps = surface.get_capabilities(&adapter);
|
||||
let present_mode = [
|
||||
wgpu::PresentMode::Immediate,
|
||||
wgpu::PresentMode::Mailbox,
|
||||
wgpu::PresentMode::AutoNoVsync,
|
||||
]
|
||||
.iter()
|
||||
.copied()
|
||||
.find(|mode| surface_caps.present_modes.contains(mode))
|
||||
.unwrap_or(wgpu::PresentMode::Fifo);
|
||||
|
||||
debug!("Using {:#?} present mode.", present_mode);
|
||||
|
||||
let surface_config = wgpu::SurfaceConfiguration {
|
||||
width,
|
||||
height,
|
||||
format: surface_caps.formats[0],
|
||||
present_mode: wgpu::PresentMode::AutoNoVsync,
|
||||
present_mode,
|
||||
alpha_mode: wgpu::CompositeAlphaMode::Auto,
|
||||
view_formats: vec![],
|
||||
usage: TextureUsages::RENDER_ATTACHMENT,
|
||||
desired_maximum_frame_latency: 3,
|
||||
};
|
||||
surface.configure(&device, &surface_config);
|
||||
let (depth_texture, depth_texture_view) = create_depth_texture(
|
||||
&device,
|
||||
surface_config.width,
|
||||
surface_config.height,
|
||||
// surface_config.format,
|
||||
);
|
||||
let (depth_texture, depth_texture_view) =
|
||||
create_depth_texture(&device, surface_config.width, surface_config.height);
|
||||
|
||||
let font_bytes = include_bytes!("DejaVuSans.ttf");
|
||||
let font = FontRef::try_from_slice(font_bytes).map_err(|e| {
|
||||
|
@ -706,7 +714,6 @@ fn create_depth_texture(
|
|||
device: &wgpu::Device,
|
||||
width: u32,
|
||||
height: u32,
|
||||
// format: wgpu::TextureFormat,
|
||||
) -> (wgpu::Texture, wgpu::TextureView) {
|
||||
let size = wgpu::Extent3d {
|
||||
width,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue