From 158dc2c438d82e68bbfdaf4cad035d5bd8573c03 Mon Sep 17 00:00:00 2001 From: Gabriel Bourgeois Date: Tue, 13 Sep 2022 20:03:16 -0400 Subject: [PATCH] Add UI viewport tests to split_screen example This example shows that only the UI on the highest priority camera will ever render. Looking at output, you can clearly see that the draw calls are happening. --- examples/3d/split_screen.rs | 45 +++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/examples/3d/split_screen.rs b/examples/3d/split_screen.rs index 7724280840e49..92f6db4b92a9d 100644 --- a/examples/3d/split_screen.rs +++ b/examples/3d/split_screen.rs @@ -47,15 +47,28 @@ fn setup( }); // Left Camera - commands + // BUG: UI viewports seem to clear or prevent each other from drawing so this doesn't render at all. + // Changing this to 2 will still display it but then the right UI will not display anymore! + let left_camera = commands .spawn_bundle(Camera3dBundle { transform: Transform::from_xyz(0.0, 200.0, -100.0).looking_at(Vec3::ZERO, Vec3::Y), + camera: Camera { + // Renders the left camera before the right camera, which has a priority of one. + priority: 0, + ..default() + }, + camera_3d: Camera3d { + // To allow testing priority change, don't clear at all. + clear_color: ClearColorConfig::None, + ..default() + }, ..default() }) - .insert(LeftCamera); + .insert(LeftCamera) + .id(); // Right Camera - commands + let right_camera = commands .spawn_bundle(Camera3dBundle { transform: Transform::from_xyz(100.0, 100., 150.0).looking_at(Vec3::ZERO, Vec3::Y), camera: Camera { @@ -70,7 +83,31 @@ fn setup( }, ..default() }) - .insert(RightCamera); + .insert(RightCamera) + .id(); + + // Text to be rendered on the left camera + commands.spawn_bundle(TextBundle::from_section( + "Left camera", + TextStyle { + font: asset_server.load("fonts/FiraSans-Bold.ttf"), + font_size: 40.0, + color: Color::BLUE, + }, + )) + .insert(UiRootCamera(left_camera)); + + // Text to be rendered on the right camera + commands.spawn_bundle( + TextBundle::from_section( + "Right camera", + TextStyle { + font: asset_server.load("fonts/FiraSans-Bold.ttf"), + font_size: 40.0, + color: Color::GREEN, + }, + )) + .insert(UiRootCamera(right_camera)); } #[derive(Component)]