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

fix(client_core): 🐛 Fix rendering C API #2567

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
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 @@ -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 @@ -705,9 +705,14 @@

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

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

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

// Decoder-related interface
Expand All @@ -858,7 +899,7 @@

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

Check warning on line 902 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:902:5 | 901 | pub enum AlvrMediacodecPropType { | ---------------------- variants in this enum 902 | Float, | ^^^^^ 903 | Int32, | ^^^^^ 904 | Int64, | ^^^^^ 905 | String, | ^^^^^^

Check warning on line 902 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:902:5 | 901 | pub enum AlvrMediacodecPropType { | ---------------------- variants in this enum 902 | Float, | ^^^^^ 903 | Int32, | ^^^^^ 904 | Int64, | ^^^^^ 905 | String, | ^^^^^^
Int32,
Int64,
String,
Expand Down Expand Up @@ -967,7 +1008,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