Skip to content

Commit

Permalink
WGPU: Fix compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
dcvz committed Jul 2, 2023
1 parent 688b09a commit 720b67d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ fast3d-wgpu-renderer = { version = "0.2.0", optional = true }

[patch.crates-io]
glium = { git = "https://github.com/retrofoundry/glium", branch = "helix" }
fast3d = { git = "https://github.com/retrofoundry/fast3d-rs", rev = "cafe87f" } # remove once we have our glium fix upstreamed
fast3d-glium-renderer = { git = "https://github.com/retrofoundry/fast3d-rs", rev = "cafe87f" } # remove once we have our glium fix upstreamed
fast3d-wgpu-renderer = { git = "https://github.com/retrofoundry/fast3d-rs", rev = "cafe87f" } # remove once we have our glium fix upstreamed
fast3d = { git = "https://github.com/retrofoundry/fast3d-rs", rev = "b9add07" } # remove once we have our glium fix upstreamed
fast3d-glium-renderer = { git = "https://github.com/retrofoundry/fast3d-rs", rev = "b9add07" } # remove once we have our glium fix upstreamed
fast3d-wgpu-renderer = { git = "https://github.com/retrofoundry/fast3d-rs", rev = "b9add07" } # remove once we have our glium fix upstreamed
13 changes: 9 additions & 4 deletions src/gui/gui_glium.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ use std::{ffi::CStr, result::Result::Ok, time::Instant};
use winit::platform::run_return::EventLoopExtRunReturn;

use crate::gamepad::manager::GamepadManager;
use fast3d::output::RCPOutput;
use fast3d::rcp::RCP;
use fast3d::rdp::OutputDimensions;
use fast3d::{output::RCPOutput, rcp::RCP, rdp::OutputDimensions};

use fast3d_glium_renderer::glium_device::GliumGraphicsDevice;

Expand Down Expand Up @@ -248,7 +246,14 @@ impl<'a> Gui<'a> {
}

fn render_game(&mut self, target: &mut Frame) -> Result<()> {
for draw_call in &self.rcp_output.draw_calls {
// omit the last draw call, because we know we that's an extra from the last flush
// for draw_call in &self.rcp_output.draw_calls[..self.rcp_output.draw_calls.len() - 1] {
for draw_call in self
.rcp_output
.draw_calls
.iter()
.take(self.rcp_output.draw_calls.len() - 1)
{
assert!(!draw_call.vbo.vbo.is_empty());

self.graphics_device.set_cull_mode(draw_call.cull_mode);
Expand Down
47 changes: 21 additions & 26 deletions src/gui/gui_wgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ use std::{
};
use winit::{dpi::LogicalSize, platform::run_return::EventLoopExtRunReturn};

use crate::fast3d::rcp::RCP;
use crate::fast3d::rdp::OutputDimensions;
use crate::{fast3d::graphics::GraphicsIntermediateDevice, gamepad::manager::GamepadManager};
use crate::gamepad::manager::GamepadManager;
use fast3d::{output::RCPOutput, rcp::RCP, rdp::OutputDimensions};

use super::renderer::wgpu_device::WgpuGraphicsDevice;
use fast3d_wgpu_renderer::wgpu_device::WgpuGraphicsDevice;

pub struct Gui<'a> {
// window
Expand Down Expand Up @@ -50,7 +49,7 @@ pub struct Gui<'a> {

// game renderer
rcp: RCP,
pub intermediate_graphics_device: GraphicsIntermediateDevice,
pub rcp_output: RCPOutput,
graphics_device: WgpuGraphicsDevice,
}

Expand Down Expand Up @@ -188,7 +187,7 @@ impl<'a> Gui<'a> {
draw_windows_callback: Box::new(draw_windows),
gamepad_manager,
rcp: RCP::default(),
intermediate_graphics_device: GraphicsIntermediateDevice::default(),
rcp_output: RCPOutput::default(),
graphics_device,
})
}
Expand Down Expand Up @@ -253,15 +252,21 @@ impl<'a> Gui<'a> {
}

fn sync_frame_rate(&mut self) {
// TODO: Fix off by one error & test other OSes
const FRAME_INTERVAL_MS: u64 = 1000 / (30 + 1) as u64;
const FRAME_INTERVAL_MS: u64 = 1000 / 30;

let frame_duration = self.ui_state.last_frame_time.elapsed();

if frame_duration < Duration::from_millis(FRAME_INTERVAL_MS) {
let sleep_duration = Duration::from_millis(FRAME_INTERVAL_MS) - frame_duration;
spin_sleep::sleep(sleep_duration);
}

let now = Instant::now();

self.imgui
.io_mut()
.update_delta_time(now - self.ui_state.last_frame_time);

self.ui_state.last_frame_time = now;
}

pub fn start_frame(
Expand All @@ -271,13 +276,6 @@ impl<'a> Gui<'a> {
// Handle events
self.handle_events(event_loop_wrapper);

// Update delta time
let now = Instant::now();
self.imgui
.io_mut()
.update_delta_time(now - self.ui_state.last_frame_time);
self.ui_state.last_frame_time = now;

// Start the frame
let frame = match self.surface.get_current_texture() {
Ok(frame) => frame,
Expand Down Expand Up @@ -326,8 +324,7 @@ impl<'a> Gui<'a> {
self.graphics_device.update_frame_count();

// Run the RCP
self.rcp
.run(&mut self.intermediate_graphics_device, commands);
self.rcp.run(&mut self.rcp_output, commands);

// Setup encoder that the RDP will use
let mut encoder: wgpu::CommandEncoder =
Expand All @@ -337,10 +334,12 @@ impl<'a> Gui<'a> {
});

// Draw the RCP output
// omit the last draw call, because we know we that's an extra from the last flush
for (index, draw_call) in self
.intermediate_graphics_device
.rcp_output
.draw_calls
.iter()
.take(self.rcp_output.draw_calls.len() - 1)
.enumerate()
{
assert!(!draw_call.vbo.vbo.is_empty());
Expand All @@ -358,13 +357,9 @@ impl<'a> Gui<'a> {
);

// loop through textures and bind them
for (index, hash) in draw_call.textures.iter().enumerate() {
for (index, hash) in draw_call.texture_indices.iter().enumerate() {
if let Some(hash) = hash {
let texture = self
.intermediate_graphics_device
.texture_cache
.get_mut(*hash)
.unwrap();
let texture = self.rcp_output.texture_cache.get_mut(*hash).unwrap();
self.graphics_device.bind_texture(
&self.device,
&self.queue,
Expand Down Expand Up @@ -419,7 +414,7 @@ impl<'a> Gui<'a> {
(self.draw_windows_callback)(ui);

// Reset state
self.intermediate_graphics_device.clear_draw_calls();
self.rcp_output.clear_draw_calls();

// Finish game encoding and submit
self.queue.submit(Some(encoder.finish()));
Expand Down

0 comments on commit 720b67d

Please sign in to comment.