summaryrefslogtreecommitdiff
path: root/alligator_render/src
diff options
context:
space:
mode:
authorMicha White <botahamec@outlook.com>2023-02-04 11:01:14 -0500
committerMicha White <botahamec@outlook.com>2023-02-04 11:01:14 -0500
commit455dd59b2c9c10b456a133302528775385e75810 (patch)
tree234558685105121b3748df1612d57f89ea74f25f /alligator_render/src
parent17662181dd3947c7e38f60116cd57e88a2a2897d (diff)
Upgrade to wgpu 0.15
Diffstat (limited to 'alligator_render/src')
-rw-r--r--alligator_render/src/renderer.rs40
-rw-r--r--alligator_render/src/texture.rs1
2 files changed, 31 insertions, 10 deletions
diff --git a/alligator_render/src/renderer.rs b/alligator_render/src/renderer.rs
index 69035ae..98c772a 100644
--- a/alligator_render/src/renderer.rs
+++ b/alligator_render/src/renderer.rs
@@ -29,11 +29,28 @@ impl NoGpuError {
}
}
+/// No device could be found which supports the given surface
+#[derive(Clone, Copy, Debug, Error)]
+#[error("A WebGPU or WebGL context could not be obtained")]
+pub struct NoWebContextError {
+ /// Prevents this type from being constructed
+ _priv: (),
+}
+
+impl NoWebContextError {
+ /// Create a new error
+ const fn new() -> Self {
+ Self { _priv: () }
+ }
+}
+
#[derive(Debug, Error)]
pub enum NewRendererError {
#[error(transparent)]
NoGpu(#[from] NoGpuError),
#[error(transparent)]
+ NoWebContext(#[from] NoWebContextError),
+ #[error(transparent)]
// TODO better error
WindowInitError(#[from] OsError),
}
@@ -72,7 +89,7 @@ fn get_adapter(
let adapter = adapter.or_else(|| {
instance
.enumerate_adapters(wgpu::Backends::PRIMARY)
- .find(|adapter| !surface.get_supported_formats(adapter).is_empty())
+ .find(|adapter| !surface.get_capabilities(adapter).formats.is_empty())
});
adapter.ok_or(NoGpuError::new())
@@ -136,10 +153,14 @@ impl Renderer {
let event_loop = Some(event_loop);
// the instance's main purpose is to create an adapter and a surface
- let instance = wgpu::Instance::new(wgpu::Backends::VULKAN);
+ let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
+ backends: wgpu::Backends::VULKAN,
+ dx12_shader_compiler: wgpu::Dx12Compiler::Fxc, // TODO support DXC
+ });
// the surface is the part of the screen we'll draw to
- let surface = unsafe { instance.create_surface(&window) };
+ let surface =
+ unsafe { instance.create_surface(&window) }.map_err(|_| NoWebContextError::new())?;
let power_preference = config.power_preference();
@@ -160,16 +181,13 @@ impl Renderer {
.expect("there was no device with the selected features");
// configuration for the surface
- let supported_present_modes = surface
- .get_supported_present_modes(&adapter)
- .into_boxed_slice();
- let supported_alpha_modes = surface
- .get_supported_alpha_modes(&adapter)
- .into_boxed_slice();
+ let capabilities = surface.get_capabilities(&adapter);
+ let supported_present_modes = capabilities.present_modes.into_boxed_slice();
+ let supported_alpha_modes = capabilities.alpha_modes.into_boxed_slice();
let surface_config = config.to_surface_configuration(
&supported_present_modes,
&supported_alpha_modes,
- surface.get_supported_formats(&adapter)[0],
+ capabilities.formats[0],
);
surface.configure(&device, &surface_config);
@@ -301,6 +319,7 @@ impl Renderer {
/// A number of problems could occur here. A timeout could occur while
/// trying to acquire the next frame. There may also be no more memory left
/// that can be used for the new frame.
+ // TODO this needs to be smaller
#[profiling::function]
fn render(&mut self) -> Result<(), wgpu::SurfaceError> {
// this will allow us to send commands to the gpu
@@ -368,6 +387,7 @@ impl Renderer {
}
/// Run the renderer indefinitely
+ // TODO this needs to be smaller
pub fn run<F: FnMut(&mut Self) + 'static>(mut self, mut f: F) -> ! {
self.window.set_visible(true);
let event_loop = self.event_loop();
diff --git a/alligator_render/src/texture.rs b/alligator_render/src/texture.rs
index 9f222e6..e2021f8 100644
--- a/alligator_render/src/texture.rs
+++ b/alligator_render/src/texture.rs
@@ -118,6 +118,7 @@ impl TextureAtlas {
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8UnormSrgb,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
+ view_formats: &[wgpu::TextureFormat::Rgba8UnormSrgb],
});
// TODO I don't think this refreshes anything