Skip to content

Commit

Permalink
Add primary window methods
Browse files Browse the repository at this point in the history
  • Loading branch information
hakolao committed Feb 2, 2022
1 parent d4aa700 commit 0b6549a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
14 changes: 4 additions & 10 deletions examples/circle/render_system_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ impl Plugin for MainRenderPlugin {

/// Insert our render pass at startup
fn insert_render_pass_system(mut commands: Commands, vulkano_windows: Res<VulkanoWindows>) {
let vulkano_window = vulkano_windows
.get_window_renderer(WindowId::primary())
.unwrap();
let vulkano_window = vulkano_windows.get_primary_window_renderer().unwrap();
let queue = vulkano_window.graphics_queue();
let format = vulkano_window.swapchain_format();
let deferred_pass = RenderPassDeferred::new(queue, format).unwrap();
Expand Down Expand Up @@ -132,7 +130,7 @@ pub fn main_render_system(
mut render_pass_deferred: ResMut<RenderPassDeferred>,
) {
let mut frame_data = pipeline_frame_data.get_mut(WindowId::primary()).unwrap();
if let Some(vulkano_window) = vulkano_windows.get_window_renderer_mut(WindowId::primary()) {
if let Some(vulkano_window) = vulkano_windows.get_primary_window_renderer_mut() {
// We take the before pipeline future leaving None in its place
if let Some(before_future) = frame_data.before.take() {
let final_image_view = vulkano_window.final_image();
Expand Down Expand Up @@ -167,18 +165,14 @@ pub fn main_render_system(

#[cfg(feature = "example_has_gui")]
fn set_gui_styles_system(vulkano_windows: Res<VulkanoWindows>) {
let primary_window = vulkano_windows
.get_window_renderer(WindowId::primary())
.unwrap();
let primary_window = vulkano_windows.get_primary_window_renderer().unwrap();
let _ctx = primary_window.gui_context();
// Set styles here... for primary window
}

#[cfg(feature = "example_has_gui")]
fn main_gui_system(vulkano_windows: Res<VulkanoWindows>, diagnostics: Res<Diagnostics>) {
let primary_window = vulkano_windows
.get_window_renderer(WindowId::primary())
.unwrap();
let primary_window = vulkano_windows.get_primary_window_renderer().unwrap();
let ctx = primary_window.gui_context();
egui::Area::new("fps")
.fixed_pos(egui::pos2(10.0, 10.0))
Expand Down
8 changes: 2 additions & 6 deletions examples/game_of_life/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ fn update_window_title_system(vulkano_windows: Res<VulkanoWindows>, time: ResMut

/// Creates our simulation pipeline & render pipeline
fn create_pipelines(mut commands: Commands, vulkano_windows: Res<VulkanoWindows>) {
let primary_window = vulkano_windows
.get_window_renderer(WindowId::primary())
.unwrap();
let primary_window = vulkano_windows.get_primary_window_renderer().unwrap();
// Create compute pipeline to simulate game of life
let game_of_life_pipeline =
GameOfLifeComputePipeline::new(primary_window.graphics_queue(), [512, 512]);
Expand Down Expand Up @@ -119,9 +117,7 @@ fn game_of_life_pipeline_system(
mut game_of_life: ResMut<GameOfLifeComputePipeline>,
mut place_over_frame: ResMut<RenderPassPlaceOverFrame>,
) {
let primary_window = vulkano_windows
.get_window_renderer_mut(WindowId::primary())
.unwrap();
let primary_window = vulkano_windows.get_primary_window_renderer_mut().unwrap();

// Start frame
let before = match primary_window.start_frame() {
Expand Down
4 changes: 1 addition & 3 deletions examples/multi_window_gui/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ fn create_new_window_on_space_system(

#[cfg(feature = "example_has_gui")]
pub fn main_render_system_primary_window(mut vulkano_windows: ResMut<VulkanoWindows>) {
let vulkano_window = vulkano_windows
.get_window_renderer_mut(WindowId::primary())
.unwrap();
let vulkano_window = vulkano_windows.get_primary_window_renderer_mut().unwrap();
// Start Frame
let before = match vulkano_window.start_frame() {
Err(e) => {
Expand Down
12 changes: 12 additions & 0 deletions src/vulkano_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ impl VulkanoWindows {
)
}

pub fn get_primary_window_renderer_mut(&mut self) -> Option<&mut VulkanoWindowRenderer> {
self.get_window_renderer_mut(WindowId::primary())
}

pub fn get_primary_window_renderer(&self) -> Option<&VulkanoWindowRenderer> {
self.get_window_renderer(WindowId::primary())
}

pub fn get_primary_winit_window(&self) -> Option<&winit::window::Window> {
self.get_winit_window(WindowId::primary())
}

pub fn get_window_renderer_mut(&mut self, id: WindowId) -> Option<&mut VulkanoWindowRenderer> {
self.window_id_to_winit
.get(&id)
Expand Down

0 comments on commit 0b6549a

Please sign in to comment.