@@ -382,7 +382,7 @@ pub extern "C" fn alvr_poll_event(out_event: *mut AlvrEvent) -> bool {
382
382
}
383
383
}
384
384
385
- // Returns the length of the message. message_buffer can be null.
385
+ /// Returns the length of the message. message_buffer can be null.
386
386
#[ no_mangle]
387
387
pub extern "C" fn alvr_hud_message ( message_buffer : * mut c_char ) -> u64 {
388
388
let cstring = CString :: new ( HUD_MESSAGE . lock ( ) . clone ( ) ) . unwrap ( ) ;
@@ -705,9 +705,14 @@ pub struct AlvrStreamConfig {
705
705
706
706
#[ no_mangle]
707
707
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) ) ) ;
709
712
}
710
713
714
+ /// The GL context might be invalid after this function! Destroy any GL resources before calling
715
+ /// this.
711
716
#[ no_mangle]
712
717
pub extern "C" fn alvr_destroy_opengl ( ) {
713
718
GRAPHICS_CONTEXT . set ( None ) ;
@@ -747,12 +752,24 @@ pub unsafe extern "C" fn alvr_resume_opengl(
747
752
convert_swapchain_array ( swapchain_textures, swapchain_length) ,
748
753
"" ,
749
754
) ) ) ;
755
+
756
+ GRAPHICS_CONTEXT . with_borrow ( |context| {
757
+ if let Some ( ctx) = context {
758
+ ctx. make_current ( ) ;
759
+ }
760
+ } ) ;
750
761
}
751
762
752
763
#[ no_mangle]
753
764
pub extern "C" fn alvr_pause_opengl ( ) {
754
765
STREAM_RENDERER . set ( None ) ;
755
- LOBBY_RENDERER . set ( None )
766
+ LOBBY_RENDERER . set ( None ) ;
767
+
768
+ GRAPHICS_CONTEXT . with_borrow ( |context| {
769
+ if let Some ( ctx) = context {
770
+ ctx. make_current ( ) ;
771
+ }
772
+ } ) ;
756
773
}
757
774
758
775
#[ no_mangle]
@@ -762,6 +779,12 @@ pub unsafe extern "C" fn alvr_update_hud_message_opengl(message: *const c_char)
762
779
renderer. update_hud_message ( CStr :: from_ptr ( message) . to_str ( ) . unwrap ( ) ) ;
763
780
}
764
781
} ) ;
782
+
783
+ GRAPHICS_CONTEXT . with_borrow ( |context| {
784
+ if let Some ( ctx) = context {
785
+ ctx. make_current ( ) ;
786
+ }
787
+ } ) ;
765
788
}
766
789
767
790
#[ no_mangle]
@@ -790,6 +813,12 @@ pub unsafe extern "C" fn alvr_start_stream_opengl(config: AlvrStreamConfig) {
790
813
1.0 , // TODO: encoding gamma config
791
814
None , // TODO: passthrough config
792
815
) ) ) ;
816
+
817
+ GRAPHICS_CONTEXT . with_borrow ( |context| {
818
+ if let Some ( ctx) = context {
819
+ ctx. make_current ( ) ;
820
+ }
821
+ } ) ;
793
822
}
794
823
795
824
// todo: support hands
@@ -821,6 +850,12 @@ pub unsafe extern "C" fn alvr_render_lobby_opengl(
821
850
) ;
822
851
}
823
852
} ) ;
853
+
854
+ GRAPHICS_CONTEXT . with_borrow ( |context| {
855
+ if let Some ( ctx) = context {
856
+ ctx. make_current ( ) ;
857
+ }
858
+ } ) ;
824
859
}
825
860
826
861
/// view_params: array of 2
@@ -850,6 +885,12 @@ pub unsafe extern "C" fn alvr_render_stream_opengl(
850
885
) ;
851
886
}
852
887
} ) ;
888
+
889
+ GRAPHICS_CONTEXT . with_borrow ( |context| {
890
+ if let Some ( ctx) = context {
891
+ ctx. make_current ( ) ;
892
+ }
893
+ } ) ;
853
894
}
854
895
855
896
// Decoder-related interface
@@ -967,7 +1008,7 @@ pub extern "C" fn alvr_destroy_decoder() {
967
1008
* DECODER_SOURCE . lock ( ) = None ;
968
1009
}
969
1010
970
- // Returns true if the timestamp and buffer has been written to
1011
+ /// Returns true if the timestamp and buffer has been written to
971
1012
#[ no_mangle]
972
1013
pub extern "C" fn alvr_get_frame (
973
1014
out_timestamp_ns : * mut u64 ,
0 commit comments