Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(client_core): 📝 Fix C API documentation #2564

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
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 @@ -59,7 +59,7 @@
pub enum AlvrEvent {
HudMessageUpdated,
StreamingStarted {
view_width: u32,

Check warning on line 62 in alvr/client_core/src/c_api.rs

View workflow job for this annotation

GitHub Actions / check-linux

warning: fields `view_width`, `view_height`, `refresh_rate_hint`, `encoding_gamma`, `enable_foveated_encoding`, and `enable_hdr` are never read --> alvr/client_core/src/c_api.rs:62:9 | 61 | StreamingStarted { | ---------------- fields in this variant 62 | view_width: u32, | ^^^^^^^^^^ 63 | view_height: u32, | ^^^^^^^^^^^ 64 | refresh_rate_hint: f32, | ^^^^^^^^^^^^^^^^^ 65 | encoding_gamma: f32, | ^^^^^^^^^^^^^^ 66 | enable_foveated_encoding: bool, | ^^^^^^^^^^^^^^^^^^^^^^^^ 67 | enable_hdr: bool, | ^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default

Check warning on line 62 in alvr/client_core/src/c_api.rs

View workflow job for this annotation

GitHub Actions / check-windows

warning: fields `view_width`, `view_height`, `refresh_rate_hint`, `encoding_gamma`, `enable_foveated_encoding`, and `enable_hdr` are never read --> alvr\client_core\src\c_api.rs:62:9 | 61 | StreamingStarted { | ---------------- fields in this variant 62 | view_width: u32, | ^^^^^^^^^^ 63 | view_height: u32, | ^^^^^^^^^^^ 64 | refresh_rate_hint: f32, | ^^^^^^^^^^^^^^^^^ 65 | encoding_gamma: f32, | ^^^^^^^^^^^^^^ 66 | enable_foveated_encoding: bool, | ^^^^^^^^^^^^^^^^^^^^^^^^ 67 | enable_hdr: bool, | ^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default
view_height: u32,
refresh_rate_hint: f32,
encoding_gamma: f32,
Expand All @@ -68,14 +68,14 @@
},
StreamingStopped,
Haptics {
device_id: u64,

Check warning on line 71 in alvr/client_core/src/c_api.rs

View workflow job for this annotation

GitHub Actions / check-linux

warning: fields `device_id`, `duration_s`, `frequency`, and `amplitude` are never read --> alvr/client_core/src/c_api.rs:71:9 | 70 | Haptics { | ------- fields in this variant 71 | device_id: u64, | ^^^^^^^^^ 72 | duration_s: f32, | ^^^^^^^^^^ 73 | frequency: f32, | ^^^^^^^^^ 74 | amplitude: f32, | ^^^^^^^^^

Check warning on line 71 in alvr/client_core/src/c_api.rs

View workflow job for this annotation

GitHub Actions / check-windows

warning: fields `device_id`, `duration_s`, `frequency`, and `amplitude` are never read --> alvr\client_core\src\c_api.rs:71:9 | 70 | Haptics { | ------- fields in this variant 71 | device_id: u64, | ^^^^^^^^^ 72 | duration_s: f32, | ^^^^^^^^^^ 73 | frequency: f32, | ^^^^^^^^^ 74 | amplitude: f32, | ^^^^^^^^^
duration_s: f32,
frequency: f32,
amplitude: f32,
},
/// Note: All subsequent DecoderConfig events should be ignored until reconnection
DecoderConfig {
codec: AlvrCodec,

Check warning on line 78 in alvr/client_core/src/c_api.rs

View workflow job for this annotation

GitHub Actions / check-linux

warning: field `codec` is never read --> alvr/client_core/src/c_api.rs:78:9 | 77 | DecoderConfig { | ------------- field in this variant 78 | codec: AlvrCodec, | ^^^^^

Check warning on line 78 in alvr/client_core/src/c_api.rs

View workflow job for this annotation

GitHub Actions / check-windows

warning: field `codec` is never read --> alvr\client_core\src\c_api.rs:78:9 | 77 | DecoderConfig { | ------------- field in this variant 78 | codec: AlvrCodec, | ^^^^^
},
}

Expand Down Expand Up @@ -382,7 +382,7 @@
}
}

// 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 @@
}

/// 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 @@
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
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.

Copy link
Member Author

@zmerp zmerp Dec 10, 2024

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.

Copy link
Member Author

@zmerp zmerp Dec 10, 2024

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 @@
[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 @@
)));
}

/// 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 @@
});
}

/// 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 @@
});
}

/// 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 @@ -858,7 +866,7 @@

#[repr(u8)]
pub enum AlvrMediacodecPropType {
Float,

Check warning on line 869 in alvr/client_core/src/c_api.rs

View workflow job for this annotation

GitHub Actions / check-linux

warning: variants `Float`, `Int32`, `Int64`, and `String` are never constructed --> alvr/client_core/src/c_api.rs:869:5 | 868 | pub enum AlvrMediacodecPropType { | ---------------------- variants in this enum 869 | Float, | ^^^^^ 870 | Int32, | ^^^^^ 871 | Int64, | ^^^^^ 872 | String, | ^^^^^^

Check warning on line 869 in alvr/client_core/src/c_api.rs

View workflow job for this annotation

GitHub Actions / check-windows

warning: variants `Float`, `Int32`, `Int64`, and `String` are never constructed --> alvr\client_core\src\c_api.rs:869:5 | 868 | pub enum AlvrMediacodecPropType { | ---------------------- variants in this enum 869 | Float, | ^^^^^ 870 | Int32, | ^^^^^ 871 | Int64, | ^^^^^ 872 | String, | ^^^^^^
Int32,
Int64,
String,
Expand Down Expand Up @@ -967,7 +975,7 @@
*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
Loading