@@ -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,16 @@ 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 ( |c| c. as_ref ( ) . unwrap ( ) . make_current ( ) ) ;
750
757
}
751
758
752
759
#[ no_mangle]
753
760
pub extern "C" fn alvr_pause_opengl ( ) {
754
761
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 ( ) ) ;
756
765
}
757
766
758
767
#[ no_mangle]
@@ -762,6 +771,8 @@ pub unsafe extern "C" fn alvr_update_hud_message_opengl(message: *const c_char)
762
771
renderer. update_hud_message ( CStr :: from_ptr ( message) . to_str ( ) . unwrap ( ) ) ;
763
772
}
764
773
} ) ;
774
+
775
+ GRAPHICS_CONTEXT . with_borrow ( |c| c. as_ref ( ) . unwrap ( ) . make_current ( ) ) ;
765
776
}
766
777
767
778
#[ no_mangle]
@@ -790,6 +801,8 @@ pub unsafe extern "C" fn alvr_start_stream_opengl(config: AlvrStreamConfig) {
790
801
1.0 , // TODO: encoding gamma config
791
802
None , // TODO: passthrough config
792
803
) ) ) ;
804
+
805
+ GRAPHICS_CONTEXT . with_borrow ( |c| c. as_ref ( ) . unwrap ( ) . make_current ( ) ) ;
793
806
}
794
807
795
808
// todo: support hands
@@ -821,6 +834,8 @@ pub unsafe extern "C" fn alvr_render_lobby_opengl(
821
834
) ;
822
835
}
823
836
} ) ;
837
+
838
+ GRAPHICS_CONTEXT . with_borrow ( |c| c. as_ref ( ) . unwrap ( ) . make_current ( ) ) ;
824
839
}
825
840
826
841
/// view_params: array of 2
@@ -850,6 +865,8 @@ pub unsafe extern "C" fn alvr_render_stream_opengl(
850
865
) ;
851
866
}
852
867
} ) ;
868
+
869
+ GRAPHICS_CONTEXT . with_borrow ( |c| c. as_ref ( ) . unwrap ( ) . make_current ( ) ) ;
853
870
}
854
871
855
872
// Decoder-related interface
@@ -967,7 +984,7 @@ pub extern "C" fn alvr_destroy_decoder() {
967
984
* DECODER_SOURCE . lock ( ) = None ;
968
985
}
969
986
970
- // Returns true if the timestamp and buffer has been written to
987
+ /// Returns true if the timestamp and buffer has been written to
971
988
#[ no_mangle]
972
989
pub extern "C" fn alvr_get_frame (
973
990
out_timestamp_ns : * mut u64 ,
0 commit comments