Wire up magicleap landscape demo cube faces to pathfinder demo

This commit is contained in:
Alan Jeffrey 2019-04-09 14:41:15 -05:00 committed by Josh Matthews
parent 1aedbec4d7
commit 685651c119
9 changed files with 156 additions and 8 deletions

1
Cargo.lock generated
View File

@ -677,6 +677,7 @@ version = "0.1.0"
dependencies = [
"gl 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"pathfinder_geometry 0.3.0",
"pathfinder_gpu 0.1.0",
"pathfinder_renderer 0.1.0",

View File

@ -3,7 +3,6 @@
<property id="name" value="root"/>
<property id="sceneName" value="PathfinderDemo"/>
<node name="quad1" nodeTypeId="lumin.quad">
<property id="color" value="0 0.102 0.502 1"/>
<property id="name" value="quad1"/>
<property id="position">
<property id="x" value="0.15"/>

View File

@ -28,7 +28,7 @@
"lap/types/file/wav"
]
},
"checkpoint-hash": "0a229200eb36f445371d5eef7cd9afaf76b99c1d2278fbca0497449dfcfd890710c7535ff703844a86fabeb5c268c4f234715814458f635ac70bf3d378499654",
"checkpoint-hash": "be7c32a96b1e398705b53fe9c7347469ec0e17c02fae27bd9e0d37a793e00b26292244892a424e35094dbc7348da159a0518e37e24c94eb33188f6756fe25737",
"templates": [
"lap/template/converted_texture_from_bmp",
"lap/template/converted_texture_from_tga",

View File

@ -3,7 +3,6 @@
<property id="name" value="root"/>
<property id="sceneName" value="PathfinderDemo"/>
<node name="quad1" nodeTypeId="lumin.quad">
<property id="color" value="0 0.102 0.502 1"/>
<property id="name" value="quad1"/>
<property id="position">
<property id="x" value="0.15"/>

View File

@ -1,6 +1,6 @@
<ObjectModel name="PathfinderDemo" version="1">
<TransformNode/>
<QuadNode castShadow="false" color="0,0.01512947,0.2453161,1" name="quad1" pos="0.15,-0.15,-0.15" receiveShadow="false" rot="-0,1,-0,-4.371139e-08" shader="MAX" size="0.300000, 0.300000"/>
<QuadNode castShadow="false" name="quad1" pos="0.15,-0.15,-0.15" receiveShadow="false" rot="-0,1,-0,-4.371139e-08" shader="MAX" size="0.300000, 0.300000"/>
<QuadNode castShadow="false" color="0.3504092,0.1572062,0.3504092,1" name="quad2" pos="-0.15,-0.15,0.15" receiveShadow="false" shader="MAX" size="0.300000, 0.300000"/>
<QuadNode castShadow="false" color="0.3504092,0,0,1" name="quad3" pos="0.15,-0.15,0.15" receiveShadow="false" rot="0,0.7071068,0,0.7071068" shader="MAX" size="0.300000, 0.300000"/>
<QuadNode castShadow="false" color="0.3504092,0.09219654,0,1" name="quad4" pos="-0.15,-0.15,-0.15" receiveShadow="false" rot="0,-0.7071068,0,0.7071068" shader="MAX" size="0.300000, 0.300000"/>

View File

@ -67,7 +67,6 @@ int PathfinderDemo::init() {
return 1;
}
// Get the root node of the prism
lumin::RootNode* root_node = prism_->getRootNode();
if (!root_node) {
@ -84,7 +83,6 @@ int PathfinderDemo::init() {
return 1;
}
/*
// Create the EGL surface for it to draw to
lumin::ResourceIDType plane_id = prism_->createPlanarEGLResourceId();
if (!plane_id) {
@ -99,8 +97,21 @@ int PathfinderDemo::init() {
return 1;
}
quad_node->setRenderResource(plane_id);
*/
// Get the EGL context, surface and display.
EGLContext ctx = plane->getEGLContext();
EGLSurface surf = plane->getEGLSurface();
EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglMakeCurrent(dpy, surf, surf, ctx);
// Initialize pathfinder
ML_LOG(Info, "Pathfinder initializing");
pathfinder_ = magicleap_pathfinder_init();
ML_LOG(Info, "Pathfinder initialized");
// Render the SVG
magicleap_pathfinder_render(pathfinder_, dpy, surf, svg_filenames_[0]);
eglSwapBuffers(dpy, surf);
return 0;
}
@ -108,6 +119,8 @@ int PathfinderDemo::deInit() {
ML_LOG(Debug, "PathfinderDemo Deinitializing.");
// Place your deinitialization here.
magicleap_pathfinder_deinit(pathfinder_);
pathfinder_ = nullptr;
return 0;
}
@ -132,7 +145,6 @@ void PathfinderDemo::spawnInitialScenes() {
}
bool PathfinderDemo::updateLoop(float fDelta) {
// Place your update here.
// Return true for your app to continue running, false to terminate the app.
@ -242,3 +254,6 @@ void PathfinderDemo::dispatch(char* svg_filename) {
return;
}
}
extern "C" void init_scene_thread(uint64_t id) {}

View File

@ -12,6 +12,7 @@
// %SRC_VERSION%: 1
#include <EGL/egl.h>
#include <lumin/LandscapeApp.h>
#include <lumin/Prism.h>
#include <lumin/event/ServerEvent.h>
@ -105,6 +106,7 @@ protected:
private:
lumin::Prism* prism_ = nullptr; // represents the bounded space where the App renders.
PrismSceneManager* prismSceneManager_ = nullptr;
void* pathfinder_ = nullptr;
uint64_t svg_filecount_ = 0;
char** svg_filenames_ = nullptr;
lumin::NodeIDType focus_node_ = lumin::INVALID_NODE_ID;
@ -112,3 +114,6 @@ private:
extern "C" uint64_t magicleap_pathfinder_svg_filecount();
extern "C" char** magicleap_pathfinder_svg_filenames();
extern "C" void* magicleap_pathfinder_init();
extern "C" void magicleap_pathfinder_render(void*, EGLDisplay, EGLSurface, char*);
extern "C" void magicleap_pathfinder_deinit(void*);

View File

@ -1,19 +1,28 @@
use crate::magicleap::MagicLeapLandscape;
use crate::magicleap::MagicLeapLogger;
use crate::magicleap::MagicLeapWindow;
use egl;
use egl::EGLContext;
use egl::EGLDisplay;
use egl::EGLSurface;
use log::debug;
use log::info;
use pathfinder_demo::Background;
use pathfinder_demo::DemoApp;
use pathfinder_demo::Options;
use pathfinder_demo::window::Event;
use pathfinder_demo::window::Mode;
use pathfinder_demo::window::SVGPath;
use pathfinder_demo::window::WindowSize;
use pathfinder_geometry::basic::point::Point2DI32;
use std::ffi::CStr;
use std::ffi::CString;
use std::os::raw::c_char;
use std::os::raw::c_void;
mod c_api;
mod magicleap;
@ -75,4 +84,55 @@ pub extern "C" fn magicleap_pathfinder_svg_filecount() -> usize {
#[no_mangle]
pub extern "C" fn magicleap_pathfinder_svg_filenames() -> *const *const c_char {
&SVG_FILENAMES[0]
}
#[no_mangle]
pub extern "C" fn magicleap_pathfinder_init() -> *mut c_void {
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 level = log::LevelFilter::Info;
let logger = MagicLeapLogger::new(tag, level);
log::set_boxed_logger(Box::new(logger)).unwrap();
log::set_max_level(level);
info!("Initialized logging");
let window = MagicLeapLandscape::new();
let window_size = window.window_size();
let options = Options::default();
info!("Initializing app");
let app = DemoApp::new(window, window_size, options);
info!("Initialized app");
Box::into_raw(Box::new(app)) as *mut c_void
}
#[no_mangle]
pub unsafe extern "C" fn magicleap_pathfinder_render(app: *mut c_void, dpy: EGLDisplay, surf: EGLSurface, svg_filename: *const c_char) {
let app = app as *mut DemoApp<MagicLeapLandscape>;
if let Some(app) = app.as_mut() {
let mut width = 0;
let mut height = 0;
egl::query_surface(dpy, surf, egl::EGL_WIDTH, &mut width);
egl::query_surface(dpy, surf, egl::EGL_HEIGHT, &mut height);
gl::Viewport(0, 0, width, height);
let svg_filename = CStr::from_ptr(svg_filename).to_string_lossy().into_owned();
info!("w={}, h={}.", width, height);
app.window.set_size(width, height);
let events = vec![
Event::WindowResized(app.window.window_size()),
Event::OpenSVG(SVGPath::Resource(svg_filename)),
];
app.prepare_frame(events);
app.draw_scene(0);
app.finish_drawing_frame();
app.prepare_frame(vec![]);
app.draw_scene(0);
app.finish_drawing_frame();
}
}
#[no_mangle]
pub unsafe extern "C" fn magicleap_pathfinder_deinit(app: *mut c_void) {
Box::from_raw(app as *mut DemoApp<MagicLeapLandscape>);
}

View File

@ -295,6 +295,75 @@ impl Drop for MagicLeapWindow {
}
}
// Magic Leap landscape app
pub struct MagicLeapLandscape {
size: Point2DI32,
resource_loader: FilesystemResourceLoader,
}
impl Window for MagicLeapLandscape {
fn resource_loader(&self) -> &dyn ResourceLoader {
&self.resource_loader
}
fn gl_version(&self) -> GLVersion {
GLVersion::GLES3
}
fn mouse_position(&self) -> Point2DI32 {
Point2DI32::new(0, 0)
}
fn create_user_event_id (&self) -> u32 {
0
}
fn push_user_event(_: u32, _: u32) {
}
fn present_open_svg_dialog(&mut self) {
}
fn run_save_dialog(&self, _: &str) -> Result<PathBuf, ()> {
Err(())
}
fn view_box_size(&self, _mode: Mode, _subpixel_aa: bool) -> Point2DI32 {
self.size
}
fn make_current(&mut self, _mode: Mode, _subpixel_aa: bool, _eye: Option<u32>) -> RectI32 {
RectI32::new(Point2DI32::new(0, 0), self.size)
}
fn present(&mut self) {
}
}
impl MagicLeapLandscape {
pub fn new() -> MagicLeapLandscape {
gl::load_with(get_proc_address);
let size = Point2DI32::new(512, 512);
let resource_loader = FilesystemResourceLoader::locate();
MagicLeapLandscape {
size,
resource_loader,
}
}
pub fn window_size(&self) -> WindowSize {
WindowSize {
logical_size: self.size,
backing_scale_factor: 1.0,
}
}
pub fn set_size(&mut self, width: i32, height: i32) {
self.size = Point2DI32::new(width, height);
}
}
// Logging
pub struct MagicLeapLogger {