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
12 changes: 10 additions & 2 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 @@ -472,6 +472,7 @@ pub extern "C" fn alvr_send_button(path_id: u64, value: AlvrButtonValue) {
}

/// The view poses need to be in local space, as if the head is at the origin.
/// Must be sent when the IPD or FoV changes.
/// view_params: array of 2
#[no_mangle]
pub extern "C" fn alvr_send_view_params(view_params: *const AlvrViewParams) {
Expand Down Expand Up @@ -703,11 +704,13 @@ pub struct AlvrStreamConfig {
foveation_edge_ratio_y: f32,
}

/// Requires calling glMakeContext again after this function
#[no_mangle]
pub extern "C" fn alvr_initialize_opengl() {
GRAPHICS_CONTEXT.set(Some(Rc::new(GraphicsContext::new_gl())));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cant we call glMakeContext in here itself, since its falloff of wgpu implementation? Also client_core is in android native context also.

@zmerp zmerp Dec 10, 2024

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if you end up calling another alvr rendering function right after, the glMakeCurrent call becomes redundant. In alvr_client_openxr instead we call glMakeCurrent just before we need it instead of just after every alvr call.

@zmerp zmerp Dec 10, 2024

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to be too nitpicky, since this C redering API is used only by PhoneVR. So if you request it i can make the glMakeCurrent calls in here. The only place where i can't is when destroying the GRAPHICS_CONTEXT, so you will need to either destroy your gl resources before that call, or call gmMakeCurrent yourself


/// Requires calling glMakeContext again after this function
#[no_mangle]
pub extern "C" fn alvr_destroy_opengl() {
GRAPHICS_CONTEXT.set(None);
Expand All @@ -734,6 +737,7 @@ unsafe fn convert_swapchain_array(
[left_swapchain, right_swapchain]
}

/// Requires calling glMakeContext again after this function
#[no_mangle]
pub unsafe extern "C" fn alvr_resume_opengl(
preferred_view_width: u32,
Expand All @@ -749,12 +753,14 @@ pub unsafe extern "C" fn alvr_resume_opengl(
)));
}

/// Requires calling glMakeContext again after this function
#[no_mangle]
pub extern "C" fn alvr_pause_opengl() {
STREAM_RENDERER.set(None);
LOBBY_RENDERER.set(None)
}

/// Requires calling glMakeContext again after this function
#[no_mangle]
pub unsafe extern "C" fn alvr_update_hud_message_opengl(message: *const c_char) {
LOBBY_RENDERER.with_borrow(|renderer| {
Expand All @@ -764,6 +770,7 @@ pub unsafe extern "C" fn alvr_update_hud_message_opengl(message: *const c_char)
});
}

/// Requires calling glMakeContext again after this function
#[no_mangle]
pub unsafe extern "C" fn alvr_start_stream_opengl(config: AlvrStreamConfig) {
let view_resolution = UVec2::new(config.view_resolution_width, config.view_resolution_height);
Expand Down Expand Up @@ -823,6 +830,7 @@ pub unsafe extern "C" fn alvr_render_lobby_opengl(
});
}

/// Requires calling glMakeContext again after this function
/// view_params: array of 2
#[no_mangle]
pub unsafe extern "C" fn alvr_render_stream_opengl(
Expand Down Expand Up @@ -967,7 +975,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