Skip to content

Commit b2ad130

Browse files
committed
Handled resizing by emittig WindowResized
1 parent ac28b29 commit b2ad130

3 files changed

Lines changed: 18 additions & 14 deletions

File tree

crates/processing_glfw/src/lib.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,8 @@ impl GlfwContext {
301301
input_set_focus(surface, focused).unwrap();
302302
}
303303
WindowEvent::Size(width, height) => {
304-
processing_render::surface_resize(
305-
surface,
306-
width.max(1) as u32,
307-
height.max(1) as u32,
308-
)
309-
.unwrap();
304+
processing_render::surface_resize(surface, width as u32, height as u32)
305+
.unwrap();
310306
}
311307
_ => {}
312308
}

crates/processing_render/src/graphics.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use bevy::{
2222
sync_world::MainEntity,
2323
view::ViewTarget,
2424
},
25-
window::WindowRef,
25+
window::{WindowRef, WindowResized},
2626
};
2727

2828
use crate::{
@@ -260,6 +260,7 @@ pub fn sync_to_surface(
260260
mut graphics_query: Query<(&mut Graphics, &RenderTarget)>,
261261
windows: Query<&Window, (With<Surface>, Changed<Window>)>,
262262
render_device: Res<RenderDevice>,
263+
mut resize_messages: MessageWriter<WindowResized>,
263264
) {
264265
for (mut graphics, target) in graphics_query.iter_mut() {
265266
let RenderTarget::Window(WindowRef::Entity(surface_entity)) = *target else {
@@ -273,6 +274,12 @@ pub fn sync_to_surface(
273274
if graphics.size.width == physical_w && graphics.size.height == physical_h {
274275
continue;
275276
}
277+
//winit plugin disabled, so WindowResized is never triggered automatically
278+
resize_messages.write(WindowResized {
279+
window: surface_entity,
280+
width: window.width(),
281+
height: window.height(),
282+
});
276283
graphics.size = Extent3d {
277284
width: physical_w,
278285
height: physical_h,

crates/processing_render/src/surface.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use bevy::{
2222
app::{App, Plugin},
2323
asset::Assets,
24-
camera::{Projection, RenderTarget},
24+
camera::RenderTarget,
2525
ecs::query::QueryEntityError,
2626
math::{IRect, IVec2},
2727
prelude::{Commands, Component, Entity, In, Query, ResMut, Window, With, default},
@@ -395,8 +395,11 @@ pub fn destroy(
395395
pub fn resize(
396396
In((window_entity, width, height)): In<(Entity, u32, u32)>,
397397
mut windows: Query<&mut Window>,
398-
mut graphics_query: Query<(&RenderTarget, &mut SurfaceSize, &mut Projection)>,
398+
mut graphics_query: Query<(&RenderTarget, &mut SurfaceSize)>,
399399
) -> Result<()> {
400+
let width = width.max(1);
401+
let height = height.max(1);
402+
400403
if let Ok(mut window) = windows.get_mut(window_entity) {
401404
let scale = window.resolution.scale_factor();
402405
let physical_w = (width as f32 * scale) as u32;
@@ -405,14 +408,12 @@ pub fn resize(
405408
.resolution
406409
.set_physical_resolution(physical_w, physical_h);
407410
}
408-
409-
for (target, mut surface_size, mut projection) in graphics_query.iter_mut() {
411+
412+
// SurfaceSize changes on resize, if not handled will break APIs dependent on correct SurfaceSize
413+
for (target, mut surface_size) in graphics_query.iter_mut() {
410414
if let RenderTarget::Window(WindowRef::Entity(surface)) = *target {
411415
if surface == window_entity {
412416
*surface_size = SurfaceSize(width, height);
413-
if let Projection::Custom(ref mut custom) = *projection {
414-
custom.update(width as f32, height as f32);
415-
}
416417
}
417418
}
418419
}

0 commit comments

Comments
 (0)