Skip to content

Commit

Permalink
fixup! Add example that switches the rendering thread
Browse files Browse the repository at this point in the history
  • Loading branch information
vially committed Dec 28, 2023
1 parent 0dc853c commit b496dce
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions glutin_examples/examples/switch_render_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let event_loop_proxy = event_loop.create_proxy();

let (_render_threads, render_thread_senders) =
spawn_render_threads(render_context, event_loop_proxy.clone());
spawn_render_threads(render_context, event_loop_proxy);

let mut app_state = AppState {
render_thread_senders,
Expand Down Expand Up @@ -134,21 +134,24 @@ impl RenderContext {
}

fn make_current(&mut self) -> Result<(), impl Error> {
let ctx = self.context.take().ok_or(GlutinError::from(ErrorKind::BadContextState))?;
let ctx =
self.context.take().ok_or_else(|| GlutinError::from(ErrorKind::BadContextState))?;
let result = ctx.make_current(&self.surface);
self.context = Some(ctx);
result
}

fn make_not_current(&mut self) -> Result<(), impl Error> {
let ctx = self.context.take().ok_or(GlutinError::from(ErrorKind::BadContextState))?;
let ctx =
self.context.take().ok_or_else(|| GlutinError::from(ErrorKind::BadContextState))?;
let not_current_ctx = ctx.make_not_current()?;
self.context = Some(not_current_ctx.treat_as_possibly_current());
Ok::<(), GlutinError>(())
}

fn swap_buffers(&mut self) -> Result<(), impl Error> {
let ctx = self.context.take().ok_or(GlutinError::from(ErrorKind::BadContextState))?;
let ctx =
self.context.take().ok_or_else(|| GlutinError::from(ErrorKind::BadContextState))?;
let result = self.surface.swap_buffers(&ctx);
self.context = Some(ctx);
result
Expand Down

0 comments on commit b496dce

Please sign in to comment.