Skip to content

Commit

Permalink
Add Device
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Sep 27, 2023
1 parent c283730 commit e7079eb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
5 changes: 5 additions & 0 deletions crates/fj-viewer/src/graphics/device.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[derive(Debug)]
pub struct Device {
pub device: wgpu::Device,
pub queue: wgpu::Queue,
}
1 change: 1 addition & 0 deletions crates/fj-viewer/src/graphics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Rendering primitives, routines, and structures.
mod device;
mod draw_config;
mod drawables;
mod geometries;
Expand Down
39 changes: 21 additions & 18 deletions crates/fj-viewer/src/graphics/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ use crate::{
};

use super::{
draw_config::DrawConfig, drawables::Drawables, geometries::Geometries,
navigation_cube::NavigationCubeRenderer, pipelines::Pipelines,
transform::Transform, uniforms::Uniforms, vertices::Vertices, DEPTH_FORMAT,
SAMPLE_COUNT,
device::Device, draw_config::DrawConfig, drawables::Drawables,
geometries::Geometries, navigation_cube::NavigationCubeRenderer,
pipelines::Pipelines, transform::Transform, uniforms::Uniforms,
vertices::Vertices, DEPTH_FORMAT, SAMPLE_COUNT,
};

/// Graphics rendering state and target abstraction
#[derive(Debug)]
pub struct Renderer {
surface: wgpu::Surface,
device: wgpu::Device,
queue: wgpu::Queue,
device: Device,

surface_config: wgpu::SurfaceConfiguration,
frame_buffer: wgpu::TextureView,
Expand Down Expand Up @@ -198,8 +197,7 @@ impl Renderer {

Ok(Self {
surface,
device,
queue,
device: Device { device, queue },

surface_config,
frame_buffer,
Expand All @@ -217,7 +215,7 @@ impl Renderer {

/// Updates the geometry of the model being rendered.
pub fn update_geometry(&mut self, mesh: Vertices) {
self.geometries = Geometries::new(&self.device, &mesh);
self.geometries = Geometries::new(&self.device.device, &mesh);
}

/// Resizes the render surface.
Expand All @@ -228,12 +226,17 @@ impl Renderer {
self.surface_config.width = size.width;
self.surface_config.height = size.height;

self.surface.configure(&self.device, &self.surface_config);
self.surface
.configure(&self.device.device, &self.surface_config);

self.frame_buffer =
Self::create_frame_buffer(&self.device, &self.surface_config);
self.depth_view =
Self::create_depth_buffer(&self.device, &self.surface_config);
self.frame_buffer = Self::create_frame_buffer(
&self.device.device,
&self.surface_config,
);
self.depth_view = Self::create_depth_buffer(
&self.device.device,
&self.surface_config,
);
}

/// Draws the renderer, camera, and config state to the window.
Expand All @@ -249,7 +252,7 @@ impl Renderer {
transform_normals: Transform::for_normals(camera),
};

self.queue.write_buffer(
self.device.queue.write_buffer(
&self.uniform_buffer,
0,
bytemuck::cast_slice(&[uniforms]),
Expand All @@ -273,7 +276,7 @@ impl Renderer {
.texture
.create_view(&wgpu::TextureViewDescriptor::default());

let mut encoder = self.device.create_command_encoder(
let mut encoder = self.device.device.create_command_encoder(
&wgpu::CommandEncoderDescriptor { label: None },
);

Expand Down Expand Up @@ -323,13 +326,13 @@ impl Renderer {
self.navigation_cube_renderer.draw(
&color_view,
&mut encoder,
&self.queue,
&self.device.queue,
aspect_ratio,
camera.rotation,
);

let command_buffer = encoder.finish();
self.queue.submit(Some(command_buffer));
self.device.queue.submit(Some(command_buffer));

trace!("Presenting...");
surface_texture.present();
Expand Down

0 comments on commit e7079eb

Please sign in to comment.