Get the magicleap immersive mode demo to take a filename argument
This commit is contained in:
parent
6f5a72229c
commit
3bd825196e
|
@ -56,7 +56,7 @@ mod magicleap;
|
||||||
mod mocked_c_api;
|
mod mocked_c_api;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn magicleap_pathfinder_demo(egl_display: EGLDisplay, egl_context: EGLContext) {
|
pub unsafe extern "C" fn magicleap_pathfinder_demo(egl_display: EGLDisplay, egl_context: EGLContext, file_name: *const c_char) {
|
||||||
unsafe { c_api::MLLoggingLog(c_api::MLLogLevel::Info, &b"Pathfinder Demo\0"[0], &b"Initializing\0"[0]) };
|
unsafe { c_api::MLLoggingLog(c_api::MLLogLevel::Info, &b"Pathfinder Demo\0"[0], &b"Initializing\0"[0]) };
|
||||||
|
|
||||||
let tag = CString::new("Pathfinder Demo").unwrap();
|
let tag = CString::new("Pathfinder Demo").unwrap();
|
||||||
|
@ -75,6 +75,10 @@ pub extern "C" fn magicleap_pathfinder_demo(egl_display: EGLDisplay, egl_context
|
||||||
options.mode = Mode::VR;
|
options.mode = Mode::VR;
|
||||||
options.jobs = Some(3);
|
options.jobs = Some(3);
|
||||||
options.pipeline = 0;
|
options.pipeline = 0;
|
||||||
|
if let Some(file_name) = file_name.as_ref() {
|
||||||
|
let file_name = CStr::from_ptr(file_name).to_string_lossy().into_owned();
|
||||||
|
options.input_path = SVGPath::Resource(file_name);
|
||||||
|
}
|
||||||
|
|
||||||
let mut app = DemoApp::new(window, window_size, options);
|
let mut app = DemoApp::new(window, window_size, options);
|
||||||
debug!("Initialized app");
|
debug!("Initialized app");
|
||||||
|
|
|
@ -24,12 +24,13 @@
|
||||||
#include <ml_graphics.h>
|
#include <ml_graphics.h>
|
||||||
#include <ml_head_tracking.h>
|
#include <ml_head_tracking.h>
|
||||||
#include <ml_perception.h>
|
#include <ml_perception.h>
|
||||||
|
#include <ml_fileinfo.h>
|
||||||
#include <ml_lifecycle.h>
|
#include <ml_lifecycle.h>
|
||||||
#include <ml_logging.h>
|
#include <ml_logging.h>
|
||||||
#include <ml_privileges.h>
|
#include <ml_privileges.h>
|
||||||
|
|
||||||
// Entry point to the Rust code
|
// Entry point to the Rust code
|
||||||
extern "C" MLResult magicleap_pathfinder_demo(EGLDisplay egl_display, EGLContext egl_context);
|
extern "C" MLResult magicleap_pathfinder_demo(EGLDisplay egl_display, EGLContext egl_context, const char* file_name);
|
||||||
|
|
||||||
// Initialization of the scene thread
|
// Initialization of the scene thread
|
||||||
extern "C" void init_scene_thread(uint64_t id) {
|
extern "C" void init_scene_thread(uint64_t id) {
|
||||||
|
@ -181,13 +182,56 @@ int main() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the file argument if there is one
|
||||||
|
MLLifecycleInitArgList* arg_list = nullptr;
|
||||||
|
const MLLifecycleInitArg* arg = nullptr;
|
||||||
|
const MLFileInfo* file_info = nullptr;
|
||||||
|
const char* file_name = nullptr;
|
||||||
|
int64_t arg_list_len = 0;
|
||||||
|
int64_t file_list_len = 0;
|
||||||
|
|
||||||
|
if (MLResult_Ok != MLLifecycleGetInitArgList(&arg_list)) {
|
||||||
|
ML_LOG(Error, "%s: Failed to get init args.", application_name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MLResult_Ok != MLLifecycleGetInitArgListLength(arg_list, &arg_list_len)) {
|
||||||
|
ML_LOG(Error, "%s: Failed to get init arg length.", application_name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg_list_len) {
|
||||||
|
if (MLResult_Ok != MLLifecycleGetInitArgByIndex(arg_list, 0, &arg)) {
|
||||||
|
ML_LOG(Error, "%s: Failed to get init arg.", application_name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MLResult_Ok != MLLifecycleGetFileInfoListLength(arg, &file_list_len)) {
|
||||||
|
ML_LOG(Error, "%s: Failed to get file list length.", application_name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_list_len) {
|
||||||
|
if (MLResult_Ok != MLLifecycleGetFileInfoByIndex(arg, 0, &file_info)) {
|
||||||
|
ML_LOG(Error, "%s: Failed to get file info.", application_name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MLResult_Ok != MLFileInfoGetFileName(file_info, &file_name)) {
|
||||||
|
ML_LOG(Error, "%s: Failed to get file name.", application_name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Run the demo!
|
// Run the demo!
|
||||||
ML_LOG(Info, "%s: Begin demo.", application_name);
|
ML_LOG(Info, "%s: Begin demo (%s).", application_name, file_name);
|
||||||
MLResult status = magicleap_pathfinder_demo(graphics_context.egl_display, graphics_context.egl_context);
|
MLResult status = magicleap_pathfinder_demo(graphics_context.egl_display, graphics_context.egl_context, file_name);
|
||||||
ML_LOG(Info, "%s: End demo (%d).", application_name, status);
|
ML_LOG(Info, "%s: End demo (%d).", application_name, status);
|
||||||
|
|
||||||
// Shut down
|
// Shut down
|
||||||
MLPerceptionShutdown();
|
MLPerceptionShutdown();
|
||||||
|
MLLifecycleFreeInitArgList(&arg_list);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue