Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 45 additions & 4 deletions alvr/client_core/src/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ pub extern "C" fn alvr_poll_event(out_event: *mut AlvrEvent) -> bool {
}
}

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

#[no_mangle]
pub extern "C" fn alvr_initialize_opengl() {
GRAPHICS_CONTEXT.set(Some(Rc::new(GraphicsContext::new_gl())));
let context = GraphicsContext::new_gl();
context.make_current();

GRAPHICS_CONTEXT.set(Some(Rc::new(context)));
}

/// The GL context might be invalid after this function! Destroy any GL resources before calling
/// this.
#[no_mangle]
pub extern "C" fn alvr_destroy_opengl() {
GRAPHICS_CONTEXT.set(None);
Expand Down Expand Up @@ -747,12 +752,24 @@ pub unsafe extern "C" fn alvr_resume_opengl(
convert_swapchain_array(swapchain_textures, swapchain_length),
"",
)));

GRAPHICS_CONTEXT.with_borrow(|context| {
if let Some(ctx) = context {
ctx.make_current();
}
});
}

#[no_mangle]
pub extern "C" fn alvr_pause_opengl() {
STREAM_RENDERER.set(None);
LOBBY_RENDERER.set(None)
LOBBY_RENDERER.set(None);

GRAPHICS_CONTEXT.with_borrow(|context| {
if let Some(ctx) = context {
ctx.make_current();
}
});
}

#[no_mangle]
Expand All @@ -762,6 +779,12 @@ pub unsafe extern "C" fn alvr_update_hud_message_opengl(message: *const c_char)
renderer.update_hud_message(CStr::from_ptr(message).to_str().unwrap());
}
});

GRAPHICS_CONTEXT.with_borrow(|context| {
if let Some(ctx) = context {
ctx.make_current();
}
});
}

#[no_mangle]
Expand Down Expand Up @@ -790,6 +813,12 @@ pub unsafe extern "C" fn alvr_start_stream_opengl(config: AlvrStreamConfig) {
1.0, // TODO: encoding gamma config
None, // TODO: passthrough config
)));

GRAPHICS_CONTEXT.with_borrow(|context| {
if let Some(ctx) = context {
ctx.make_current();
}
});
}

// todo: support hands
Expand Down Expand Up @@ -821,6 +850,12 @@ pub unsafe extern "C" fn alvr_render_lobby_opengl(
);
}
});

GRAPHICS_CONTEXT.with_borrow(|context| {
if let Some(ctx) = context {
ctx.make_current();
}
});
}

/// view_params: array of 2
Expand Down Expand Up @@ -850,6 +885,12 @@ pub unsafe extern "C" fn alvr_render_stream_opengl(
);
}
});

GRAPHICS_CONTEXT.with_borrow(|context| {
if let Some(ctx) = context {
ctx.make_current();
}
});
}

// Decoder-related interface
Expand Down Expand Up @@ -967,7 +1008,7 @@ pub extern "C" fn alvr_destroy_decoder() {
*DECODER_SOURCE.lock() = None;
}

// Returns true if the timestamp and buffer has been written to
/// Returns true if the timestamp and buffer has been written to
#[no_mangle]
pub extern "C" fn alvr_get_frame(
out_timestamp_ns: *mut u64,
Expand Down