Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect present_mode when creating the Pixels instance #20

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use crate::prelude::*;
use bevy::diagnostic::Diagnostics;
use bevy::{
prelude::*,
window::{RawHandleWrapper, WindowBackendScaleFactorChanged, WindowResized},
window::{PresentMode, RawHandleWrapper, WindowBackendScaleFactorChanged, WindowResized},
winit::WinitWindows,
};
use pixels::{Pixels, SurfaceTexture};
use pixels::{PixelsBuilder, SurfaceTexture};
#[cfg(target_arch = "wasm32")]
use pollster::FutureExt as _;
#[cfg(feature = "render")]
Expand All @@ -23,10 +23,13 @@ use std::time::Instant;
#[allow(clippy::type_complexity)]
pub fn create_pixels(
mut commands: Commands,
query: Query<(Entity, &PixelsOptions), (With<RawHandleWrapper>, Without<PixelsWrapper>)>,
query: Query<
(Entity, &PixelsOptions, &Window),
(With<RawHandleWrapper>, Without<PixelsWrapper>),
>,
winit_windows: NonSend<WinitWindows>,
) {
for (entity, options) in &query {
for (entity, options, window) in &query {
let winit_window = winit_windows
.get_window(entity)
.expect("failed to get winit window");
Expand All @@ -36,14 +39,24 @@ pub fn create_pixels(
SurfaceTexture::new(window_size.width, window_size.height, winit_window);

let pixels = {
let builder = PixelsBuilder::new(options.width, options.height, surface_texture)
.present_mode(match window.present_mode {
PresentMode::Fifo => pixels::wgpu::PresentMode::Fifo,
PresentMode::FifoRelaxed => pixels::wgpu::PresentMode::FifoRelaxed,
PresentMode::Mailbox => pixels::wgpu::PresentMode::Mailbox,
PresentMode::Immediate => pixels::wgpu::PresentMode::Immediate,
PresentMode::AutoVsync => pixels::wgpu::PresentMode::AutoVsync,
PresentMode::AutoNoVsync => pixels::wgpu::PresentMode::AutoNoVsync,
});

#[cfg(not(target_arch = "wasm32"))]
{
Pixels::new(options.width, options.height, surface_texture)
builder.build()
}
#[cfg(target_arch = "wasm32")]
{
// TODO: Find a way to asynchronously load pixels on web.
Pixels::new_async(options.width, options.height, surface_texture).block_on()
builder.build_async().block_on()
}
}
.expect("failed to create pixels");
Expand Down