Skip to content

Commit a348366

Browse files
committed
fix(client_core): 🐛 Fix rendering C API
1 parent 3a060d3 commit a348366

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

alvr/client_core/src/c_api.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ pub extern "C" fn alvr_poll_event(out_event: *mut AlvrEvent) -> bool {
382382
}
383383
}
384384

385-
// Returns the length of the message. message_buffer can be null.
385+
/// Returns the length of the message. message_buffer can be null.
386386
#[no_mangle]
387387
pub extern "C" fn alvr_hud_message(message_buffer: *mut c_char) -> u64 {
388388
let cstring = CString::new(HUD_MESSAGE.lock().clone()).unwrap();
@@ -705,9 +705,14 @@ pub struct AlvrStreamConfig {
705705

706706
#[no_mangle]
707707
pub extern "C" fn alvr_initialize_opengl() {
708-
GRAPHICS_CONTEXT.set(Some(Rc::new(GraphicsContext::new_gl())));
708+
let context = GraphicsContext::new_gl();
709+
context.make_current();
710+
711+
GRAPHICS_CONTEXT.set(Some(Rc::new(context)));
709712
}
710713

714+
/// The GL context might be invalid after this function! Destroy any GL resources before calling
715+
/// this.
711716
#[no_mangle]
712717
pub extern "C" fn alvr_destroy_opengl() {
713718
GRAPHICS_CONTEXT.set(None);
@@ -747,12 +752,16 @@ pub unsafe extern "C" fn alvr_resume_opengl(
747752
convert_swapchain_array(swapchain_textures, swapchain_length),
748753
"",
749754
)));
755+
756+
GRAPHICS_CONTEXT.with_borrow(|c| c.as_ref().unwrap().make_current());
750757
}
751758

752759
#[no_mangle]
753760
pub extern "C" fn alvr_pause_opengl() {
754761
STREAM_RENDERER.set(None);
755-
LOBBY_RENDERER.set(None)
762+
LOBBY_RENDERER.set(None);
763+
764+
GRAPHICS_CONTEXT.with_borrow(|c| c.as_ref().unwrap().make_current());
756765
}
757766

758767
#[no_mangle]
@@ -762,6 +771,8 @@ pub unsafe extern "C" fn alvr_update_hud_message_opengl(message: *const c_char)
762771
renderer.update_hud_message(CStr::from_ptr(message).to_str().unwrap());
763772
}
764773
});
774+
775+
GRAPHICS_CONTEXT.with_borrow(|c| c.as_ref().unwrap().make_current());
765776
}
766777

767778
#[no_mangle]
@@ -790,6 +801,8 @@ pub unsafe extern "C" fn alvr_start_stream_opengl(config: AlvrStreamConfig) {
790801
1.0, // TODO: encoding gamma config
791802
None, // TODO: passthrough config
792803
)));
804+
805+
GRAPHICS_CONTEXT.with_borrow(|c| c.as_ref().unwrap().make_current());
793806
}
794807

795808
// todo: support hands
@@ -821,6 +834,8 @@ pub unsafe extern "C" fn alvr_render_lobby_opengl(
821834
);
822835
}
823836
});
837+
838+
GRAPHICS_CONTEXT.with_borrow(|c| c.as_ref().unwrap().make_current());
824839
}
825840

826841
/// view_params: array of 2
@@ -850,6 +865,8 @@ pub unsafe extern "C" fn alvr_render_stream_opengl(
850865
);
851866
}
852867
});
868+
869+
GRAPHICS_CONTEXT.with_borrow(|c| c.as_ref().unwrap().make_current());
853870
}
854871

855872
// Decoder-related interface
@@ -967,7 +984,7 @@ pub extern "C" fn alvr_destroy_decoder() {
967984
*DECODER_SOURCE.lock() = None;
968985
}
969986

970-
// Returns true if the timestamp and buffer has been written to
987+
/// Returns true if the timestamp and buffer has been written to
971988
#[no_mangle]
972989
pub extern "C" fn alvr_get_frame(
973990
out_timestamp_ns: *mut u64,

0 commit comments

Comments
 (0)