Skip to content

Commit

Permalink
Merge pull request #1587 from hannobraun/update
Browse files Browse the repository at this point in the history
Upgrade to latest wgpu, winit, egui
  • Loading branch information
hannobraun authored Feb 14, 2023
2 parents 107a0c3 + 925ed83 commit f835ba0
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 547 deletions.
758 changes: 231 additions & 527 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/fj-host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ libloading = "0.7.4"
notify = "5.1.0"
thiserror = "1.0.35"
tracing = "0.1.37"
winit = "0.27.5"
winit = "0.28.1"
7 changes: 3 additions & 4 deletions crates/fj-viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ categories.workspace = true
bytemuck = "1.13.0"
chrono = "0.4.23"
crossbeam-channel = "0.5.6"
egui = "0.20.1"
egui-wgpu = "0.20.0"
egui = "0.21.0"
egui-wgpu = "0.21.0"
fj-interop.workspace = true
fj-math.workspace = true
nalgebra = "0.32.1"
tobj = "3.2.4"
raw-window-handle = "0.5.0"
thiserror = "1.0.35"
tracing = "0.1.37"
wgpu_glyph = "0.18.0"

[dependencies.image]
version = "0.24"
Expand All @@ -36,7 +35,7 @@ default_features = false
features = ["xdg-portal"]

[dependencies.wgpu]
version = "0.14.2"
version = "0.15.1"
features = ["webgl"]

# We don't depend on `getrandom` directly, but we need this to enable the `js`
Expand Down
26 changes: 15 additions & 11 deletions crates/fj-viewer/src/graphics/renderer.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::{io, mem::size_of};
use std::{io, mem::size_of, vec};

use thiserror::Error;
use tracing::debug;
use wgpu::util::DeviceExt as _;
use wgpu_glyph::ab_glyph::InvalidFont;

use crate::{
camera::Camera,
Expand Down Expand Up @@ -42,10 +41,13 @@ pub struct Renderer {
impl Renderer {
/// Returns a new `Renderer`.
pub async fn new(screen: &impl Screen) -> Result<Self, RendererInitError> {
let instance = wgpu::Instance::new(wgpu::Backends::PRIMARY);
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends: wgpu::Backends::PRIMARY,
..Default::default()
});

// This is sound, as `window` is an object to create a surface upon.
let surface = unsafe { instance.create_surface(screen.window()) };
let surface = unsafe { instance.create_surface(screen.window()) }?;

let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
Expand Down Expand Up @@ -95,7 +97,8 @@ impl Renderer {
.await?;

let color_format = 'color_format: {
let supported_formats = surface.get_supported_formats(&adapter);
let capabilities = surface.get_capabilities(&adapter);
let supported_formats = capabilities.formats;

// We don't really care which color format we use, as long as we
// find one that's supported. `egui_wgpu` prints a warning though,
Expand Down Expand Up @@ -137,6 +140,7 @@ impl Renderer {
//
// @hannobraun
alpha_mode: wgpu::CompositeAlphaMode::Auto,
view_formats: vec![],
};
surface.configure(&device, &surface_config);

Expand Down Expand Up @@ -373,6 +377,7 @@ impl Renderer {
dimension: wgpu::TextureDimension::D2,
format: surface_config.format,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
view_formats: &[],
});
texture.create_view(&wgpu::TextureViewDescriptor::default())
}
Expand All @@ -393,6 +398,7 @@ impl Renderer {
dimension: wgpu::TextureDimension::D2,
format: DEPTH_FORMAT,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
view_formats: &[],
});

texture.create_view(&wgpu::TextureViewDescriptor::default())
Expand All @@ -411,6 +417,10 @@ pub enum RendererInitError {
#[error("I/O error: {0}")]
Io(#[from] io::Error),

/// Surface creating error
#[error("Error creating surface: {0}")]
CreateSurface(#[from] wgpu::CreateSurfaceError),

/// Graphics accelerator acquisition error
#[error("Error request adapter")]
RequestAdapter,
Expand All @@ -420,12 +430,6 @@ pub enum RendererInitError {
/// See: [wgpu::RequestDeviceError](https://docs.rs/wgpu/latest/wgpu/struct.RequestDeviceError.html)
#[error("Error requesting device: {0}")]
RequestDevice(#[from] wgpu::RequestDeviceError),

/// Error loading font
///
/// See: [ab_glyph::InvalidFont](https://docs.rs/ab_glyph/latest/ab_glyph/struct.InvalidFont.html)
#[error("Error loading font: {0}")]
InvalidFont(#[from] InvalidFont),
}

/// Graphics rendering error
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-viewer/src/graphics/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn vertex(in: VertexInput) -> VertexOutput {
return out;
}

let pi: f32 = 3.14159265359;
const pi: f32 = 3.14159265359;

@fragment
fn frag_model(in: VertexOutput) -> FragmentOutput {
Expand Down
1 change: 1 addition & 0 deletions crates/fj-viewer/src/graphics/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl Texture {
format: wgpu::TextureFormat::Rgba8UnormSrgb,
usage: wgpu::TextureUsages::TEXTURE_BINDING
| wgpu::TextureUsages::COPY_DST,
view_formats: &[],
});

queue.write_texture(
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-viewer/src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl Gui {
&& self.options.show_debug_text_example
{
let hover_pos =
ui.input().pointer.hover_pos().unwrap_or_default();
ui.input(|input| input.pointer.hover_pos().unwrap_or_default());
ui.painter().debug_text(
hover_pos,
egui::Align2::LEFT_TOP,
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-window/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ crossbeam-channel = "0.5.6"
futures = "0.3.26"
thiserror = "1.0.35"
tracing = "0.1.37"
winit = "0.27.5"
winit = "0.28.1"

[dependencies.egui-winit]
version = "0.20.1"
version = "0.21.1"
default-features = false

0 comments on commit f835ba0

Please sign in to comment.