From 838bf684fba58e17beaa1b1016a1559ce147a43e Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Sat, 9 Mar 2019 11:57:44 -0600 Subject: [PATCH 01/32] Add magicleap demo --- Cargo.toml | 1 + demo/magicleap/.cargo/config | 3 + demo/magicleap/.gitignore | 1 + demo/magicleap/Cargo.toml | 44 ++++ demo/magicleap/PathfinderDemo.mabu | 19 ++ demo/magicleap/PathfinderDemo.package | 2 + demo/magicleap/fake-ld.sh | 18 ++ demo/magicleap/manifest.xml | 19 ++ demo/magicleap/src/c_api.rs | 281 ++++++++++++++++++++ demo/magicleap/src/display.rs | 46 ++++ demo/magicleap/src/glwindow.rs | 254 ++++++++++++++++++ demo/magicleap/src/immersive.rs | 129 +++++++++ demo/magicleap/src/lib.rs | 57 ++++ demo/magicleap/src/magicleap.rs | 362 ++++++++++++++++++++++++++ demo/magicleap/src/main.cpp | 179 +++++++++++++ demo/magicleap/src/mocked_c_api.rs | 86 ++++++ 16 files changed, 1501 insertions(+) create mode 100644 demo/magicleap/.cargo/config create mode 100644 demo/magicleap/.gitignore create mode 100644 demo/magicleap/Cargo.toml create mode 100644 demo/magicleap/PathfinderDemo.mabu create mode 100644 demo/magicleap/PathfinderDemo.package create mode 100755 demo/magicleap/fake-ld.sh create mode 100644 demo/magicleap/manifest.xml create mode 100644 demo/magicleap/src/c_api.rs create mode 100644 demo/magicleap/src/display.rs create mode 100644 demo/magicleap/src/glwindow.rs create mode 100644 demo/magicleap/src/immersive.rs create mode 100644 demo/magicleap/src/lib.rs create mode 100644 demo/magicleap/src/magicleap.rs create mode 100644 demo/magicleap/src/main.cpp create mode 100644 demo/magicleap/src/mocked_c_api.rs diff --git a/Cargo.toml b/Cargo.toml index 2f3a55f3..c6c528c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ members = [ "demo/android/rust", "demo/common", + "demo/magicleap", "demo/native", "geometry", "gl", diff --git a/demo/magicleap/.cargo/config b/demo/magicleap/.cargo/config new file mode 100644 index 00000000..33795c4a --- /dev/null +++ b/demo/magicleap/.cargo/config @@ -0,0 +1,3 @@ +[target.aarch64-linux-android] +linker = "./fake-ld.sh" +ar = "aarch64-linux-android-ar" diff --git a/demo/magicleap/.gitignore b/demo/magicleap/.gitignore new file mode 100644 index 00000000..4efeb1bf --- /dev/null +++ b/demo/magicleap/.gitignore @@ -0,0 +1 @@ +.out/ diff --git a/demo/magicleap/Cargo.toml b/demo/magicleap/Cargo.toml new file mode 100644 index 00000000..75d5c6e1 --- /dev/null +++ b/demo/magicleap/Cargo.toml @@ -0,0 +1,44 @@ +[package] +name = "pathfinder_immersive_demo" +version = "0.1.0" +edition = "2018" +authors = ["Alan Jeffrey "] + +[dependencies] +gl = "0.6" +rayon = "1.0" +usvg = "0.4" +egl = "0.2" +log = "0.4" +smallvec = "0.6" +glutin = { version = "0.19", optional = true } + +[lib] +crate-type = ["staticlib"] + +[features] +mocked = ["glutin"] + +[dependencies.pathfinder_demo] +path = "../common" + +[dependencies.pathfinder_geometry] +path = "../../geometry" + +[dependencies.pathfinder_gl] +path = "../../gl" + +[dependencies.pathfinder_gpu] +path = "../../gpu" + +[dependencies.pathfinder_renderer] +path = "../../renderer" + +[dependencies.pathfinder_simd] +path = "../../simd" + +[dependencies.pathfinder_svg] +path = "../../svg" + +[dependencies.pathfinder_ui] +path = "../../ui" diff --git a/demo/magicleap/PathfinderDemo.mabu b/demo/magicleap/PathfinderDemo.mabu new file mode 100644 index 00000000..17ec0e3e --- /dev/null +++ b/demo/magicleap/PathfinderDemo.mabu @@ -0,0 +1,19 @@ +KIND = program +SRCS = src/main.cpp + +LIBPATHS.debug = \ + ../../target/aarch64-linux-android/debug + +LIBPATHS.release = \ + ../../target/aarch64-linux-android/release + +USES = ml_sdk OpenGL stdc++ + +STLIBS = \ + pathfinder_immersive_demo + +SHLIBS = \ + ml_privileges + +DATAS = \ + ../../resources/** : resources/ diff --git a/demo/magicleap/PathfinderDemo.package b/demo/magicleap/PathfinderDemo.package new file mode 100644 index 00000000..de059c08 --- /dev/null +++ b/demo/magicleap/PathfinderDemo.package @@ -0,0 +1,2 @@ +REFS = PathfinderDemo +OPTIONS=package/debuggable/on diff --git a/demo/magicleap/fake-ld.sh b/demo/magicleap/fake-ld.sh new file mode 100755 index 00000000..88f32377 --- /dev/null +++ b/demo/magicleap/fake-ld.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +# This shell script strips out the -landroid that is passed by default by rustc to +# the linker on aarch64-linux-android, and adds some entries to the ld search path. + +set -o errexit +set -o nounset +set -o pipefail + +TARGET=${TARGET:-"aarch64-linux-android"} +LD=${LD:-"${MAGICLEAP_SDK}/tools/toolchains/bin/${TARGET}-gcc"} +LDFLAGS=${LDFLAGS:-"--sysroot=${MAGICLEAP_SDK}/lumin -L${MAGICLEAP_SDK}/tools/toolchains/lib/gcc/${TARGET}/4.9.x ${MAGICLEAP_SDK}/lumin/usr/lib/crtbegin_so.o"} + +# Remove the -landroid flag, grr +ARGS=("$@") +ARGS=${ARGS[@]/-landroid} + +${LD} ${LDFLAGS} ${ARGS} diff --git a/demo/magicleap/manifest.xml b/demo/magicleap/manifest.xml new file mode 100644 index 00000000..3377bed5 --- /dev/null +++ b/demo/magicleap/manifest.xml @@ -0,0 +1,19 @@ + + + + + + + + diff --git a/demo/magicleap/src/c_api.rs b/demo/magicleap/src/c_api.rs new file mode 100644 index 00000000..6f0992f6 --- /dev/null +++ b/demo/magicleap/src/c_api.rs @@ -0,0 +1,281 @@ +#![allow(dead_code)] + +use gl::types::GLuint; +use std::error::Error; +use std::ffi::CStr; +use std::fmt; +#[cfg(not(feature = "mocked"))] +use std::os::raw::c_char; +use std::os::raw::c_void; + +// Types from the MagicLeap C API + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[repr(C)] +pub struct MLHandle(u64); + +impl MLHandle { + pub fn as_gl_uint(self) -> GLuint { + self.0 as GLuint + } +} + +impl From<*mut T> for MLHandle { + fn from(ptr: *mut T) -> MLHandle { + MLHandle(ptr as u64) + } +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[repr(C)] +pub struct MLResult(u32); + +#[derive(Clone, Copy, Debug)] +#[repr(C)] +pub struct MLGraphicsOptions { + pub graphics_flags: u32, + pub color_format: MLSurfaceFormat, + pub depth_format: MLSurfaceFormat, +} + +impl Default for MLGraphicsOptions { + fn default() -> MLGraphicsOptions { + MLGraphicsOptions { + graphics_flags: 0, + color_format: MLSurfaceFormat::RGBA8UNormSRGB, + depth_format: MLSurfaceFormat::D32Float, + } + } +} + +#[derive(Clone, Copy, Debug)] +#[repr(C)] +pub struct MLGraphicsRenderTargetsInfo { + pub min_clip: f32, + pub max_clip: f32, + pub num_virtual_cameras: u32, + pub buffers: [MLGraphicsRenderBufferInfo; ML_BUFFER_COUNT], +} + +#[derive(Clone, Copy, Debug)] +#[repr(C)] +pub struct MLGraphicsRenderBufferInfo { + pub color: MLGraphicsRenderTarget, + pub depth: MLGraphicsRenderTarget, +} + +#[derive(Clone, Copy, Debug)] +#[repr(C)] +pub struct MLGraphicsRenderTarget { + pub width: u32, + pub height: u32, + pub id: MLHandle, + pub format: MLSurfaceFormat, +} + +#[derive(Clone, Copy, Debug)] +#[repr(u32)] +pub enum MLSurfaceFormat { + Unknown = 0, + RGBA8UNorm, + RGBA8UNormSRGB, + RGB10A2UNorm, + RGBA16Float, + D32Float, + D24NormS8, + D32FloatS8, +} + +#[derive(Clone, Copy, Debug)] +#[repr(C)] +pub struct MLGraphicsVirtualCameraInfoArray { + pub num_virtual_cameras: u32, + pub color_id: MLHandle, + pub depth_id: MLHandle, + pub viewport: MLRectf, + pub virtual_cameras: [MLGraphicsVirtualCameraInfo; ML_VIRTUAL_CAMERA_COUNT], +} + +#[derive(Clone, Copy, Debug)] +#[repr(C)] +pub struct MLGraphicsVirtualCameraInfo { + pub left_half_angle: f32, + pub right_half_angle: f32, + pub top_half_angle: f32, + pub bottom_half_angle: f32, + pub sync_object: MLHandle, + pub projection: MLMat4f, + pub transform: MLTransform, + pub virtual_camera_name: MLGraphicsVirtualCameraName, +} + +#[derive(Clone, Copy, Debug)] +#[repr(i32)] +pub enum MLGraphicsVirtualCameraName { + Combined = -1, + Left = 0, + Right, +} + +#[derive(Clone, Copy, Debug)] +#[repr(C)] +pub struct MLGraphicsFrameParams { + pub near_clip: f32, + pub far_clip: f32, + pub focus_distance: f32, + pub surface_scale: f32, + pub protected_surface: bool, + pub projection_type: MLGraphicsProjectionType, +} + +#[derive(Clone, Copy, Debug)] +#[repr(C)] +pub struct MLSnapshotPtr(*mut c_void); + +#[derive(Clone, Copy, Debug)] +#[repr(C)] +pub struct MLCoordinateFrameUID { + pub data: [u64; 2], +} + +#[derive(Clone, Copy, Debug)] +#[repr(C)] +pub struct MLHeadTrackingStaticData { + pub coord_frame_head: MLCoordinateFrameUID, +} + +#[derive(Clone, Copy, Debug)] +#[repr(C)] +pub struct MLGraphicsClipExtentsInfo { + pub virtual_camera_name: MLGraphicsVirtualCameraName, + pub projection: MLMat4f, + pub transform: MLTransform, +} + +#[derive(Clone, Copy, Debug)] +#[repr(C)] +pub struct MLGraphicsClipExtentsInfoArray { + pub num_virtual_cameras: u32, + pub full_extents: MLGraphicsClipExtentsInfo, + pub virtual_camera_extents: [MLGraphicsClipExtentsInfo; ML_VIRTUAL_CAMERA_COUNT], +} + +#[derive(Clone, Copy, Debug)] +#[repr(u32)] +pub enum MLGraphicsProjectionType { + SignedZ = 0, + ReversedInfiniteZ = 1, + UnsignedZ = 2, +} + +#[derive(Clone, Copy, Debug)] +#[repr(C)] +pub struct MLTransform { + pub rotation: MLQuaternionf, + pub position: MLVec3f, +} + +#[derive(Clone, Copy, Debug)] +#[repr(C)] +pub struct MLVec3f { + pub x: f32, + pub y: f32, + pub z: f32, +} + +#[derive(Clone, Copy, Debug)] +#[repr(C)] +pub struct MLRectf { + pub x: f32, + pub y: f32, + pub w: f32, + pub h: f32, +} + +#[derive(Clone, Copy, Debug)] +#[repr(C)] +pub struct MLQuaternionf { + pub x: f32, + pub y: f32, + pub z: f32, + pub w: f32, +} + +#[derive(Clone, Copy, Debug)] +#[repr(C)] +pub struct MLMat4f { + pub matrix_colmajor: [f32; 16], +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[repr(u32)] +pub enum MLLogLevel { + Fatal = 0, + Error = 1, + Warning = 2, + Info = 3, + Debug = 4, + Verbose = 5, +} + +// Constants from the MagicLeap C API + +pub const ML_RESULT_OK: MLResult = MLResult(0); +pub const ML_RESULT_TIMEOUT: MLResult = MLResult(2); +pub const ML_RESULT_UNSPECIFIED_FAILURE: MLResult = MLResult(4); +pub const ML_HANDLE_INVALID: MLHandle = MLHandle(0xFFFFFFFFFFFFFFFF); +pub const ML_BUFFER_COUNT: usize = 3; +pub const ML_VIRTUAL_CAMERA_COUNT: usize = 2; + +// ML error handling + +impl fmt::Display for MLResult { + fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> { + let cmessage = unsafe { CStr::from_ptr(MLGetResultString(*self)) }; + let message = cmessage.to_str().or(Err(fmt::Error))?; + formatter.write_str(message) + } +} + +impl MLResult { + pub fn ok(self) -> Result<(), MLResult> { + if self == ML_RESULT_OK { + Ok(()) + } else { + Err(self) + } + } + + pub fn unwrap(self) { + self.ok().unwrap() + } +} + +impl Error for MLResult { +} + +// Functions from the MagicLeap C API + +#[cfg(not(feature = "mocked"))] +extern "C" { + pub fn MLGraphicsCreateClientGL(options: *const MLGraphicsOptions, gl_context: MLHandle, graphics_client : &mut MLHandle) -> MLResult; + pub fn MLGraphicsDestroyClient(graphics_client: *mut MLHandle) -> MLResult; + pub fn MLHeadTrackingCreate(tracker: *mut MLHandle) -> MLResult; + pub fn MLHeadTrackingGetStaticData(head_tracker: MLHandle, data: *mut MLHeadTrackingStaticData) -> MLResult; + pub fn MLPerceptionGetSnapshot(snapshot: *mut MLSnapshotPtr) -> MLResult; + pub fn MLSnapshotGetTransform(snapshot: MLSnapshotPtr, id: *const MLCoordinateFrameUID, transform: *mut MLTransform) -> MLResult; + pub fn MLPerceptionReleaseSnapshot(snapshot: MLSnapshotPtr) -> MLResult; + pub fn MLLifecycleSetReadyIndication() -> MLResult; + pub fn MLGraphicsGetClipExtents(graphics_client: MLHandle, array: *mut MLGraphicsClipExtentsInfoArray) -> MLResult; + pub fn MLGraphicsGetRenderTargets(graphics_client: MLHandle, targets: *mut MLGraphicsRenderTargetsInfo) -> MLResult; + pub fn MLGraphicsInitFrameParams(params: *mut MLGraphicsFrameParams) -> MLResult; + pub fn MLGraphicsBeginFrame(graphics_client: MLHandle, params: *const MLGraphicsFrameParams, frame_handle: *mut MLHandle, virtual_camera_array: *mut MLGraphicsVirtualCameraInfoArray) -> MLResult; + pub fn MLGraphicsEndFrame(graphics_client: MLHandle, frame_handle: MLHandle) -> MLResult; + pub fn MLGraphicsSignalSyncObjectGL(graphics_client: MLHandle, sync_object: MLHandle) -> MLResult; + pub fn MLGetResultString(result_code: MLResult) -> *const c_char; + pub fn MLLoggingLogLevelIsEnabled(lvl: MLLogLevel) -> bool; + pub fn MLLoggingLog(lvl: MLLogLevel, tag: *const c_char, message: *const c_char); +} + +#[cfg(feature = "mocked")] +pub use crate::mocked_c_api::*; diff --git a/demo/magicleap/src/display.rs b/demo/magicleap/src/display.rs new file mode 100644 index 00000000..6a0f94ba --- /dev/null +++ b/demo/magicleap/src/display.rs @@ -0,0 +1,46 @@ +// pathfinder/demo/immersive/display.rs +// +// Copyright © 2019 The Pathfinder Project Developers. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::error::Error; +use std::io; +use pathfinder_geometry::basic::point::Point2DI32; +use pathfinder_geometry::basic::rect::RectI32; +use pathfinder_geometry::basic::transform3d::Perspective; +use pathfinder_geometry::basic::transform3d::Transform3DF32; +use pathfinder_gl::GLVersion; +use pathfinder_gpu::resources::ResourceLoader; + +pub trait Display: Sized { + type Error: DisplayError; + type Camera: DisplayCamera; + + fn resource_loader(&self) -> &dyn ResourceLoader; + fn gl_version(&self) -> GLVersion; + fn make_current(&mut self) -> Result<(), Self::Error>; + + fn running(&self) -> bool; + fn size(&self) -> Point2DI32; + + fn begin_frame(&mut self) -> Result<&mut[Self::Camera], Self::Error>; + fn end_frame(&mut self) -> Result<(), Self::Error>; +} + +pub trait DisplayCamera { + type Error: DisplayError; + + fn bounds(&self) -> RectI32; + fn view(&self) -> Transform3DF32; + fn perspective(&self) -> Perspective; + + fn make_current(&mut self) -> Result<(), Self::Error>; +} + +pub trait DisplayError: Error + From + From{ +} diff --git a/demo/magicleap/src/glwindow.rs b/demo/magicleap/src/glwindow.rs new file mode 100644 index 00000000..bd90d08e --- /dev/null +++ b/demo/magicleap/src/glwindow.rs @@ -0,0 +1,254 @@ +// pathfinder/demo/immersive/glwindow.rs +// +// Copyright © 2019 The Pathfinder Project Developers. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use gl; + +use glutin::ContextBuilder; +use glutin::ContextError; +use glutin::CreationError; +use glutin::EventsLoop; +use glutin::Event; +use glutin::WindowEvent; +use glutin::GlContext; +use glutin::GlWindow; +use glutin::WindowBuilder; +use glutin::dpi::LogicalSize; + +use crate::display::Display; +use crate::display::DisplayCamera; +use crate::display::DisplayError; + +use pathfinder_geometry::basic::point::Point2DI32; +use pathfinder_geometry::basic::rect::RectI32; +use pathfinder_geometry::basic::transform3d::Transform3DF32; +use pathfinder_geometry::basic::transform3d::Perspective; +use pathfinder_gl::GLVersion; +use pathfinder_gpu::resources::FilesystemResourceLoader; +use pathfinder_gpu::resources::ResourceLoader; + +use std::env; +use std::error::Error; +use std::fmt; +use std::f32::consts::FRAC_PI_4; +use std::io; +use std::rc::Rc; +use std::time::Instant; + +use usvg; + +pub struct GlWindowDisplay { + events_loop: EventsLoop, + gl_window: Rc, + running: bool, + cameras: Vec, + resource_loader: FilesystemResourceLoader, +} + +pub struct GlWindowCamera { + eye: Eye, + gl_window: Rc, + start: Instant, +} + +enum Eye { + Left, + Right, +} + +#[derive(Debug)] +pub enum GlWindowError { + Creation(CreationError), + Context(ContextError), + SVG(usvg::Error), + IO(io::Error), +} + +const DEFAULT_EYE_WIDTH: u32 = 1024; +const DEFAULT_EYE_HEIGHT: u32 = 768; + +const CAMERA_DISTANCE: f32 = 3.0; +const NEAR_CLIP_PLANE: f32 = 0.01; +const FAR_CLIP_PLANE: f32 = 10.0; + +impl Display for GlWindowDisplay { + type Error = GlWindowError; + type Camera = GlWindowCamera; + + fn resource_loader(&self) -> &dyn ResourceLoader { + &self.resource_loader + } + + fn gl_version(&self) -> GLVersion { + GLVersion::GL3 + } + + fn make_current(&mut self) -> Result<(), GlWindowError> { + let size = self.size(); + unsafe { + self.gl_window.make_current()?; + gl::Viewport(0, 0, size.x(), size.y()); + gl::Scissor(0, 0, size.x(), size.y()); + gl::Enable(gl::SCISSOR_TEST); + } + self.handle_events(); + Ok(()) + } + + fn begin_frame(&mut self) -> Result<&mut[GlWindowCamera], GlWindowError> { + self.handle_events(); + Ok(&mut self.cameras[..]) + } + + fn end_frame(&mut self) -> Result<(), GlWindowError> { + self.handle_events(); + self.gl_window.swap_buffers()?; + self.handle_events(); + Ok(()) + } + + fn running(&self) -> bool { + self.running + } + + fn size(&self) -> Point2DI32 { + window_size(&*self.gl_window) + } +} + +impl DisplayCamera for GlWindowCamera { + type Error = GlWindowError; + + fn make_current(&mut self) -> Result<(), GlWindowError> { + let bounds = self.bounds(); + unsafe { + self.gl_window.make_current()?; + gl::Viewport(bounds.origin().x(), bounds.origin().y(), bounds.size().x(), bounds.size().y()); + gl::Scissor(bounds.origin().x(), bounds.origin().y(), bounds.size().x(), bounds.size().y()); + } + Ok(()) + } + + fn bounds(&self) -> RectI32 { + let window_size = window_size(&*self.gl_window); + let eye_size = Point2DI32::new(window_size.x()/2, window_size.y()); + let origin = match self.eye { + Eye::Left => Point2DI32::new(0, 0), + Eye::Right => Point2DI32::new(eye_size.x(), 0), + }; + RectI32::new(origin, eye_size) + } + + fn perspective(&self) -> Perspective { + // TODO: add eye offsets + let bounds = self.bounds(); + let aspect = bounds.size().x() as f32 / bounds.size().y() as f32; + let transform = Transform3DF32::from_perspective(FRAC_PI_4, aspect, NEAR_CLIP_PLANE, FAR_CLIP_PLANE); + Perspective::new(&transform, bounds.size()) + } + + fn view(&self) -> Transform3DF32 { + let duration = Instant::now() - self.start; + let rotation = duration.as_millis() as f32 / 1000.0; + Transform3DF32::from_rotation(rotation, 0.0, 0.0) + .pre_mul(&Transform3DF32::from_translation(0.0, 0.0, -CAMERA_DISTANCE)) + } +} + +impl GlWindowDisplay { + pub fn new() -> Result { + let resource_loader = FilesystemResourceLoader::locate(); + let size = default_window_size(); + let events_loop = glutin::EventsLoop::new(); + let window = WindowBuilder::new() + .with_title("Pathfinder Immersive Demo") + .with_dimensions(size); + let context = ContextBuilder::new() + .with_vsync(true); + let gl_window = Rc::new(glutin::GlWindow::new(window, context, &events_loop)?); + let start = Instant::now(); + let cameras = vec![ + GlWindowCamera { gl_window: gl_window.clone(), start, eye: Eye::Left }, + GlWindowCamera { gl_window: gl_window.clone(), start, eye: Eye::Right }, + ]; + gl::load_with(|name| gl_window.get_proc_address(name) as *const _); + Ok(GlWindowDisplay { + resource_loader, + events_loop, + gl_window, + cameras, + running: true, + }) + } + + fn handle_events(&mut self) { + let running = &mut self.running; + self.events_loop.poll_events(|event| { + match event { + Event::WindowEvent { event: WindowEvent::CloseRequested, .. } | + Event::WindowEvent { event: WindowEvent::Destroyed, .. } => *running = false, + _ => (), + } + }) + } +} + +fn window_size(gl_window: &GlWindow) -> Point2DI32 { + let logical = gl_window + .get_inner_size() + .unwrap_or_else(|| default_window_size()); + let hidpi = gl_window.get_hidpi_factor(); + let physical = logical.to_physical(hidpi); + Point2DI32::new(physical.width as i32, physical.height as i32) +} + +fn default_window_size() -> LogicalSize { + LogicalSize::new((DEFAULT_EYE_WIDTH * 2) as f64, DEFAULT_EYE_HEIGHT as f64) +} + +impl fmt::Display for GlWindowError { + fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + GlWindowError::Creation(ref err) => err.fmt(formatter), + GlWindowError::Context(ref err) => err.fmt(formatter), + GlWindowError::SVG(ref err) => err.fmt(formatter), + GlWindowError::IO(ref err) => err.fmt(formatter), + } + } +} + +impl Error for GlWindowError { +} + +impl From for GlWindowError { + fn from(err: CreationError) -> GlWindowError { + GlWindowError::Creation(err) + } +} + +impl From for GlWindowError { + fn from(err: ContextError) -> GlWindowError { + GlWindowError::Context(err) + } +} + +impl From for GlWindowError { + fn from(err: usvg::Error) -> GlWindowError { + GlWindowError::SVG(err) + } +} + +impl From for GlWindowError { + fn from(err: io::Error) -> GlWindowError { + GlWindowError::IO(err) + } +} + +impl DisplayError for GlWindowError { +} \ No newline at end of file diff --git a/demo/magicleap/src/immersive.rs b/demo/magicleap/src/immersive.rs new file mode 100644 index 00000000..775a0b37 --- /dev/null +++ b/demo/magicleap/src/immersive.rs @@ -0,0 +1,129 @@ +#![allow(unused_imports)] +#![allow(dead_code)] + +use crate::display::Display; +use crate::display::DisplayCamera; + +use log::debug; + +use pathfinder_demo::Options; +use pathfinder_demo::BuildOptions; +use pathfinder_demo::SceneThreadProxy; +use pathfinder_demo::MainToSceneMsg; +use pathfinder_demo::SceneToMainMsg; +use pathfinder_demo::Camera; +use pathfinder_demo::CameraTransform3D; +use pathfinder_gl::GLDevice; +use pathfinder_renderer::gpu::renderer::Renderer; +use pathfinder_geometry::basic::point::Point2DI32; +use pathfinder_geometry::basic::point::Point2DF32; +use pathfinder_geometry::basic::point::Point3DF32; +use pathfinder_geometry::basic::rect::RectI32; +use pathfinder_geometry::basic::transform2d::Transform2DF32; +use pathfinder_geometry::basic::transform3d::Transform3DF32; +use pathfinder_geometry::basic::transform3d::Perspective; +use pathfinder_gpu::Device; +use pathfinder_simd::default::F32x4; +use pathfinder_svg::BuiltSVG; +use pathfinder_renderer::scene::Scene; +use pathfinder_renderer::builder::RenderTransform; + +use std::error::Error; +use std::fmt; +use std::path::Path; +use std::path::PathBuf; +use std::time::Instant; + +use usvg; + +pub struct ImmersiveDemo { + display: D, + renderer: Renderer, + scene_thread_proxy: SceneThreadProxy, + svg_size: Point2DF32, + svg_to_world: Option, +} + +static DEFAULT_SVG_VIRTUAL_PATH: &'static str = "svg/Ghostscript_Tiger.svg"; + +// SVG dimensions in metres +const MAX_SVG_HEIGHT: f32 = 1.0; +const MAX_SVG_WIDTH: f32 = 1.0; +const DEFAULT_SVG_DISTANCE: f32 = 1.5; + +impl ImmersiveDemo { + pub fn new(mut display: D) -> Result { + display.make_current()?; + let resources = display.resource_loader(); + let options = Options::get(); + let svg_data = resources.slurp(DEFAULT_SVG_VIRTUAL_PATH)?; + let tree = usvg::Tree::from_data(&svg_data[..], &usvg::Options::default())?; + let svg = BuiltSVG::from_tree(tree); + let svg_size = svg.scene.view_box.size(); + let scene_thread_proxy = SceneThreadProxy::new(svg.scene, options); + let _ = scene_thread_proxy.sender.send(MainToSceneMsg::SetDrawableSize(display.size())); + let device = GLDevice::new(display.gl_version()); + let viewport = RectI32::new(Point2DI32::new(0, 0), display.size()); + let renderer = Renderer::new(device, resources, viewport, display.size()); + Ok(ImmersiveDemo { + display, + renderer, + scene_thread_proxy, + svg_size, + svg_to_world: None, + }) + } + + pub fn running(&self) -> bool { + self.display.running() + } + + pub fn render_scene(&mut self) -> Result<(), D::Error> { + self.display.make_current()?; + let cameras = self.display.begin_frame()?; + + debug!("PF rendering a frame"); + let start = Instant::now(); + + let svg_size = self.svg_size; + let svg_to_world = self.svg_to_world.get_or_insert_with(|| { + let view: Transform3DF32 = cameras[0].view(); + let svg_to_world_scale = f32::max(MAX_SVG_WIDTH / svg_size.x(), MAX_SVG_HEIGHT / svg_size.y()); + let svg_width = svg_size.x() * svg_to_world_scale; + let svg_height = svg_size.y() * svg_to_world_scale; + Transform3DF32::from_uniform_scale(svg_to_world_scale) + .pre_mul(&Transform3DF32::from_translation(-svg_width / 2.0, -svg_height / 2.0, -DEFAULT_SVG_DISTANCE)) + .pre_mul(&Transform3DF32::from_scale(1.0, -1.0, 1.0)) + .pre_mul(&view.inverse()) + }); + + let render_transforms = cameras.iter() + .map(|camera| RenderTransform::Perspective( + camera.perspective() + .post_mul(&camera.view()) + .post_mul(&svg_to_world) + )).collect(); + let msg = MainToSceneMsg::Build(BuildOptions { + render_transforms: render_transforms, + stem_darkening_font_size: None, + }); + let _ = self.scene_thread_proxy.sender.send(msg); + + if let Ok(reply) = self.scene_thread_proxy.receiver.recv() { + for (camera, scene) in cameras.iter_mut().zip(reply.render_scenes) { + debug!("PF rendering eye after {}ms", (Instant::now() - start).as_millis()); + camera.make_current()?; + let bounds = camera.bounds(); + let background = F32x4::new(0.0, 0.0, 0.0, 1.0); + self.renderer.device.clear(Some(background), Some(1.0), Some(0)); + self.renderer.enable_depth(); + self.renderer.set_viewport(bounds); + self.renderer.render_scene(&scene.built_scene); + } + } + + debug!("PF rendered frame after {}ms", (Instant::now() - start).as_millis()); + self.display.end_frame()?; + Ok(()) + } +} diff --git a/demo/magicleap/src/lib.rs b/demo/magicleap/src/lib.rs new file mode 100644 index 00000000..ebe1e57a --- /dev/null +++ b/demo/magicleap/src/lib.rs @@ -0,0 +1,57 @@ +use crate::magicleap::MagicLeapLogger; +use crate::magicleap::MagicLeapWindow; + +use egl; +use egl::EGLContext; +use egl::EGLDisplay; + +use log::debug; + +use pathfinder_demo::Background; +use pathfinder_demo::DemoApp; +use pathfinder_demo::Options; +use pathfinder_demo::window::Mode; + +use std::ffi::CString; + +mod c_api; +mod magicleap; + +#[cfg(feature = "mocked")] +mod mocked_c_api; + +#[no_mangle] +pub extern "C" fn magicleap_pathfinder_demo(egl_display: EGLDisplay, egl_context: EGLContext) { + 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::Warn; + let logger = MagicLeapLogger::new(tag, level); + log::set_boxed_logger(Box::new(logger)).unwrap(); + log::set_max_level(level); + debug!("Initialized logging"); + + let window = MagicLeapWindow::new(egl_display, egl_context); + let window_size = window.size(); + + let mut options = Options::default(); + options.ui = false; + options.background = Background::None; + options.mode = Mode::VR; + + let mut app = DemoApp::new(window, window_size, options); + debug!("Initialized app"); + + while app.window.running() { + let mut events = Vec::new(); + while let Some(event) = app.window.try_get_event() { + events.push(event); + } + + let scene_count = app.prepare_frame(events); + for scene_index in 0..scene_count { + app.draw_scene(scene_index); + } + app.finish_drawing_frame(); + } +} \ No newline at end of file diff --git a/demo/magicleap/src/magicleap.rs b/demo/magicleap/src/magicleap.rs new file mode 100644 index 00000000..a1275b0e --- /dev/null +++ b/demo/magicleap/src/magicleap.rs @@ -0,0 +1,362 @@ +// pathfinder/demo/magicleap/magicleap.rs +// +// Copyright © 2019 The Pathfinder Project Developers. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use crate::c_api::MLGraphicsBeginFrame; +use crate::c_api::MLGraphicsCreateClientGL; +use crate::c_api::MLGraphicsDestroyClient; +use crate::c_api::MLGraphicsEndFrame; +use crate::c_api::MLGraphicsGetRenderTargets; +use crate::c_api::MLGraphicsInitFrameParams; +use crate::c_api::MLGraphicsOptions; +use crate::c_api::MLGraphicsSignalSyncObjectGL; +use crate::c_api::MLGraphicsVirtualCameraInfoArray; +use crate::c_api::MLHandle; +use crate::c_api::MLHeadTrackingCreate; +use crate::c_api::MLLifecycleSetReadyIndication; +use crate::c_api::MLLogLevel; +use crate::c_api::MLLoggingLog; +use crate::c_api::MLMat4f; +use crate::c_api::MLQuaternionf; +use crate::c_api::MLRectf; +use crate::c_api::MLTransform; +use crate::c_api::MLVec3f; +use crate::c_api::ML_HANDLE_INVALID; +use crate::c_api::ML_RESULT_TIMEOUT; +use crate::c_api::ML_VIRTUAL_CAMERA_COUNT; + +use egl; +use egl::EGL_NO_SURFACE; +use egl::EGLContext; +use egl::EGLDisplay; + +use gl; +use gl::types::GLuint; + +use log; +use log::debug; +use log::info; +use log::warn; + +use pathfinder_demo::window::CameraTransform; +use pathfinder_demo::window::Event; +use pathfinder_demo::window::Mode; +use pathfinder_demo::window::Window; +use pathfinder_demo::window::WindowSize; +use pathfinder_geometry::basic::point::Point2DI32; +use pathfinder_geometry::basic::point::Point2DF32; +use pathfinder_geometry::basic::rect::RectF32; +use pathfinder_geometry::basic::rect::RectI32; +use pathfinder_geometry::basic::transform3d::Perspective; +use pathfinder_geometry::basic::transform3d::Transform3DF32; +use pathfinder_geometry::distortion::BarrelDistortionCoefficients; +use pathfinder_gl::GLVersion; +use pathfinder_gpu::resources::FilesystemResourceLoader; +use pathfinder_gpu::resources::ResourceLoader; +use pathfinder_simd::default::F32x4; + +use smallvec::SmallVec; + +use std::ffi::CString; +use std::io::Write; +use std::mem; +use std::os::raw::c_void; +use std::path::PathBuf; +use std::thread; +use std::time::Duration; + +pub struct MagicLeapWindow { + framebuffer_id: GLuint, + graphics_client: MLHandle, + size: Point2DI32, + virtual_camera_array: MLGraphicsVirtualCameraInfoArray, + initial_camera_transforms: Option>, + frame_handle: MLHandle, + resource_loader: FilesystemResourceLoader, + pose_event: Option>, + running: bool, + in_frame: bool, +} + +impl Window for MagicLeapWindow { + fn resource_loader(&self) -> &dyn ResourceLoader { + &self.resource_loader + } + + fn gl_version(&self) -> GLVersion { + GLVersion::GL3 + } + + fn gl_default_framebuffer(&self) -> GLuint { + self.framebuffer_id + } + + 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 { + Err(()) + } + + fn view_box_size(&self, _mode: Mode) -> Point2DI32 { + self.size + } + + fn barrel_distortion_coefficients(&self) -> BarrelDistortionCoefficients { + BarrelDistortionCoefficients { k0: 0.0, k1: 0.0 } + } + + fn make_current(&mut self, _mode: Mode, eye: Option) -> RectI32 { + self.begin_frame(); + let eye = match eye { + Some(eye) if (eye as usize) < ML_VIRTUAL_CAMERA_COUNT => eye as usize, + _ => { warn!("Asked for eye out of range {:?}", eye); 0 } + }; + debug!("Making {} current.", eye); + let viewport = self.virtual_camera_array.viewport; + let color_id = self.virtual_camera_array.color_id.as_gl_uint(); + let depth_id = self.virtual_camera_array.depth_id.as_gl_uint(); + let virtual_camera = self.virtual_camera_array.virtual_cameras[eye]; + let layer_id = virtual_camera.virtual_camera_name as i32; + unsafe { + gl::FramebufferTextureLayer(gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, color_id, 0, layer_id); + gl::FramebufferTextureLayer(gl::FRAMEBUFFER, gl::DEPTH_ATTACHMENT, depth_id, 0, layer_id); + gl::Viewport(viewport.x as i32, viewport.y as i32, viewport.w as i32, viewport.h as i32); + } + debug!("Made {} current.", eye); + RectI32::new(Point2DI32::new(0, 0), self.size) + } + + fn present(&mut self) { + self.end_frame(); + self.begin_frame(); + } +} + +fn get_proc_address(s: &str) -> *const c_void { + egl::get_proc_address(s) as *const c_void +} + +impl MagicLeapWindow { + pub fn new(egl_display: EGLDisplay, egl_context: EGLContext) -> MagicLeapWindow { + debug!("Creating MagicLeapWindow"); + let mut framebuffer_id = 0; + let graphics_options = MLGraphicsOptions::default(); + let mut graphics_client = unsafe { mem::zeroed() }; + let mut head_tracker = unsafe { mem::zeroed() }; + let mut targets = unsafe { mem::zeroed() }; + let virtual_camera_array = unsafe { mem::zeroed() }; + let handle = MLHandle::from(egl_context); + unsafe { + egl::make_current(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, egl_context); + gl::load_with(get_proc_address); + gl::GenFramebuffers(1, &mut framebuffer_id); + MLGraphicsCreateClientGL(&graphics_options, handle, &mut graphics_client).unwrap(); + MLLifecycleSetReadyIndication().unwrap(); + MLHeadTrackingCreate(&mut head_tracker).unwrap(); + MLGraphicsGetRenderTargets(graphics_client, &mut targets).unwrap(); + } + let (max_width, max_height) = targets.buffers.iter().map(|buffer| buffer.color) + .chain(targets.buffers.iter().map(|buffer| buffer.depth)) + .map(|target| (target.width as i32, target.height as i32)) + .max() + .unwrap_or_default(); + let resource_loader = FilesystemResourceLoader::locate(); + debug!("Created MagicLeapWindow"); + MagicLeapWindow { + framebuffer_id, + graphics_client, + size: Point2DI32::new(max_width, max_height), + frame_handle: ML_HANDLE_INVALID, + virtual_camera_array, + initial_camera_transforms: None, + resource_loader, + pose_event: None, + running: true, + in_frame: false, + } + } + + pub fn size(&self) -> WindowSize { + WindowSize { + logical_size: self.size, + backing_scale_factor: 1.0, + } + } + + pub fn running(&self) -> bool { + self.running + } + + pub fn try_get_event(&mut self) -> Option { + self.pose_event.take().map(Event::CameraTransforms) + } + + fn begin_frame(&mut self) { + if !self.in_frame { + debug!("PF beginning frame"); + let mut params = unsafe { mem::zeroed() }; + unsafe { + gl::BindFramebuffer(gl::FRAMEBUFFER, self.framebuffer_id); + MLGraphicsInitFrameParams(&mut params).unwrap(); + let mut result = MLGraphicsBeginFrame(self.graphics_client, ¶ms, &mut self.frame_handle, &mut self.virtual_camera_array); + if result == ML_RESULT_TIMEOUT { + info!("PF frame timeout"); + let mut sleep = Duration::from_millis(1); + let max_sleep = Duration::from_secs(5); + while result == ML_RESULT_TIMEOUT { + sleep = (sleep * 2).min(max_sleep); + info!("PF exponential backoff {}ms", sleep.as_millis()); + thread::sleep(sleep); + result = MLGraphicsBeginFrame(self.graphics_client, ¶ms, &mut self.frame_handle, &mut self.virtual_camera_array); + } + info!("PF frame finished timeout"); + } + result.unwrap(); + } + let virtual_camera_array = &self.virtual_camera_array; + let initial_cameras = self.initial_camera_transforms.get_or_insert_with(|| + (0..virtual_camera_array.num_virtual_cameras) + .map(|i| &virtual_camera_array.virtual_cameras[i as usize]) + .map(|camera| Transform3DF32::from(camera.transform).post_mul(&Transform3DF32::from_uniform_scale(0.5))) + .collect() + ); + let camera_transforms = (0..virtual_camera_array.num_virtual_cameras) + .map(|i| &virtual_camera_array.virtual_cameras[i as usize]) + .zip(initial_cameras) + .map(|(camera, initial_camera)| CameraTransform { + perspective: Perspective::new( + &Transform3DF32::from(camera.projection), + RectI32::from(virtual_camera_array.viewport).size(), + ), + view: Transform3DF32::from(camera.transform).inverse().post_mul(initial_camera), + }).collect(); + self.in_frame = true; + self.pose_event = Some(camera_transforms); + debug!("PF begun frame"); + } + } + + fn end_frame(&mut self) { + if self.in_frame { + debug!("PF ending frame"); + unsafe { + gl::BindFramebuffer(gl::FRAMEBUFFER, 0); + for i in 0..self.virtual_camera_array.num_virtual_cameras { + let virtual_camera = &self.virtual_camera_array.virtual_cameras[i as usize]; + MLGraphicsSignalSyncObjectGL(self.graphics_client, virtual_camera.sync_object).unwrap(); + } + MLGraphicsEndFrame(self.graphics_client, self.frame_handle).unwrap(); + } + self.in_frame = false; + debug!("PF ended frame"); + } + } +} + +impl Drop for MagicLeapWindow { + fn drop(&mut self) { + self.end_frame(); + unsafe { + gl::DeleteFramebuffers(1, &self.framebuffer_id); + MLGraphicsDestroyClient(&mut self.graphics_client); + } + } +} + +// Logging + +pub struct MagicLeapLogger { + tag: CString, + level_filter: log::LevelFilter, +} + +impl log::Log for MagicLeapLogger { + fn enabled(&self, metadata: &log::Metadata) -> bool { + metadata.level() <= self.level_filter + } + + fn log(&self, record: &log::Record) { + let lvl = match record.level() { + log::Level::Error => MLLogLevel::Error, + log::Level::Warn => MLLogLevel::Warning, + log::Level::Info => MLLogLevel::Info, + log::Level::Debug => MLLogLevel::Debug, + log::Level::Trace => MLLogLevel::Verbose, + }; + let mut msg = SmallVec::<[u8; 128]>::new(); + write!(msg, "{}\0", record.args()).unwrap(); + unsafe { + MLLoggingLog(lvl, self.tag.as_ptr(), &msg[0] as *const _ as _); + } + } + + fn flush(&self) {} +} + +impl MagicLeapLogger { + pub fn new(tag: CString, level_filter: log::LevelFilter) -> Self { + MagicLeapLogger { tag, level_filter } + } +} + +// Impl pathfinder traits for c-api types + +impl From for Transform3DF32 { + fn from(mat: MLTransform) -> Self { + Transform3DF32::from(mat.rotation) + .pre_mul(&Transform3DF32::from(mat.position)) + } +} + +impl From for Transform3DF32 { + fn from(v: MLVec3f) -> Self { + Transform3DF32::from_translation(v.x, v.y, v.z) + } +} + +impl From for RectF32 { + fn from(r: MLRectf) -> Self { + RectF32::new(Point2DF32::new(r.x, r.y), Point2DF32::new(r.w, r.h)) + } +} + +impl From for RectI32 { + fn from(r: MLRectf) -> Self { + RectF32::from(r).to_i32() + } +} + +impl From for Transform3DF32 { + fn from(q: MLQuaternionf) -> Self { + Transform3DF32::from_rotation_quaternion(F32x4::new(q.x, q.y, q.z, q.w)) + } +} + +impl From for Transform3DF32 { + fn from(mat: MLMat4f) -> Self { + let a = mat.matrix_colmajor; + Transform3DF32::row_major(a[0], a[4], a[8], a[12], + a[1], a[5], a[9], a[13], + a[2], a[6], a[10], a[14], + a[3], a[7], a[11], a[15]) + } +} + diff --git a/demo/magicleap/src/main.cpp b/demo/magicleap/src/main.cpp new file mode 100644 index 00000000..666e6bbc --- /dev/null +++ b/demo/magicleap/src/main.cpp @@ -0,0 +1,179 @@ +#include +#include + +#include +#include + +#ifndef EGL_EGLEXT_PROTOTYPES +#define EGL_EGLEXT_PROTOTYPES +#endif + +#include +#include + +#ifndef GL_GLEXT_PROTOTYPES +#define GL_GLEXT_PROTOTYPES +#endif + +#include +#include + +#include +#include +#include +#include +#include +#include + +// Entry point to the Rust code +extern "C" MLResult magicleap_pathfinder_demo(EGLDisplay egl_display, EGLContext egl_context); + +// Constants +const char application_name[] = "com.mozilla.pathfinder.demo"; + +// Structures +struct application_context_t { + int dummy_value; +}; + +struct graphics_context_t { + + EGLDisplay egl_display; + EGLContext egl_context; + + GLuint framebuffer_id; + GLuint vertex_shader_id; + GLuint fragment_shader_id; + GLuint program_id; + + graphics_context_t(); + ~graphics_context_t(); + + void makeCurrent(); + void swapBuffers(); + void unmakeCurrent(); +}; + +graphics_context_t::graphics_context_t() { + egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); + + EGLint major = 4; + EGLint minor = 0; + eglInitialize(egl_display, &major, &minor); + eglBindAPI(EGL_OPENGL_API); + + EGLint config_attribs[] = { + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, 0, + EGL_DEPTH_SIZE, 24, + EGL_STENCIL_SIZE, 8, + EGL_NONE + }; + EGLConfig egl_config = nullptr; + EGLint config_size = 0; + eglChooseConfig(egl_display, config_attribs, &egl_config, 1, &config_size); + + EGLint context_attribs[] = { + EGL_CONTEXT_MAJOR_VERSION_KHR, 3, + EGL_CONTEXT_MINOR_VERSION_KHR, 0, + EGL_NONE + }; + egl_context = eglCreateContext(egl_display, egl_config, EGL_NO_CONTEXT, context_attribs); +} + +void graphics_context_t::makeCurrent() { + eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, egl_context); +} + +void graphics_context_t::unmakeCurrent() { + eglMakeCurrent(NULL, EGL_NO_SURFACE, EGL_NO_SURFACE, NULL); +} + +void graphics_context_t::swapBuffers() { + // buffer swapping is implicit on device (MLGraphicsEndFrame) +} + +graphics_context_t::~graphics_context_t() { + eglDestroyContext(egl_display, egl_context); + eglTerminate(egl_display); +} + +// Callbacks +static void onStop(void* application_context) +{ + ((struct application_context_t*)application_context)->dummy_value = 0; + ML_LOG(Info, "%s: On stop called.", application_name); +} + +static void onPause(void* application_context) +{ + ((struct application_context_t*)application_context)->dummy_value = 1; + ML_LOG(Info, "%s: On pause called.", application_name); +} + +static void onResume(void* application_context) +{ + ((struct application_context_t*)application_context)->dummy_value = 2; + ML_LOG(Info, "%s: On resume called.", application_name); +} + +extern "C" void logMessage(MLLogLevel lvl, char* msg) { + if (MLLoggingLogLevelIsEnabled(lvl)) { + MLLoggingLog(lvl, ML_DEFAULT_LOG_TAG, msg); + } +} + +int main() { + // set up host-specific graphics surface + graphics_context_t graphics_context; + + // let system know our app has started + MLLifecycleCallbacks lifecycle_callbacks = {}; + lifecycle_callbacks.on_stop = onStop; + lifecycle_callbacks.on_pause = onPause; + lifecycle_callbacks.on_resume = onResume; + + struct application_context_t application_context; + application_context.dummy_value = 2; + + if (MLResult_Ok != MLLifecycleInit(&lifecycle_callbacks, (void*)&application_context)) { + ML_LOG(Error, "%s: Failed to initialize lifecycle.", application_name); + return -1; + } + + if (MLResult_Ok != MLPrivilegesStartup()) { + ML_LOG(Error, "%s: Failed to initialize privileges.", application_name); + return -1; + } + if (MLPrivilegesRequestPrivilege(MLPrivilegeID_WorldReconstruction) != MLPrivilegesResult_Granted) { + ML_LOG(Error, "Privilege %d denied.", MLPrivilegeID_WorldReconstruction); + return -1; + } + if (MLPrivilegesRequestPrivilege(MLPrivilegeID_LowLatencyLightwear) != MLPrivilegesResult_Granted) { + ML_LOG(Error, "Privilege %d denied.", MLPrivilegeID_LowLatencyLightwear); + return -1; + } + + // initialize perception system + MLPerceptionSettings perception_settings; + if (MLResult_Ok != MLPerceptionInitSettings(&perception_settings)) { + ML_LOG(Error, "%s: Failed to initialize perception.", application_name); + } + + if (MLResult_Ok != MLPerceptionStartup(&perception_settings)) { + ML_LOG(Error, "%s: Failed to startup perception.", application_name); + return -1; + } + + // Run the demo! + ML_LOG(Info, "%s: Begin demo.", application_name); + MLResult status = magicleap_pathfinder_demo(graphics_context.egl_display, graphics_context.egl_context); + ML_LOG(Info, "%s: End demo (%d).", application_name, status); + + // Shut down + MLPerceptionShutdown(); + + return 0; +} diff --git a/demo/magicleap/src/mocked_c_api.rs b/demo/magicleap/src/mocked_c_api.rs new file mode 100644 index 00000000..37159c68 --- /dev/null +++ b/demo/magicleap/src/mocked_c_api.rs @@ -0,0 +1,86 @@ +#![allow(unused_variables)] +#![allow(dead_code)] +#![allow(non_snake_case)] + +use crate::c_api::MLCoordinateFrameUID; +use crate::c_api::MLGraphicsClipExtentsInfoArray; +use crate::c_api::MLGraphicsFrameParams; +use crate::c_api::MLGraphicsOptions; +use crate::c_api::MLGraphicsRenderTargetsInfo; +use crate::c_api::MLGraphicsVirtualCameraInfoArray; +use crate::c_api::MLHandle; +use crate::c_api::MLHeadTrackingStaticData; +use crate::c_api::MLLogLevel; +use crate::c_api::MLResult; +use crate::c_api::MLSnapshotPtr; +use crate::c_api::MLTransform; +use std::os::raw::c_char; + +pub unsafe fn MLGraphicsCreateClientGL(options: *const MLGraphicsOptions, gl_context: MLHandle, graphics_client : &mut MLHandle) -> MLResult { + unimplemented!() +} + +pub unsafe fn MLGraphicsDestroyClient(graphics_client: *mut MLHandle) -> MLResult { + unimplemented!() +} + +pub unsafe fn MLHeadTrackingCreate(tracker: *mut MLHandle) -> MLResult { + unimplemented!() +} + +pub unsafe fn MLHeadTrackingGetStaticData(head_tracker: MLHandle, data: *mut MLHeadTrackingStaticData) -> MLResult { + unimplemented!() +} + +pub unsafe fn MLPerceptionGetSnapshot(snapshot: *mut MLSnapshotPtr) -> MLResult { + unimplemented!() +} + +pub unsafe fn MLSnapshotGetTransform(snapshot: MLSnapshotPtr, id: *const MLCoordinateFrameUID, transform: *mut MLTransform) -> MLResult { + unimplemented!() +} + +pub unsafe fn MLPerceptionReleaseSnapshot(snapshot: MLSnapshotPtr) -> MLResult { + unimplemented!() +} + +pub unsafe fn MLLifecycleSetReadyIndication() -> MLResult { + unimplemented!() +} + +pub unsafe fn MLGraphicsGetClipExtents(graphics_client: MLHandle, array: *mut MLGraphicsClipExtentsInfoArray) -> MLResult { + unimplemented!() +} + +pub unsafe fn MLGraphicsGetRenderTargets(graphics_client: MLHandle, targets: *mut MLGraphicsRenderTargetsInfo) -> MLResult { + unimplemented!() +} + +pub unsafe fn MLGraphicsInitFrameParams(params: *mut MLGraphicsFrameParams) -> MLResult { + unimplemented!() +} + +pub unsafe fn MLGraphicsBeginFrame(graphics_client: MLHandle, params: *const MLGraphicsFrameParams, frame_handle: *mut MLHandle, virtual_camera_array: *mut MLGraphicsVirtualCameraInfoArray) -> MLResult { + unimplemented!() +} + +pub unsafe fn MLGraphicsEndFrame(graphics_client: MLHandle, frame_handle: MLHandle) -> MLResult { + unimplemented!() +} + +pub unsafe fn MLGraphicsSignalSyncObjectGL(graphics_client: MLHandle, sync_object: MLHandle) -> MLResult { + unimplemented!() +} + +pub unsafe fn MLGetResultString(result_code: MLResult) -> *const c_char { + unimplemented!() +} + +pub unsafe fn MLLoggingLogLevelIsEnabled(lvl: MLLogLevel) -> bool { + unimplemented!() +} + +pub unsafe fn MLLoggingLog(lvl: MLLogLevel, tag: *const c_char, message: *const c_char) { + unimplemented!() +} + From dd0283d8488f8200924a4d84cbebe7c1de20ab76 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Mon, 25 Mar 2019 12:36:15 -0500 Subject: [PATCH 02/32] Reenable jemallocator --- demo/magicleap/README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 demo/magicleap/README.md diff --git a/demo/magicleap/README.md b/demo/magicleap/README.md new file mode 100644 index 00000000..9dacb8af --- /dev/null +++ b/demo/magicleap/README.md @@ -0,0 +1,30 @@ +# Magic Leap demo + +First, install the Magic Leap SDK. By default this is installed in `MagicLeap/mlsdk/`, for example: +``` + export MAGICLEAP_SDK=~/MagicLeap/mlsdk/v0.19.0 +``` + You will also need a signing certificate. +``` + export MLCERT=~/MagicLeap/cert/mycert.cert +``` + +Now build the pathfilder demo library: +``` + CFLAGS="-I${MAGICLEAP_SDK}/lumin/usr/include --sysroot=${MAGICLEAP_SDK}/lumin/usr" \ + PATH=$PATH:${MAGICLEAP_SDK}/tools/toolchains/bin/ \ + cargo build --release --target=aarch64-linux-android +``` + +Then build the `.mpk` archive: +``` + ${MAGICLEAP_SDK}/mabu PathfinderDemo.package -t release_device -s ${MLCERT} +``` +The `.mpk` can be installed: +``` + ${MAGICLEAP_SDK}/tools/mldb/mldb install -u .out/PathfinderDemo/PathfinderDemo.mpk +``` +and run: +``` + ${MAGICLEAP_SDK}/tools/mldb/mldb launch -w com.mozilla.pathfinder.demo +``` From daeee1305c09d91537b05321e33e8c0bf5b9fbf5 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Wed, 27 Mar 2019 11:36:16 -0500 Subject: [PATCH 03/32] Set rayon thread pool size to be 2 in magicleap demo --- demo/magicleap/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/demo/magicleap/src/lib.rs b/demo/magicleap/src/lib.rs index ebe1e57a..a12ff72a 100644 --- a/demo/magicleap/src/lib.rs +++ b/demo/magicleap/src/lib.rs @@ -38,6 +38,7 @@ pub extern "C" fn magicleap_pathfinder_demo(egl_display: EGLDisplay, egl_context options.ui = false; options.background = Background::None; options.mode = Mode::VR; + options.jobs = Some(2); let mut app = DemoApp::new(window, window_size, options); debug!("Initialized app"); From 8de4b952becee4d423c11314ef855aa7e5884395 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Wed, 27 Mar 2019 11:37:06 -0500 Subject: [PATCH 04/32] Change initial camera transform --- demo/magicleap/src/magicleap.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/demo/magicleap/src/magicleap.rs b/demo/magicleap/src/magicleap.rs index a1275b0e..e9ac7a91 100644 --- a/demo/magicleap/src/magicleap.rs +++ b/demo/magicleap/src/magicleap.rs @@ -115,7 +115,7 @@ impl Window for MagicLeapWindow { Err(()) } - fn view_box_size(&self, _mode: Mode) -> Point2DI32 { + fn view_box_size(&self, _mode: Mode, _subpixel_aa: bool) -> Point2DI32 { self.size } @@ -123,7 +123,7 @@ impl Window for MagicLeapWindow { BarrelDistortionCoefficients { k0: 0.0, k1: 0.0 } } - fn make_current(&mut self, _mode: Mode, eye: Option) -> RectI32 { + fn make_current(&mut self, _mode: Mode, _subpixel_aa: bool, eye: Option) -> RectI32 { self.begin_frame(); let eye = match eye { Some(eye) if (eye as usize) < ML_VIRTUAL_CAMERA_COUNT => eye as usize, @@ -232,10 +232,11 @@ impl MagicLeapWindow { result.unwrap(); } let virtual_camera_array = &self.virtual_camera_array; + let initial_offset = Transform3DF32::from_translation(0.0, 0.0, 1.0); let initial_cameras = self.initial_camera_transforms.get_or_insert_with(|| (0..virtual_camera_array.num_virtual_cameras) .map(|i| &virtual_camera_array.virtual_cameras[i as usize]) - .map(|camera| Transform3DF32::from(camera.transform).post_mul(&Transform3DF32::from_uniform_scale(0.5))) + .map(|camera| Transform3DF32::from(camera.transform).post_mul(&initial_offset)) .collect() ); let camera_transforms = (0..virtual_camera_array.num_virtual_cameras) From cf6032416c5308042fbaf911db63876af3a80c82 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Wed, 27 Mar 2019 16:40:09 -0500 Subject: [PATCH 05/32] Predict next frame pose --- demo/magicleap/Cargo.toml | 3 ++ demo/magicleap/src/magicleap.rs | 60 ++++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/demo/magicleap/Cargo.toml b/demo/magicleap/Cargo.toml index 75d5c6e1..33780e3a 100644 --- a/demo/magicleap/Cargo.toml +++ b/demo/magicleap/Cargo.toml @@ -19,6 +19,9 @@ crate-type = ["staticlib"] [features] mocked = ["glutin"] +[profile.release] +debug = true + [dependencies.pathfinder_demo] path = "../common" diff --git a/demo/magicleap/src/magicleap.rs b/demo/magicleap/src/magicleap.rs index e9ac7a91..0850769e 100644 --- a/demo/magicleap/src/magicleap.rs +++ b/demo/magicleap/src/magicleap.rs @@ -56,6 +56,7 @@ use pathfinder_geometry::basic::rect::RectI32; use pathfinder_geometry::basic::transform3d::Perspective; use pathfinder_geometry::basic::transform3d::Transform3DF32; use pathfinder_geometry::distortion::BarrelDistortionCoefficients; +use pathfinder_geometry::util; use pathfinder_gl::GLVersion; use pathfinder_gpu::resources::FilesystemResourceLoader; use pathfinder_gpu::resources::ResourceLoader; @@ -77,6 +78,7 @@ pub struct MagicLeapWindow { size: Point2DI32, virtual_camera_array: MLGraphicsVirtualCameraInfoArray, initial_camera_transforms: Option>, + previous_camera_transforms: Option>, frame_handle: MLHandle, resource_loader: FilesystemResourceLoader, pose_event: Option>, @@ -187,6 +189,7 @@ impl MagicLeapWindow { frame_handle: ML_HANDLE_INVALID, virtual_camera_array, initial_camera_transforms: None, + previous_camera_transforms: None, resource_loader, pose_event: None, running: true, @@ -232,23 +235,32 @@ impl MagicLeapWindow { result.unwrap(); } let virtual_camera_array = &self.virtual_camera_array; - let initial_offset = Transform3DF32::from_translation(0.0, 0.0, 1.0); + let initial_offset = Transform3DF32::from_translation(0.0, 0.0, 1.0); let initial_cameras = self.initial_camera_transforms.get_or_insert_with(|| (0..virtual_camera_array.num_virtual_cameras) .map(|i| &virtual_camera_array.virtual_cameras[i as usize]) .map(|camera| Transform3DF32::from(camera.transform).post_mul(&initial_offset)) .collect() ); + let previous_cameras = self.previous_camera_transforms.get_or_insert_with(|| + (0..virtual_camera_array.num_virtual_cameras) + .map(|i| virtual_camera_array.virtual_cameras[i as usize].transform) + .collect() + ); let camera_transforms = (0..virtual_camera_array.num_virtual_cameras) .map(|i| &virtual_camera_array.virtual_cameras[i as usize]) .zip(initial_cameras) - .map(|(camera, initial_camera)| CameraTransform { - perspective: Perspective::new( - &Transform3DF32::from(camera.projection), - RectI32::from(virtual_camera_array.viewport).size(), - ), - view: Transform3DF32::from(camera.transform).inverse().post_mul(initial_camera), - }).collect(); + .zip(previous_cameras) + .map(|((camera, initial_camera), previous_camera)| { + let predicted_camera = previous_camera.lerp(camera.transform, 1.5); + let projection = Transform3DF32::from(camera.projection); + let size = RectI32::from(virtual_camera_array.viewport).size(); + let perspective = Perspective::new(&projection, size); + let view = Transform3DF32::from(predicted_camera).inverse().post_mul(initial_camera); + *previous_camera = camera.transform; + CameraTransform { perspective, view } + }) + .collect(); self.in_frame = true; self.pose_event = Some(camera_transforms); debug!("PF begun frame"); @@ -318,6 +330,38 @@ impl MagicLeapLogger { } } +// Linear interpolation + +impl MLVec3f { + fn lerp(&self, other: MLVec3f, t: f32) -> MLVec3f { + MLVec3f { + x: util::lerp(self.x, other.x, t), + y: util::lerp(self.y, other.y, t), + z: util::lerp(self.z, other.z, t), + } + } +} + +impl MLQuaternionf { + fn lerp(&self, other: MLQuaternionf, t: f32) -> MLQuaternionf { + MLQuaternionf { + x: util::lerp(self.x, other.x, t), + y: util::lerp(self.y, other.y, t), + z: util::lerp(self.z, other.z, t), + w: util::lerp(self.w, other.w, t), + } + } +} + +impl MLTransform { + fn lerp(&self, other: MLTransform, t: f32) -> MLTransform { + MLTransform { + rotation: self.rotation.lerp(other.rotation, t), + position: self.position.lerp(other.position, t), + } + } +} + // Impl pathfinder traits for c-api types impl From for Transform3DF32 { From 463ea6519b6db63b2ab6df293619a4490b8fe056 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Wed, 27 Mar 2019 17:06:06 -0500 Subject: [PATCH 06/32] Move a magic number into a constant declaration --- demo/magicleap/src/magicleap.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/demo/magicleap/src/magicleap.rs b/demo/magicleap/src/magicleap.rs index 0850769e..8df89d41 100644 --- a/demo/magicleap/src/magicleap.rs +++ b/demo/magicleap/src/magicleap.rs @@ -72,6 +72,9 @@ use std::path::PathBuf; use std::thread; use std::time::Duration; +// How much to predict the next frame based on the current frame and the velocity. +const PREDICTION_FACTOR: f32 = 0.75; + pub struct MagicLeapWindow { framebuffer_id: GLuint, graphics_client: MLHandle, @@ -252,7 +255,7 @@ impl MagicLeapWindow { .zip(initial_cameras) .zip(previous_cameras) .map(|((camera, initial_camera), previous_camera)| { - let predicted_camera = previous_camera.lerp(camera.transform, 1.5); + let predicted_camera = previous_camera.lerp(camera.transform, 1.0 + PREDICTION_FACTOR); let projection = Transform3DF32::from(camera.projection); let size = RectI32::from(virtual_camera_array.viewport).size(); let perspective = Perspective::new(&projection, size); From 6642a2ce1e315f44e6b3d57c6df2f8c9c26c59eb Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Thu, 28 Mar 2019 11:22:22 -0500 Subject: [PATCH 07/32] Lerp the initial cameras to get the initial transform --- demo/magicleap/src/lib.rs | 1 + demo/magicleap/src/magicleap.rs | 42 ++++++++++++--------------------- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/demo/magicleap/src/lib.rs b/demo/magicleap/src/lib.rs index a12ff72a..523dad3f 100644 --- a/demo/magicleap/src/lib.rs +++ b/demo/magicleap/src/lib.rs @@ -39,6 +39,7 @@ pub extern "C" fn magicleap_pathfinder_demo(egl_display: EGLDisplay, egl_context options.background = Background::None; options.mode = Mode::VR; options.jobs = Some(2); + options.pipeline = 0; let mut app = DemoApp::new(window, window_size, options); debug!("Initialized app"); diff --git a/demo/magicleap/src/magicleap.rs b/demo/magicleap/src/magicleap.rs index 8df89d41..30c6e1e2 100644 --- a/demo/magicleap/src/magicleap.rs +++ b/demo/magicleap/src/magicleap.rs @@ -72,16 +72,12 @@ use std::path::PathBuf; use std::thread; use std::time::Duration; -// How much to predict the next frame based on the current frame and the velocity. -const PREDICTION_FACTOR: f32 = 0.75; - pub struct MagicLeapWindow { framebuffer_id: GLuint, graphics_client: MLHandle, size: Point2DI32, virtual_camera_array: MLGraphicsVirtualCameraInfoArray, - initial_camera_transforms: Option>, - previous_camera_transforms: Option>, + initial_camera_transform: Option, frame_handle: MLHandle, resource_loader: FilesystemResourceLoader, pose_event: Option>, @@ -191,8 +187,7 @@ impl MagicLeapWindow { size: Point2DI32::new(max_width, max_height), frame_handle: ML_HANDLE_INVALID, virtual_camera_array, - initial_camera_transforms: None, - previous_camera_transforms: None, + initial_camera_transform: None, resource_loader, pose_event: None, running: true, @@ -217,7 +212,7 @@ impl MagicLeapWindow { fn begin_frame(&mut self) { if !self.in_frame { - debug!("PF beginning frame"); + debug!("PF beginning frame"); let mut params = unsafe { mem::zeroed() }; unsafe { gl::BindFramebuffer(gl::FRAMEBUFFER, self.framebuffer_id); @@ -238,29 +233,22 @@ impl MagicLeapWindow { result.unwrap(); } let virtual_camera_array = &self.virtual_camera_array; - let initial_offset = Transform3DF32::from_translation(0.0, 0.0, 1.0); - let initial_cameras = self.initial_camera_transforms.get_or_insert_with(|| - (0..virtual_camera_array.num_virtual_cameras) - .map(|i| &virtual_camera_array.virtual_cameras[i as usize]) - .map(|camera| Transform3DF32::from(camera.transform).post_mul(&initial_offset)) - .collect() - ); - let previous_cameras = self.previous_camera_transforms.get_or_insert_with(|| - (0..virtual_camera_array.num_virtual_cameras) - .map(|i| virtual_camera_array.virtual_cameras[i as usize].transform) - .collect() - ); + let initial_camera = self.initial_camera_transform.get_or_insert_with(|| { + let initial_offset = Transform3DF32::from_translation(0.0, 0.0, 1.0); + let mut camera = virtual_camera_array.virtual_cameras[0].transform; + for i in 1..virtual_camera_array.num_virtual_cameras { + let next = virtual_camera_array.virtual_cameras[i as usize].transform; + camera = camera.lerp(next, 1.0 / (i as f32 + 1.0)); + } + Transform3DF32::from(camera).post_mul(&initial_offset) + }); let camera_transforms = (0..virtual_camera_array.num_virtual_cameras) - .map(|i| &virtual_camera_array.virtual_cameras[i as usize]) - .zip(initial_cameras) - .zip(previous_cameras) - .map(|((camera, initial_camera), previous_camera)| { - let predicted_camera = previous_camera.lerp(camera.transform, 1.0 + PREDICTION_FACTOR); + .map(|i| { + let camera = &virtual_camera_array.virtual_cameras[i as usize]; let projection = Transform3DF32::from(camera.projection); let size = RectI32::from(virtual_camera_array.viewport).size(); let perspective = Perspective::new(&projection, size); - let view = Transform3DF32::from(predicted_camera).inverse().post_mul(initial_camera); - *previous_camera = camera.transform; + let view = Transform3DF32::from(camera.transform).inverse().post_mul(initial_camera); CameraTransform { perspective, view } }) .collect(); From 8ba56e5597268f4e1bf4e3bb9dc349b950c3ebaf Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Thu, 28 Mar 2019 14:36:27 -0500 Subject: [PATCH 08/32] Pin the scene threads to CPUs --- demo/magicleap/Cargo.toml | 3 --- demo/magicleap/src/lib.rs | 2 +- demo/magicleap/src/magicleap.rs | 10 ++++++++++ demo/magicleap/src/main.cpp | 14 ++++++++++++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/demo/magicleap/Cargo.toml b/demo/magicleap/Cargo.toml index 33780e3a..75d5c6e1 100644 --- a/demo/magicleap/Cargo.toml +++ b/demo/magicleap/Cargo.toml @@ -19,9 +19,6 @@ crate-type = ["staticlib"] [features] mocked = ["glutin"] -[profile.release] -debug = true - [dependencies.pathfinder_demo] path = "../common" diff --git a/demo/magicleap/src/lib.rs b/demo/magicleap/src/lib.rs index 523dad3f..08513f16 100644 --- a/demo/magicleap/src/lib.rs +++ b/demo/magicleap/src/lib.rs @@ -38,7 +38,7 @@ pub extern "C" fn magicleap_pathfinder_demo(egl_display: EGLDisplay, egl_context options.ui = false; options.background = Background::None; options.mode = Mode::VR; - options.jobs = Some(2); + options.jobs = Some(3); options.pipeline = 0; let mut app = DemoApp::new(window, window_size, options); diff --git a/demo/magicleap/src/magicleap.rs b/demo/magicleap/src/magicleap.rs index 30c6e1e2..345f10ce 100644 --- a/demo/magicleap/src/magicleap.rs +++ b/demo/magicleap/src/magicleap.rs @@ -62,6 +62,8 @@ use pathfinder_gpu::resources::FilesystemResourceLoader; use pathfinder_gpu::resources::ResourceLoader; use pathfinder_simd::default::F32x4; +use rayon::ThreadPoolBuilder; + use smallvec::SmallVec; use std::ffi::CString; @@ -98,6 +100,10 @@ impl Window for MagicLeapWindow { self.framebuffer_id } + fn customize_rayon(&self, thread_pool_builder: ThreadPoolBuilder) -> ThreadPoolBuilder { + thread_pool_builder.start_handler(|id| unsafe { init_scene_thread(id) }) + } + fn mouse_position(&self) -> Point2DI32 { Point2DI32::new(0, 0) } @@ -151,6 +157,10 @@ impl Window for MagicLeapWindow { } } +extern "C" { + fn init_scene_thread(id: usize); +} + fn get_proc_address(s: &str) -> *const c_void { egl::get_proc_address(s) as *const c_void } diff --git a/demo/magicleap/src/main.cpp b/demo/magicleap/src/main.cpp index 666e6bbc..6de3d895 100644 --- a/demo/magicleap/src/main.cpp +++ b/demo/magicleap/src/main.cpp @@ -4,6 +4,9 @@ #include #include +#include +#include + #ifndef EGL_EGLEXT_PROTOTYPES #define EGL_EGLEXT_PROTOTYPES #endif @@ -28,6 +31,17 @@ // Entry point to the Rust code extern "C" MLResult magicleap_pathfinder_demo(EGLDisplay egl_display, EGLContext egl_context); +// Initialization of the scene thread +extern "C" void init_scene_thread(uint64_t id) { + // https://forum.magicleap.com/hc/en-us/community/posts/360043120832-How-many-CPUs-does-an-immersive-app-have-access-to-?page=1#community_comment_360005035691 + // We pin scene thread 0 to the Denver core. + if (id < 3) { + uint32_t DenverCoreAffinityMask = 1 << (2 + id); // Denver core is CPU2, A57s are CPU3 and 4. + pid_t ThreadId = gettid(); + syscall(__NR_sched_setaffinity, ThreadId, sizeof(DenverCoreAffinityMask), &DenverCoreAffinityMask); + } +} + // Constants const char application_name[] = "com.mozilla.pathfinder.demo"; From 37c7457929538489ef419c844c39fd2cd6b21fdb Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Fri, 29 Mar 2019 15:28:16 -0500 Subject: [PATCH 09/32] Add magicleap landscape demo --- demo/magicleap/Cargo.toml | 2 +- demo/magicleap/PathfinderDemo.package | 3 +- demo/magicleap/PathfinderImmersiveDemo.mabu | 19 ++ demo/magicleap/PathfinderLandscapeDemo.mabu | 19 ++ demo/magicleap/lre/.gitignore | 12 ++ demo/magicleap/lre/PathfinderDemo.draft | 183 ++++++++++++++++++ demo/magicleap/lre/PathfinderDemo.mabu | 13 ++ demo/magicleap/lre/PathfinderDemo.mlproject | 10 + demo/magicleap/lre/PathfinderDemo.package | 3 + demo/magicleap/lre/code/inc/PathfinderDemo.h | 99 ++++++++++ .../inc/gen/PathfinderDemo/PathfinderDemo.h | 45 +++++ .../lre/code/inc/gen/PrismSceneManager.h | 74 +++++++ .../lre/code/inc/gen/SceneDescriptor.h | 58 ++++++ .../lre/code/inc/gen/SpawnedSceneBase.h | 43 ++++ .../lre/code/inc/gen/SpawnedSceneHandlers.h | 31 +++ .../lre/code/inc/gen/SpawnedSceneUserData.h | 27 +++ demo/magicleap/lre/code/inc/gen/scenes.h | 33 ++++ .../magicleap/lre/code/src/PathfinderDemo.cpp | 102 ++++++++++ .../src/gen/PathfinderDemo/PathfinderDemo.cpp | 63 ++++++ .../lre/code/src/gen/PrismSceneManager.cpp | 124 ++++++++++++ .../lre/code/src/gen/SceneDescriptor.cpp | 66 +++++++ .../lre/code/src/gen/SpawnedSceneBase.cpp | 35 ++++ .../lre/code/src/gen/SpawnedSceneHandlers.cpp | 29 +++ .../lre/code/src/gen/SpawnedSceneUserData.cpp | 26 +++ demo/magicleap/lre/code/src/gen/scenes.cpp | 64 ++++++ demo/magicleap/lre/code/src/main.cpp | 25 +++ demo/magicleap/lre/code/srcs.comp | 8 + demo/magicleap/lre/manifest.xml | 19 ++ .../lre/pipeline/cache/AssetManifest.comp | 0 demo/magicleap/lre/pipeline/lap/project.json | 47 +++++ demo/magicleap/lre/scenes.comp | 3 + .../lre/scenes/PathfinderDemo.design | 183 ++++++++++++++++++ .../lre/scenes/PathfinderDemo.scene.res.xml | 1 + .../lre/scenes/PathfinderDemo.scene.xml | 9 + demo/magicleap/manifest.xml | 14 +- demo/magicleap/src/landscape.cpp | 165 ++++++++++++++++ demo/magicleap/src/landscape.h | 109 +++++++++++ demo/magicleap/src/lib.rs | 19 ++ 38 files changed, 1781 insertions(+), 4 deletions(-) create mode 100644 demo/magicleap/PathfinderImmersiveDemo.mabu create mode 100644 demo/magicleap/PathfinderLandscapeDemo.mabu create mode 100644 demo/magicleap/lre/.gitignore create mode 100644 demo/magicleap/lre/PathfinderDemo.draft create mode 100644 demo/magicleap/lre/PathfinderDemo.mabu create mode 100644 demo/magicleap/lre/PathfinderDemo.mlproject create mode 100644 demo/magicleap/lre/PathfinderDemo.package create mode 100644 demo/magicleap/lre/code/inc/PathfinderDemo.h create mode 100644 demo/magicleap/lre/code/inc/gen/PathfinderDemo/PathfinderDemo.h create mode 100644 demo/magicleap/lre/code/inc/gen/PrismSceneManager.h create mode 100644 demo/magicleap/lre/code/inc/gen/SceneDescriptor.h create mode 100644 demo/magicleap/lre/code/inc/gen/SpawnedSceneBase.h create mode 100644 demo/magicleap/lre/code/inc/gen/SpawnedSceneHandlers.h create mode 100644 demo/magicleap/lre/code/inc/gen/SpawnedSceneUserData.h create mode 100644 demo/magicleap/lre/code/inc/gen/scenes.h create mode 100644 demo/magicleap/lre/code/src/PathfinderDemo.cpp create mode 100644 demo/magicleap/lre/code/src/gen/PathfinderDemo/PathfinderDemo.cpp create mode 100644 demo/magicleap/lre/code/src/gen/PrismSceneManager.cpp create mode 100644 demo/magicleap/lre/code/src/gen/SceneDescriptor.cpp create mode 100644 demo/magicleap/lre/code/src/gen/SpawnedSceneBase.cpp create mode 100644 demo/magicleap/lre/code/src/gen/SpawnedSceneHandlers.cpp create mode 100644 demo/magicleap/lre/code/src/gen/SpawnedSceneUserData.cpp create mode 100644 demo/magicleap/lre/code/src/gen/scenes.cpp create mode 100644 demo/magicleap/lre/code/src/main.cpp create mode 100644 demo/magicleap/lre/code/srcs.comp create mode 100644 demo/magicleap/lre/manifest.xml create mode 100644 demo/magicleap/lre/pipeline/cache/AssetManifest.comp create mode 100644 demo/magicleap/lre/pipeline/lap/project.json create mode 100644 demo/magicleap/lre/scenes.comp create mode 100644 demo/magicleap/lre/scenes/PathfinderDemo.design create mode 100644 demo/magicleap/lre/scenes/PathfinderDemo.scene.res.xml create mode 100644 demo/magicleap/lre/scenes/PathfinderDemo.scene.xml create mode 100644 demo/magicleap/src/landscape.cpp create mode 100644 demo/magicleap/src/landscape.h diff --git a/demo/magicleap/Cargo.toml b/demo/magicleap/Cargo.toml index 75d5c6e1..ea310522 100644 --- a/demo/magicleap/Cargo.toml +++ b/demo/magicleap/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "pathfinder_immersive_demo" +name = "pathfinder_magicleap_demo" version = "0.1.0" edition = "2018" authors = ["Alan Jeffrey "] diff --git a/demo/magicleap/PathfinderDemo.package b/demo/magicleap/PathfinderDemo.package index de059c08..b0f672c6 100644 --- a/demo/magicleap/PathfinderDemo.package +++ b/demo/magicleap/PathfinderDemo.package @@ -1,2 +1,3 @@ -REFS = PathfinderDemo +USES = "lre/scenes" +REFS = PathfinderImmersiveDemo PathfinderLandscapeDemo OPTIONS=package/debuggable/on diff --git a/demo/magicleap/PathfinderImmersiveDemo.mabu b/demo/magicleap/PathfinderImmersiveDemo.mabu new file mode 100644 index 00000000..90209f53 --- /dev/null +++ b/demo/magicleap/PathfinderImmersiveDemo.mabu @@ -0,0 +1,19 @@ +KIND = program +SRCS = src/main.cpp + +LIBPATHS.debug = \ + ../../target/aarch64-linux-android/debug + +LIBPATHS.release = \ + ../../target/aarch64-linux-android/release + +USES = ml_sdk OpenGL stdc++ + +STLIBS = \ + pathfinder_magicleap_demo + +SHLIBS = \ + ml_privileges + +DATAS = \ + ../../resources/** : resources/ diff --git a/demo/magicleap/PathfinderLandscapeDemo.mabu b/demo/magicleap/PathfinderLandscapeDemo.mabu new file mode 100644 index 00000000..be11ba0e --- /dev/null +++ b/demo/magicleap/PathfinderLandscapeDemo.mabu @@ -0,0 +1,19 @@ +KIND = program +SRCS = src/landscape.cpp + +LIBPATHS.debug = \ + ../../target/aarch64-linux-android/debug + +LIBPATHS.release = \ + ../../target/aarch64-linux-android/release + +INCS = \ + src/ \ + lre/code/inc/gen/ + +USES = \ + lumin_runtime \ + lre/code/srcs + +STLIBS = \ + pathfinder_magicleap_demo diff --git a/demo/magicleap/lre/.gitignore b/demo/magicleap/lre/.gitignore new file mode 100644 index 00000000..7eae926b --- /dev/null +++ b/demo/magicleap/lre/.gitignore @@ -0,0 +1,12 @@ +.DS_Store +*.log +*.json.dirty +*.json.lock +*.pyc +*.sln +*.vcxproj* + +pipeline/cache/intermediate/ +.out/ +.vscode/ +.vs/ diff --git a/demo/magicleap/lre/PathfinderDemo.draft b/demo/magicleap/lre/PathfinderDemo.draft new file mode 100644 index 00000000..4df9e299 --- /dev/null +++ b/demo/magicleap/lre/PathfinderDemo.draft @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/demo/magicleap/lre/PathfinderDemo.mabu b/demo/magicleap/lre/PathfinderDemo.mabu new file mode 100644 index 00000000..92bb5f7d --- /dev/null +++ b/demo/magicleap/lre/PathfinderDemo.mabu @@ -0,0 +1,13 @@ +KIND = program + +INCS = \ + code/inc/ \ + code/inc/gen/ + +SRCS = \ + code/src/main.cpp \ + code/src/PathfinderDemo.cpp + +USES = \ + lumin_runtime \ + code/srcs diff --git a/demo/magicleap/lre/PathfinderDemo.mlproject b/demo/magicleap/lre/PathfinderDemo.mlproject new file mode 100644 index 00000000..60d8ace3 --- /dev/null +++ b/demo/magicleap/lre/PathfinderDemo.mlproject @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/demo/magicleap/lre/PathfinderDemo.package b/demo/magicleap/lre/PathfinderDemo.package new file mode 100644 index 00000000..49a402ec --- /dev/null +++ b/demo/magicleap/lre/PathfinderDemo.package @@ -0,0 +1,3 @@ + +USES = "scenes" "pipeline/cache/AssetManifest" +REFS = PathfinderDemo \ No newline at end of file diff --git a/demo/magicleap/lre/code/inc/PathfinderDemo.h b/demo/magicleap/lre/code/inc/PathfinderDemo.h new file mode 100644 index 00000000..0cbefd4a --- /dev/null +++ b/demo/magicleap/lre/code/inc/PathfinderDemo.h @@ -0,0 +1,99 @@ +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#include +#include +#include +#include +#include + +/** + * PathfinderDemo Landscape Application + */ +class PathfinderDemo : public lumin::LandscapeApp { +public: + /** + * Constructs the Landscape Application. + */ + PathfinderDemo(); + + /** + * Destroys the Landscape Application. + */ + virtual ~PathfinderDemo(); + + /** + * Disallows the copy constructor. + */ + PathfinderDemo(const PathfinderDemo&) = delete; + + /** + * Disallows the move constructor. + */ + PathfinderDemo(PathfinderDemo&&) = delete; + + /** + * Disallows the copy assignment operator. + */ + PathfinderDemo& operator=(const PathfinderDemo&) = delete; + + /** + * Disallows the move assignment operator. + */ + PathfinderDemo& operator=(PathfinderDemo&&) = delete; + +protected: + /** + * Initializes the Landscape Application. + * @return - 0 on success, error code on failure. + */ + int init() override; + + /** + * Deinitializes the Landscape Application. + * @return - 0 on success, error code on failure. + */ + int deInit() override; + + /** + * Returns the initial size of the Prism + * Used in createPrism(). + */ + const glm::vec3 getInitialPrismSize() const; + + /** + * Creates the prism, updates the private variable prism_ with the created prism. + */ + void createInitialPrism(); + + /** + * Initializes and creates the scene of all scenes marked as initially instanced + */ + void spawnInitialScenes(); + + /** + * Run application login + */ + virtual bool updateLoop(float fDelta) override; + + /** + * Handle events from the server + */ + virtual bool eventListener(lumin::ServerEvent* event) override; + +private: + lumin::Prism* prism_ = nullptr; // represents the bounded space where the App renders. + PrismSceneManager* prismSceneManager_ = nullptr; +}; + diff --git a/demo/magicleap/lre/code/inc/gen/PathfinderDemo/PathfinderDemo.h b/demo/magicleap/lre/code/inc/gen/PathfinderDemo/PathfinderDemo.h new file mode 100644 index 00000000..e408f388 --- /dev/null +++ b/demo/magicleap/lre/code/inc/gen/PathfinderDemo/PathfinderDemo.h @@ -0,0 +1,45 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#pragma once + +#include +#include + +namespace scenes { + + namespace PathfinderDemo { + + namespace externalNodes { + } + + struct SpawnedScene : public SpawnedSceneBase { + SpawnedScene(const SceneDescriptor& sceneDescriptor, lumin::Node* root); + ~SpawnedScene(); + }; + + SpawnedSceneBase* createSpawnedScene(const SceneDescriptor& sceneDescriptor, lumin::Node* root); + SpawnedSceneHandlers* createSpawnedSceneHandlers(SpawnedSceneBase& spawnedScene); + + extern const SceneDescriptor descriptor; + } +} + diff --git a/demo/magicleap/lre/code/inc/gen/PrismSceneManager.h b/demo/magicleap/lre/code/inc/gen/PrismSceneManager.h new file mode 100644 index 00000000..82d43212 --- /dev/null +++ b/demo/magicleap/lre/code/inc/gen/PrismSceneManager.h @@ -0,0 +1,74 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#pragma once + +#include +#include + +#include +#include +#include +#include + +class PrismSceneManager { + public: + + typedef std::function (*CreateSpawnedSceneUserData); + static void setUserDataCreator(const SceneDescriptor & sceneDescriptor, CreateSpawnedSceneUserData createSpawnedSceneUserData); + + public: + + PrismSceneManager(lumin::Prism* prism); + + enum class SceneState { + Unloaded, + ResourceModelLoaded, + ResourceAndObjectModelLoaded, + }; + + void setSceneState(const SceneDescriptor & sceneDescriptor, SceneState sceneState); + SceneState getSceneState(const SceneDescriptor & sceneDescriptor, SceneState sceneState) const; + + SpawnedSceneBase* spawnScene(const SceneDescriptor & sceneDescriptor); + lumin::Node* spawn(const SceneDescriptor & sceneDescriptor); + + private: + + typedef SpawnedSceneBase* (*CreateSpawnedScene)(const SceneDescriptor& sceneDescriptor, lumin::Node* root); + static const CreateSpawnedScene createSpawnedScene[scenes::numberOfExternalScenes]; + + typedef SpawnedSceneHandlers* (*CreateSpawnedSceneHandlers)(SpawnedSceneBase& spawnedScene); + static const CreateSpawnedSceneHandlers createSpawnedSceneHandlers[scenes::numberOfExternalScenes]; + + static CreateSpawnedSceneUserData createSpawnedSceneUserData[scenes::numberOfExternalScenes]; + + private: + + lumin::Node* createNodeTree(const SceneDescriptor & sceneDescriptor); + + private: + + lumin::Prism* prism_; + SceneState sceneStates_[scenes::numberOfExternalScenes]; + std::string objectModelNames_[scenes::numberOfExternalScenes]; +}; + diff --git a/demo/magicleap/lre/code/inc/gen/SceneDescriptor.h b/demo/magicleap/lre/code/inc/gen/SceneDescriptor.h new file mode 100644 index 00000000..c1b42119 --- /dev/null +++ b/demo/magicleap/lre/code/inc/gen/SceneDescriptor.h @@ -0,0 +1,58 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#pragma once + +#include +#include + +// data class +class SceneDescriptor { + public: + + typedef std::map ExternalNodeReferences; + + SceneDescriptor(int index, const char* externalName, const char* id, const char* sceneGraphFilePath, const char* resourceModelFilePath, const ExternalNodeReferences& externalNodeReferences, bool initiallySpawned); + const std::string& getExternalName() const; + const std::string& getId() const; + const std::string& getSceneGraphPath() const; + const std::string& getResourceModelPath() const; + const ExternalNodeReferences & getExternalNodeReferences() const; + bool getInitiallySpawned() const; + + private: + + friend class PrismSceneManager; + int getIndex() const; + + private: + + int index_; + std::string externalName_; + std::string id_; + std::string sceneGraphPath_; + std::string resourceModelPath_; + const ExternalNodeReferences& externalNodeReferences_; + bool initiallySpawned_; +}; + +bool operator<(const SceneDescriptor& a, const SceneDescriptor& b); + diff --git a/demo/magicleap/lre/code/inc/gen/SpawnedSceneBase.h b/demo/magicleap/lre/code/inc/gen/SpawnedSceneBase.h new file mode 100644 index 00000000..4b597bfd --- /dev/null +++ b/demo/magicleap/lre/code/inc/gen/SpawnedSceneBase.h @@ -0,0 +1,43 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#pragma once + +#include + +class SceneDescriptor; +class SpawnedSceneHandlers; +struct SpawnedSceneUserData; + +struct SpawnedSceneBase { + SpawnedSceneBase(const SceneDescriptor &sd, lumin::Node* rt); + virtual ~SpawnedSceneBase(); + + SpawnedSceneBase() = delete; + SpawnedSceneBase(const SpawnedSceneBase&) = delete; + SpawnedSceneBase(const SpawnedSceneBase&&) = delete; + + const SceneDescriptor& sceneDescriptor; + lumin::Node* root = nullptr; + SpawnedSceneHandlers* handlers = nullptr; + SpawnedSceneUserData* userData = nullptr; +}; + diff --git a/demo/magicleap/lre/code/inc/gen/SpawnedSceneHandlers.h b/demo/magicleap/lre/code/inc/gen/SpawnedSceneHandlers.h new file mode 100644 index 00000000..071a9c9b --- /dev/null +++ b/demo/magicleap/lre/code/inc/gen/SpawnedSceneHandlers.h @@ -0,0 +1,31 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#pragma once + +struct SpawnedSceneBase; + +class SpawnedSceneHandlers { +public: + SpawnedSceneHandlers(SpawnedSceneBase& ssb); + virtual ~SpawnedSceneHandlers(); +}; + diff --git a/demo/magicleap/lre/code/inc/gen/SpawnedSceneUserData.h b/demo/magicleap/lre/code/inc/gen/SpawnedSceneUserData.h new file mode 100644 index 00000000..936efea6 --- /dev/null +++ b/demo/magicleap/lre/code/inc/gen/SpawnedSceneUserData.h @@ -0,0 +1,27 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#pragma once + +struct SpawnedSceneUserData { + virtual ~SpawnedSceneUserData(); +}; + diff --git a/demo/magicleap/lre/code/inc/gen/scenes.h b/demo/magicleap/lre/code/inc/gen/scenes.h new file mode 100644 index 00000000..73f00a03 --- /dev/null +++ b/demo/magicleap/lre/code/inc/gen/scenes.h @@ -0,0 +1,33 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#pragma once + +#include +#include + +namespace scenes { + const int numberOfExternalScenes = 1; + + typedef std::map SceneDescriptorReferences; + extern const SceneDescriptorReferences externalScenes; +} + diff --git a/demo/magicleap/lre/code/src/PathfinderDemo.cpp b/demo/magicleap/lre/code/src/PathfinderDemo.cpp new file mode 100644 index 00000000..fb8d1651 --- /dev/null +++ b/demo/magicleap/lre/code/src/PathfinderDemo.cpp @@ -0,0 +1,102 @@ +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#include +#include +#include +#include +#include +#include + +PathfinderDemo::PathfinderDemo() { + ML_LOG(Debug, "PathfinderDemo Constructor."); + + // Place your constructor implementation here. +} + +PathfinderDemo::~PathfinderDemo() { + ML_LOG(Debug, "PathfinderDemo Destructor."); + + // Place your destructor implementation here. +} + +const glm::vec3 PathfinderDemo::getInitialPrismSize() const { + return glm::vec3(2.0f, 2.0f, 2.0f); +} + +void PathfinderDemo::createInitialPrism() { + prism_ = requestNewPrism(getInitialPrismSize()); + if (!prism_) { + ML_LOG(Error, "PathfinderDemo Error creating default prism."); + abort(); + } + prismSceneManager_ = new PrismSceneManager(prism_); +} + +int PathfinderDemo::init() { + + ML_LOG(Debug, "PathfinderDemo Initializing."); + + createInitialPrism(); + lumin::ui::Cursor::SetScale(prism_, 0.03f); + spawnInitialScenes(); + + // Place your initialization here. + + return 0; +} + +int PathfinderDemo::deInit() { + ML_LOG(Debug, "PathfinderDemo Deinitializing."); + + // Place your deinitialization here. + + return 0; +} + +void PathfinderDemo::spawnInitialScenes() { + + // Iterate over all the exported scenes + for (auto& exportedSceneEntry : scenes::externalScenes ) { + + // If this scene was marked to be instanced at app initialization, do it + const SceneDescriptor &sd = exportedSceneEntry.second; + if (sd.getInitiallySpawned()) { + lumin::Node* const spawnedRoot = prismSceneManager_->spawn(sd); + if (spawnedRoot) { + if (!prism_->getRootNode()->addChild(spawnedRoot)) { + ML_LOG(Error, "PathfinderDemo Failed to add spawnedRoot to the prism root node"); + abort(); + } + } + } + } +} + +bool PathfinderDemo::updateLoop(float fDelta) { + + // Place your update here. + + // Return true for your app to continue running, false to terminate the app. + return true; +} + +bool PathfinderDemo::eventListener(lumin::ServerEvent* event) { + + // Place your event handling here. + + // Return true if the event is consumed. + return false; +} + diff --git a/demo/magicleap/lre/code/src/gen/PathfinderDemo/PathfinderDemo.cpp b/demo/magicleap/lre/code/src/gen/PathfinderDemo/PathfinderDemo.cpp new file mode 100644 index 00000000..9d63c0d7 --- /dev/null +++ b/demo/magicleap/lre/code/src/gen/PathfinderDemo/PathfinderDemo.cpp @@ -0,0 +1,63 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#include +#include +#include + +namespace scenes { + + namespace PathfinderDemo { + + SpawnedScene::SpawnedScene(const SceneDescriptor& sceneDescriptor, lumin::Node* root) + : SpawnedSceneBase(sceneDescriptor, root) { + } + + SpawnedScene::~SpawnedScene() { + } + + SpawnedSceneBase* createSpawnedScene(const SceneDescriptor& sceneDescriptor, lumin::Node* root) { + using namespace externalNodes; + SpawnedScene* spawnedScene = new SpawnedScene(sceneDescriptor, root); + return spawnedScene; + } + + class Handlers : public SpawnedSceneHandlers + { + public: + Handlers(SpawnedScene& ss); + + private: + + }; + + + Handlers::Handlers(SpawnedScene& ss) + : SpawnedSceneHandlers(ss) + { + } + + SpawnedSceneHandlers* createSpawnedSceneHandlers(SpawnedSceneBase& ssb) { + return new Handlers(static_cast(ssb)); + } + } +} + diff --git a/demo/magicleap/lre/code/src/gen/PrismSceneManager.cpp b/demo/magicleap/lre/code/src/gen/PrismSceneManager.cpp new file mode 100644 index 00000000..7a8aee9f --- /dev/null +++ b/demo/magicleap/lre/code/src/gen/PrismSceneManager.cpp @@ -0,0 +1,124 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#include + +#include + +PrismSceneManager::CreateSpawnedSceneUserData PrismSceneManager::createSpawnedSceneUserData[scenes::numberOfExternalScenes]; + +PrismSceneManager::PrismSceneManager(lumin::Prism* prism) +: prism_(prism) { + + if (!prism_) { + ML_LOG(Error, "PrismSceneManager nullptr prism"); + abort(); + } + + for (int i = 0; i < sizeof(sceneStates_)/sizeof(sceneStates_[0]); ++i) { + sceneStates_[i] = SceneState::Unloaded; + } +} + +void PrismSceneManager::setSceneState(const SceneDescriptor & sceneDescriptor, SceneState newState) { + + const int sceneIndex = sceneDescriptor.getIndex(); + SceneState& sceneState = sceneStates_[sceneIndex]; + std::string& objectModelName = objectModelNames_[sceneIndex]; + + if (sceneState == SceneState::Unloaded && (newState == SceneState::ResourceModelLoaded || newState == SceneState::ResourceAndObjectModelLoaded)) { + if (!prism_->loadResourceModel(sceneDescriptor.getResourceModelPath())) { + ML_LOG(Error, "PrismSceneManager failed to load resource model"); + abort(); + } + sceneState = SceneState::ResourceModelLoaded; + } + + if (sceneState == SceneState::ResourceModelLoaded && newState == SceneState::ResourceAndObjectModelLoaded) { + std::string& objectModelName = objectModelNames_[sceneIndex]; + if (!prism_->loadObjectModel(sceneDescriptor.getSceneGraphPath(), objectModelName)) { + ML_LOG(Error, "PrismSceneManager failed to load object model"); + abort(); + } + sceneState = SceneState::ResourceAndObjectModelLoaded; + } + + if (sceneState == SceneState::ResourceAndObjectModelLoaded && (newState == SceneState::ResourceModelLoaded || newState == SceneState::Unloaded)) { + if (!prism_->unloadObjectModel(objectModelName)) { + ML_LOG(Error, "PrismSceneManager failed to unload object model"); + abort(); + } + sceneState = SceneState::ResourceModelLoaded; + objectModelName.clear(); + } + + // Currently there is no effective way to unload the resource model +} + +SpawnedSceneBase* PrismSceneManager::spawnScene(const SceneDescriptor & sceneDescriptor) { + + lumin::Node* root = createNodeTree(sceneDescriptor); + if (!root) { + return nullptr; + } + + const int index = sceneDescriptor.getIndex(); + CreateSpawnedScene css = createSpawnedScene[index]; + SpawnedSceneBase* const spawnedScene = (*css)(sceneDescriptor, root); + + CreateSpawnedSceneHandlers ch = createSpawnedSceneHandlers[index]; + SpawnedSceneHandlers* const handlers = (*ch)(*spawnedScene); + spawnedScene->handlers = handlers; + + CreateSpawnedSceneUserData cssud = createSpawnedSceneUserData[sceneDescriptor.getIndex()]; + if (cssud) { + spawnedScene->userData = (*cssud)(*spawnedScene); + } + return spawnedScene; +} + +lumin::Node* PrismSceneManager::spawn(const SceneDescriptor & sceneDescriptor) { + SpawnedSceneBase* spawnedSceneBase = spawnScene(sceneDescriptor); + if (!spawnedSceneBase) { + return nullptr; + } + lumin::Node* root = spawnedSceneBase->root; + return root; +} + +lumin::Node* PrismSceneManager::createNodeTree(const SceneDescriptor & sceneDescriptor) { + setSceneState(sceneDescriptor, SceneState::ResourceAndObjectModelLoaded); + const int sceneIndex = sceneDescriptor.getIndex(); + std::string& objectModelName = objectModelNames_[sceneIndex]; + + lumin::Node* root = prism_->createAll(objectModelName); + if (!root) { + ML_LOG(Error, "PrismSceneManager failed to create the scene. Is the scene empty?"); + return nullptr; + } + + return root; +} + +void PrismSceneManager::setUserDataCreator(const SceneDescriptor & sceneDescriptor, CreateSpawnedSceneUserData cssud) { + createSpawnedSceneUserData[sceneDescriptor.getIndex()] = cssud ; +} + diff --git a/demo/magicleap/lre/code/src/gen/SceneDescriptor.cpp b/demo/magicleap/lre/code/src/gen/SceneDescriptor.cpp new file mode 100644 index 00000000..92673e33 --- /dev/null +++ b/demo/magicleap/lre/code/src/gen/SceneDescriptor.cpp @@ -0,0 +1,66 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#include + +SceneDescriptor::SceneDescriptor(int index, const char * externalName, const char * id, const char * sceneGraphPath, const char * resourceModelPath, const ExternalNodeReferences& externalNodeReferences, bool initiallySpawned) +: + index_(index), + externalName_(externalName), + id_(id), + sceneGraphPath_(sceneGraphPath), + resourceModelPath_(resourceModelPath), + externalNodeReferences_(externalNodeReferences), + initiallySpawned_(initiallySpawned) { +} + +int SceneDescriptor::getIndex() const { + return index_; +} + +const std::string & SceneDescriptor::getExternalName() const { + return externalName_; +} + +const std::string & SceneDescriptor::getId() const { + return id_; +} + +const std::string & SceneDescriptor::getSceneGraphPath() const { + return sceneGraphPath_; +} + +const std::string & SceneDescriptor::getResourceModelPath() const { + return resourceModelPath_; +} + +const SceneDescriptor::ExternalNodeReferences & SceneDescriptor::getExternalNodeReferences() const { + return externalNodeReferences_; +} + +bool SceneDescriptor::getInitiallySpawned() const { + return initiallySpawned_; +} + +bool operator<(const SceneDescriptor& a, const SceneDescriptor& b) { + return a.getExternalName() < b.getExternalName(); +} + diff --git a/demo/magicleap/lre/code/src/gen/SpawnedSceneBase.cpp b/demo/magicleap/lre/code/src/gen/SpawnedSceneBase.cpp new file mode 100644 index 00000000..51cc3aa7 --- /dev/null +++ b/demo/magicleap/lre/code/src/gen/SpawnedSceneBase.cpp @@ -0,0 +1,35 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#include +#include +#include + +SpawnedSceneBase::SpawnedSceneBase(const SceneDescriptor &sd, lumin::Node* rt) +: sceneDescriptor(sd), + root(rt) { +} + +SpawnedSceneBase::~SpawnedSceneBase() { + delete handlers; + delete userData; +} + diff --git a/demo/magicleap/lre/code/src/gen/SpawnedSceneHandlers.cpp b/demo/magicleap/lre/code/src/gen/SpawnedSceneHandlers.cpp new file mode 100644 index 00000000..6aa30422 --- /dev/null +++ b/demo/magicleap/lre/code/src/gen/SpawnedSceneHandlers.cpp @@ -0,0 +1,29 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#include + +SpawnedSceneHandlers::SpawnedSceneHandlers(SpawnedSceneBase& ssb) { +} + +SpawnedSceneHandlers::~SpawnedSceneHandlers() { +} + diff --git a/demo/magicleap/lre/code/src/gen/SpawnedSceneUserData.cpp b/demo/magicleap/lre/code/src/gen/SpawnedSceneUserData.cpp new file mode 100644 index 00000000..777f0ed6 --- /dev/null +++ b/demo/magicleap/lre/code/src/gen/SpawnedSceneUserData.cpp @@ -0,0 +1,26 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#include + +SpawnedSceneUserData::~SpawnedSceneUserData() { +} + diff --git a/demo/magicleap/lre/code/src/gen/scenes.cpp b/demo/magicleap/lre/code/src/gen/scenes.cpp new file mode 100644 index 00000000..d62a26ba --- /dev/null +++ b/demo/magicleap/lre/code/src/gen/scenes.cpp @@ -0,0 +1,64 @@ +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- +// +// THE CONTENTS OF THIS FILE IS GENERATED BY CODE AND +// ANY MODIFICATIONS WILL BE OVERWRITTEN +// +// -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- + +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#include +#include +#include + +namespace scenes { + + namespace PathfinderDemo { + + namespace externalNodes { + } + + const SceneDescriptor::ExternalNodeReferences externalNodesMap = { + }; + + const SceneDescriptor descriptor( + 0, + "PathfinderDemo", + "root", + "/assets/scenes/PathfinderDemo.scene.xml", + "/assets/scenes/PathfinderDemo.scene.res.xml", + externalNodesMap, + true); + } + + const SceneDescriptorReferences externalScenes = { + {PathfinderDemo::descriptor.getExternalName(), PathfinderDemo::descriptor} + }; + + struct VerifyNumberOfExternalScenes { + VerifyNumberOfExternalScenes() { assert(externalScenes.size() == numberOfExternalScenes); } + }; + + VerifyNumberOfExternalScenes verifyNumberOfExternalScenes; +} + +const PrismSceneManager::CreateSpawnedScene PrismSceneManager::createSpawnedScene[scenes::numberOfExternalScenes] = { + ::scenes::PathfinderDemo::createSpawnedScene +}; + +const PrismSceneManager::CreateSpawnedSceneHandlers PrismSceneManager::createSpawnedSceneHandlers[scenes::numberOfExternalScenes] = { + static_cast(::scenes::PathfinderDemo::createSpawnedSceneHandlers) +}; + diff --git a/demo/magicleap/lre/code/src/main.cpp b/demo/magicleap/lre/code/src/main.cpp new file mode 100644 index 00000000..451406a9 --- /dev/null +++ b/demo/magicleap/lre/code/src/main.cpp @@ -0,0 +1,25 @@ +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + + +#include +#include + +int main(int argc, char **argv) +{ + ML_LOG(Debug, "PathfinderDemo Starting."); + PathfinderDemo myApp; + return myApp.run(); +} + diff --git a/demo/magicleap/lre/code/srcs.comp b/demo/magicleap/lre/code/srcs.comp new file mode 100644 index 00000000..36719ea4 --- /dev/null +++ b/demo/magicleap/lre/code/srcs.comp @@ -0,0 +1,8 @@ +SRCS = \ + src/gen/scenes.cpp \ + src/gen/PathfinderDemo/PathfinderDemo.cpp \ + src/gen/PrismSceneManager.cpp \ + src/gen/SceneDescriptor.cpp \ + src/gen/SpawnedSceneBase.cpp \ + src/gen/SpawnedSceneHandlers.cpp \ + src/gen/SpawnedSceneUserData.cpp \ diff --git a/demo/magicleap/lre/manifest.xml b/demo/magicleap/lre/manifest.xml new file mode 100644 index 00000000..587be289 --- /dev/null +++ b/demo/magicleap/lre/manifest.xml @@ -0,0 +1,19 @@ + + + + + + + diff --git a/demo/magicleap/lre/pipeline/cache/AssetManifest.comp b/demo/magicleap/lre/pipeline/cache/AssetManifest.comp new file mode 100644 index 00000000..e69de29b diff --git a/demo/magicleap/lre/pipeline/lap/project.json b/demo/magicleap/lre/pipeline/lap/project.json new file mode 100644 index 00000000..599272b6 --- /dev/null +++ b/demo/magicleap/lre/pipeline/lap/project.json @@ -0,0 +1,47 @@ +{ + "intermediate-storage": { + "path": "cache", + "kind": "in-tree" + }, + "project-schema-version": 4, + "types": { + "assets": [ + "lap/types/asset/audio", + "lap/types/asset/material", + "lap/types/asset/model", + "lap/types/asset/outline-font", + "lap/types/asset/texture" + ], + "files": [ + "lap/types/file/bmp", + "lap/types/file/dds", + "lap/types/file/fbx", + "lap/types/file/files", + "lap/types/file/gltf", + "lap/types/file/jpg", + "lap/types/file/kmat", + "lap/types/file/ogg", + "lap/types/file/otf", + "lap/types/file/png", + "lap/types/file/tga", + "lap/types/file/tiff", + "lap/types/file/wav" + ] + }, + "checkpoint-hash": "0a229200eb36f445371d5eef7cd9afaf76b99c1d2278fbca0497449dfcfd890710c7535ff703844a86fabeb5c268c4f234715814458f635ac70bf3d378499654", + "templates": [ + "lap/template/converted_texture_from_bmp", + "lap/template/converted_texture_from_tga", + "lap/template/converted_texture_from_tiff", + "lap/template/passthru_audio_from_ogg", + "lap/template/passthru_audio_from_wav", + "lap/template/passthru_material_from_kmat", + "lap/template/passthru_model_from_fbx", + "lap/template/passthru_model_from_gltf", + "lap/template/passthru_outline_font_from_otf", + "lap/template/passthru_texture_from_dds", + "lap/template/passthru_texture_from_jpg", + "lap/template/passthru_texture_from_png" + ], + "nodes": {} +} \ No newline at end of file diff --git a/demo/magicleap/lre/scenes.comp b/demo/magicleap/lre/scenes.comp new file mode 100644 index 00000000..ebc999ca --- /dev/null +++ b/demo/magicleap/lre/scenes.comp @@ -0,0 +1,3 @@ +DATAS = \ + scenes/PathfinderDemo.scene.res.xml : assets/scenes/PathfinderDemo.scene.res.xml \ + scenes/PathfinderDemo.scene.xml : assets/scenes/PathfinderDemo.scene.xml diff --git a/demo/magicleap/lre/scenes/PathfinderDemo.design b/demo/magicleap/lre/scenes/PathfinderDemo.design new file mode 100644 index 00000000..4df9e299 --- /dev/null +++ b/demo/magicleap/lre/scenes/PathfinderDemo.design @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/demo/magicleap/lre/scenes/PathfinderDemo.scene.res.xml b/demo/magicleap/lre/scenes/PathfinderDemo.scene.res.xml new file mode 100644 index 00000000..ef5f53f7 --- /dev/null +++ b/demo/magicleap/lre/scenes/PathfinderDemo.scene.res.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/demo/magicleap/lre/scenes/PathfinderDemo.scene.xml b/demo/magicleap/lre/scenes/PathfinderDemo.scene.xml new file mode 100644 index 00000000..10695e5d --- /dev/null +++ b/demo/magicleap/lre/scenes/PathfinderDemo.scene.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/demo/magicleap/manifest.xml b/demo/magicleap/manifest.xml index 3377bed5..80240ff1 100644 --- a/demo/magicleap/manifest.xml +++ b/demo/magicleap/manifest.xml @@ -9,10 +9,20 @@ ml:min_api_level="3"> + + + + diff --git a/demo/magicleap/src/landscape.cpp b/demo/magicleap/src/landscape.cpp new file mode 100644 index 00000000..7b0d52d8 --- /dev/null +++ b/demo/magicleap/src/landscape.cpp @@ -0,0 +1,165 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + ML_LOG(Debug, "PathfinderDemo Starting."); + PathfinderDemo myApp; + return myApp.run(); +} + +const char* QUAD_NAMES[1] = { + "quad1" +}; + +const char* PANEL_NAMES[1] = { + "uiPanel1" +}; + +PathfinderDemo::PathfinderDemo() { + ML_LOG(Debug, "PathfinderDemo Constructor."); + + // Place your constructor implementation here. + svg_filecount_ = magicleap_pathfinder_svg_filecount(); + svg_filenames_ = magicleap_pathfinder_svg_filenames(); +} + +PathfinderDemo::~PathfinderDemo() { + ML_LOG(Debug, "PathfinderDemo Destructor."); + + // Place your destructor implementation here. +} + +const glm::vec3 PathfinderDemo::getInitialPrismSize() const { + return glm::vec3(0.4f, 0.4f, 0.4f); +} + +void PathfinderDemo::createInitialPrism() { + prism_ = requestNewPrism(getInitialPrismSize()); + if (!prism_) { + ML_LOG(Error, "PathfinderDemo Error creating default prism."); + abort(); + } + prismSceneManager_ = new PrismSceneManager(prism_); +} + +int PathfinderDemo::init() { + + ML_LOG(Debug, "PathfinderDemo Initializing."); + + createInitialPrism(); + lumin::ui::Cursor::SetEnabled(prism_, false); + spawnInitialScenes(); + + // Place your initialization here. + if (checkPrivilege(lumin::PrivilegeId::kControllerPose) != lumin::PrivilegeResult::kGranted) { + ML_LOG(Error, "Pathfinder Failed to get controller access"); + abort(); + return 1; + } + + + // Get the root node of the prism + lumin::RootNode* root_node = prism_->getRootNode(); + if (!root_node) { + ML_LOG(Error, "Pathfinder Failed to get root node"); + abort(); + return 1; + } + + // Get the quad + lumin::QuadNode* quad_node = lumin::QuadNode::CastFrom(prism_->findNode(QUAD_NAMES[0], root_node)); + if (!quad_node) { + ML_LOG(Error, "Pathfinder Failed to get quad node"); + abort(); + return 1; + } + + // Create the EGL surface for it to draw to + lumin::ResourceIDType plane_id = prism_->createPlanarEGLResourceId(); + if (!plane_id) { + ML_LOG(Error, "Pathfinder Failed to create EGL resource"); + abort(); + return 1; + } + lumin::PlanarResource* plane = static_cast(prism_->getResource(plane_id)); + if (!plane) { + ML_LOG(Error, "Pathfinder Failed to get plane"); + abort(); + return 1; + } + quad_node->setRenderResource(plane_id); + + return 0; +} + +int PathfinderDemo::deInit() { + ML_LOG(Debug, "PathfinderDemo Deinitializing."); + + // Place your deinitialization here. + + return 0; +} + +void PathfinderDemo::spawnInitialScenes() { + + // Iterate over all the exported scenes + for (auto& exportedSceneEntry : scenes::externalScenes ) { + + // If this scene was marked to be instanced at app initialization, do it + const SceneDescriptor &sd = exportedSceneEntry.second; + if (sd.getInitiallySpawned()) { + lumin::Node* const spawnedRoot = prismSceneManager_->spawn(sd); + if (spawnedRoot) { + if (!prism_->getRootNode()->addChild(spawnedRoot)) { + ML_LOG(Error, "PathfinderDemo Failed to add spawnedRoot to the prism root node"); + abort(); + } + } + } + } +} + +bool PathfinderDemo::updateLoop(float fDelta) { + + // Place your update here. + + // Return true for your app to continue running, false to terminate the app. + return true; +} + +bool PathfinderDemo::eventListener(lumin::ServerEvent* event) { + // Place your event handling here. + lumin::ServerEventType typ = event->getServerEventType(); + switch (typ) { + case lumin::ServerEventType::kControlPose6DofInputEvent: + requestWorldRayCast(getHeadposeWorldPosition(), getHeadposeWorldForwardVector(), 0); + return false; + case lumin::ServerEventType::kRayCastEvent: { + lumin::RayCastEventData* raycast_event = static_cast(event); + std::shared_ptr raycast_result = raycast_event->getHitData(); + switch (raycast_result->getType()) { + case lumin::RaycastResultType::kQuadNode: { + std::shared_ptr quad_result = std::static_pointer_cast(raycast_result); + focus_node = quad_result->getNodeId(); + return false; + } + default: + focus_node = lumin::INVALID_NODE_ID; + return false; + } + } + default: + return false; + } +} + diff --git a/demo/magicleap/src/landscape.h b/demo/magicleap/src/landscape.h new file mode 100644 index 00000000..a4191e32 --- /dev/null +++ b/demo/magicleap/src/landscape.h @@ -0,0 +1,109 @@ +// %BANNER_BEGIN% +// --------------------------------------------------------------------- +// %COPYRIGHT_BEGIN% +// +// Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. +// Use of this file is governed by the Creator Agreement, located +// here: https://id.magicleap.com/creator-terms +// +// %COPYRIGHT_END% +// --------------------------------------------------------------------- +// %BANNER_END% + +// %SRC_VERSION%: 1 + +#include +#include +#include +#include +#include + +/** + * PathfinderDemo Landscape Application + */ +class PathfinderDemo : public lumin::LandscapeApp { +public: + /** + * Constructs the Landscape Application. + */ + PathfinderDemo(); + + /** + * Destroys the Landscape Application. + */ + virtual ~PathfinderDemo(); + + /** + * Disallows the copy constructor. + */ + PathfinderDemo(const PathfinderDemo&) = delete; + + /** + * Disallows the move constructor. + */ + PathfinderDemo(PathfinderDemo&&) = delete; + + /** + * Disallows the copy assignment operator. + */ + PathfinderDemo& operator=(const PathfinderDemo&) = delete; + + /** + * Disallows the move assignment operator. + */ + PathfinderDemo& operator=(PathfinderDemo&&) = delete; + +protected: + /** + * Initializes the Landscape Application. + * @return - 0 on success, error code on failure. + */ + int init() override; + + /** + * Deinitializes the Landscape Application. + * @return - 0 on success, error code on failure. + */ + int deInit() override; + + /** + * Returns the initial size of the Prism + * Used in createPrism(). + */ + const glm::vec3 getInitialPrismSize() const; + + /** + * Creates the prism, updates the private variable prism_ with the created prism. + */ + void createInitialPrism(); + + /** + * Initializes and creates the scene of all scenes marked as initially instanced + */ + void spawnInitialScenes(); + + /** + * Respond to a cube face being activated + */ + void onActivate(int face); + + /** + * Run application login + */ + virtual bool updateLoop(float fDelta) override; + + /** + * Handle events from the server + */ + virtual bool eventListener(lumin::ServerEvent* event) override; + +private: + lumin::Prism* prism_ = nullptr; // represents the bounded space where the App renders. + PrismSceneManager* prismSceneManager_ = nullptr; + uint64_t svg_filecount_ = 0; + char** svg_filenames_ = nullptr; + lumin::NodeIDType focus_node = lumin::INVALID_NODE_ID; +}; + +extern "C" uint64_t magicleap_pathfinder_svg_filecount(); +extern "C" char** magicleap_pathfinder_svg_filenames(); diff --git a/demo/magicleap/src/lib.rs b/demo/magicleap/src/lib.rs index 08513f16..ba49e8ef 100644 --- a/demo/magicleap/src/lib.rs +++ b/demo/magicleap/src/lib.rs @@ -13,6 +13,7 @@ use pathfinder_demo::Options; use pathfinder_demo::window::Mode; use std::ffi::CString; +use std::os::raw::c_char; mod c_api; mod magicleap; @@ -56,4 +57,22 @@ pub extern "C" fn magicleap_pathfinder_demo(egl_display: EGLDisplay, egl_context } app.finish_drawing_frame(); } +} + +const SVG_FILENAMES: &[*const c_char] = &[ + &b"svg/Ghostscript_Tiger.svg\0"[0], + &b"svg/paper.svg\0"[0], + &b"svg/julius-caesar-with-bg.svg\0"[0], + &b"svg/nba-notext.svg\0"[0], + &b"svg/pathfinder_logo.svg\0"[0], +]; + +#[no_mangle] +pub extern "C" fn magicleap_pathfinder_svg_filecount() -> usize { + SVG_FILENAMES.len() +} + +#[no_mangle] +pub extern "C" fn magicleap_pathfinder_svg_filenames() -> *const *const c_char { + &SVG_FILENAMES[0] } \ No newline at end of file From 1aedbec4d71f4adc10ca73d508ee674bcfaf8f29 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Mon, 1 Apr 2019 13:13:41 -0500 Subject: [PATCH 10/32] Get landscape app to respond to clicks --- demo/magicleap/manifest.xml | 5 ++ demo/magicleap/src/landscape.cpp | 97 +++++++++++++++++++++++++++++--- demo/magicleap/src/landscape.h | 11 +++- 3 files changed, 101 insertions(+), 12 deletions(-) diff --git a/demo/magicleap/manifest.xml b/demo/magicleap/manifest.xml index 80240ff1..9ed77b74 100644 --- a/demo/magicleap/manifest.xml +++ b/demo/magicleap/manifest.xml @@ -24,6 +24,11 @@ ml:visible_name="Pathfinder Immersive Demo" ml:binary_name="bin/PathfinderImmersiveDemo" ml:type="Fullscreen"> + + + diff --git a/demo/magicleap/src/landscape.cpp b/demo/magicleap/src/landscape.cpp index 7b0d52d8..4f60dbd9 100644 --- a/demo/magicleap/src/landscape.cpp +++ b/demo/magicleap/src/landscape.cpp @@ -5,7 +5,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -17,12 +19,10 @@ int main(int argc, char **argv) return myApp.run(); } -const char* QUAD_NAMES[1] = { - "quad1" -}; +const int NUM_QUADS = 1; -const char* PANEL_NAMES[1] = { - "uiPanel1" +const char* QUAD_NAMES[NUM_QUADS] = { + "quad1" }; PathfinderDemo::PathfinderDemo() { @@ -84,6 +84,7 @@ int PathfinderDemo::init() { return 1; } + /* // Create the EGL surface for it to draw to lumin::ResourceIDType plane_id = prism_->createPlanarEGLResourceId(); if (!plane_id) { @@ -98,6 +99,7 @@ int PathfinderDemo::init() { return 1; } quad_node->setRenderResource(plane_id); + */ return 0; } @@ -141,21 +143,34 @@ bool PathfinderDemo::eventListener(lumin::ServerEvent* event) { // Place your event handling here. lumin::ServerEventType typ = event->getServerEventType(); switch (typ) { - case lumin::ServerEventType::kControlPose6DofInputEvent: + case lumin::ServerEventType::kControlPose6DofInputEvent: { requestWorldRayCast(getHeadposeWorldPosition(), getHeadposeWorldForwardVector(), 0); return false; + } case lumin::ServerEventType::kRayCastEvent: { lumin::RayCastEventData* raycast_event = static_cast(event); std::shared_ptr raycast_result = raycast_event->getHitData(); switch (raycast_result->getType()) { case lumin::RaycastResultType::kQuadNode: { std::shared_ptr quad_result = std::static_pointer_cast(raycast_result); - focus_node = quad_result->getNodeId(); + focus_node_ = quad_result->getNodeId(); return false; } - default: - focus_node = lumin::INVALID_NODE_ID; + default: { + focus_node_ = lumin::INVALID_NODE_ID; return false; + } + } + } + case lumin::ServerEventType::kGestureInputEvent: { + lumin::GestureInputEventData* gesture_event = static_cast(event); + switch (gesture_event->getGesture()) { + case lumin::input::GestureType::TriggerClick: { + return onClick(); + } + default: { + return false; + } } } default: @@ -163,3 +178,67 @@ bool PathfinderDemo::eventListener(lumin::ServerEvent* event) { } } +bool PathfinderDemo::onClick() { + lumin::RootNode* root_node = prism_->getRootNode(); + for (int i=0; ifindNode(QUAD_NAMES[i], root_node); + if (node->getNodeId() == focus_node_) { + dispatch(svg_filenames_[i]); + return true; + } + } + return false; +} + +void PathfinderDemo::dispatch(char* svg_filename) { + ML_LOG(Info, "Dispatching %s", svg_filename); + + MLDispatchPacket* dispatcher; + if (MLResult_Ok != MLDispatchAllocateEmptyPacket(&dispatcher)) { + ML_LOG(Error, "Failed to allocate dispatcher"); + return; + } + + if (MLResult_Ok != MLDispatchAllocateFileInfoList(dispatcher, 1)) { + ML_LOG(Error, "Failed to allocate file info list"); + return; + } + + MLFileInfo* file_info; + if (MLResult_Ok != MLDispatchGetFileInfoByIndex(dispatcher, 0, &file_info)) { + ML_LOG(Error, "Failed to get file info"); + return; + } + + if (MLResult_Ok != MLFileInfoSetFileName(file_info, svg_filename)) { + ML_LOG(Error, "Failed to set filename"); + return; + } + + if (MLResult_Ok != MLFileInfoSetMimeType(file_info, "image/svg")) { + ML_LOG(Error, "Failed to set mime type"); + return; + } + + if (MLResult_Ok != MLDispatchAddFileInfo(dispatcher, file_info)) { + ML_LOG(Error, "Failed to add file info"); + return; + } + + MLResult result = MLDispatchTryOpenApplication(dispatcher); + if (MLResult_Ok != result) { + ML_LOG(Error, "Failed to dispatch: %s", MLDispatchGetResultString(result)); + return; + } + + // https://forum.magicleap.com/hc/en-us/community/posts/360043198492-Calling-MLDispatchReleaseFileInfoList-causes-a-dynamic-link-error + // if (MLResult_Ok != MLDispatchReleaseFileInfoList(dispatcher, false)) { + // ML_LOG(Error, "Failed to deallocate file info list"); + // return; + // } + + if (MLResult_Ok != MLDispatchReleasePacket(&dispatcher, false, false)) { + ML_LOG(Error, "Failed to deallocate dispatcher"); + return; + } +} diff --git a/demo/magicleap/src/landscape.h b/demo/magicleap/src/landscape.h index a4191e32..40833f67 100644 --- a/demo/magicleap/src/landscape.h +++ b/demo/magicleap/src/landscape.h @@ -83,10 +83,15 @@ protected: void spawnInitialScenes(); /** - * Respond to a cube face being activated + * Respond to a click */ - void onActivate(int face); + bool onClick(); + /** + * Dispatch an SVG file to the immersive app + */ + void dispatch(char* svg_filename); + /** * Run application login */ @@ -102,7 +107,7 @@ private: PrismSceneManager* prismSceneManager_ = nullptr; uint64_t svg_filecount_ = 0; char** svg_filenames_ = nullptr; - lumin::NodeIDType focus_node = lumin::INVALID_NODE_ID; + lumin::NodeIDType focus_node_ = lumin::INVALID_NODE_ID; }; extern "C" uint64_t magicleap_pathfinder_svg_filecount(); From 685651c119f7ab838b441878750fe150fb39938b Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Tue, 9 Apr 2019 14:41:15 -0500 Subject: [PATCH 11/32] Wire up magicleap landscape demo cube faces to pathfinder demo --- Cargo.lock | 1 + demo/magicleap/lre/PathfinderDemo.draft | 1 - demo/magicleap/lre/pipeline/lap/project.json | 2 +- .../lre/scenes/PathfinderDemo.design | 1 - .../lre/scenes/PathfinderDemo.scene.xml | 2 +- demo/magicleap/src/landscape.cpp | 23 +++++-- demo/magicleap/src/landscape.h | 5 ++ demo/magicleap/src/lib.rs | 60 ++++++++++++++++ demo/magicleap/src/magicleap.rs | 69 +++++++++++++++++++ 9 files changed, 156 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fac3793c..fc401538 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/demo/magicleap/lre/PathfinderDemo.draft b/demo/magicleap/lre/PathfinderDemo.draft index 4df9e299..35c232e7 100644 --- a/demo/magicleap/lre/PathfinderDemo.draft +++ b/demo/magicleap/lre/PathfinderDemo.draft @@ -3,7 +3,6 @@ - diff --git a/demo/magicleap/lre/pipeline/lap/project.json b/demo/magicleap/lre/pipeline/lap/project.json index 599272b6..b409d80a 100644 --- a/demo/magicleap/lre/pipeline/lap/project.json +++ b/demo/magicleap/lre/pipeline/lap/project.json @@ -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", diff --git a/demo/magicleap/lre/scenes/PathfinderDemo.design b/demo/magicleap/lre/scenes/PathfinderDemo.design index 4df9e299..35c232e7 100644 --- a/demo/magicleap/lre/scenes/PathfinderDemo.design +++ b/demo/magicleap/lre/scenes/PathfinderDemo.design @@ -3,7 +3,6 @@ - diff --git a/demo/magicleap/lre/scenes/PathfinderDemo.scene.xml b/demo/magicleap/lre/scenes/PathfinderDemo.scene.xml index 10695e5d..09523fc6 100644 --- a/demo/magicleap/lre/scenes/PathfinderDemo.scene.xml +++ b/demo/magicleap/lre/scenes/PathfinderDemo.scene.xml @@ -1,6 +1,6 @@ - + diff --git a/demo/magicleap/src/landscape.cpp b/demo/magicleap/src/landscape.cpp index 4f60dbd9..ae5bcc5c 100644 --- a/demo/magicleap/src/landscape.cpp +++ b/demo/magicleap/src/landscape.cpp @@ -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) {} + diff --git a/demo/magicleap/src/landscape.h b/demo/magicleap/src/landscape.h index 40833f67..3268e25e 100644 --- a/demo/magicleap/src/landscape.h +++ b/demo/magicleap/src/landscape.h @@ -12,6 +12,7 @@ // %SRC_VERSION%: 1 +#include #include #include #include @@ -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*); diff --git a/demo/magicleap/src/lib.rs b/demo/magicleap/src/lib.rs index ba49e8ef..ef7356b2 100644 --- a/demo/magicleap/src/lib.rs +++ b/demo/magicleap/src/lib.rs @@ -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; + 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); } \ No newline at end of file diff --git a/demo/magicleap/src/magicleap.rs b/demo/magicleap/src/magicleap.rs index 345f10ce..3b55bac9 100644 --- a/demo/magicleap/src/magicleap.rs +++ b/demo/magicleap/src/magicleap.rs @@ -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 { + 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) -> 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 { From 29ef8b57e0a5421f534e32a2024ecc51c1dceee2 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Tue, 9 Apr 2019 14:33:33 -0500 Subject: [PATCH 12/32] Use pathfinder directly for magicleap demo cube faces rather than using pathfinder_demo --- demo/magicleap/lre/PathfinderDemo.draft | 5 - demo/magicleap/lre/pipeline/lap/project.json | 2 +- .../lre/scenes/PathfinderDemo.design | 5 - .../lre/scenes/PathfinderDemo.scene.xml | 10 +- demo/magicleap/src/landscape.cpp | 26 ++- demo/magicleap/src/landscape.h | 2 +- demo/magicleap/src/lib.rs | 192 ++++++++++++++---- demo/magicleap/src/magicleap.rs | 14 +- 8 files changed, 196 insertions(+), 60 deletions(-) diff --git a/demo/magicleap/lre/PathfinderDemo.draft b/demo/magicleap/lre/PathfinderDemo.draft index 35c232e7..e87e27ab 100644 --- a/demo/magicleap/lre/PathfinderDemo.draft +++ b/demo/magicleap/lre/PathfinderDemo.draft @@ -32,7 +32,6 @@ - @@ -60,7 +59,6 @@ - @@ -90,7 +88,6 @@ - @@ -120,7 +117,6 @@ - @@ -150,7 +146,6 @@ - diff --git a/demo/magicleap/lre/pipeline/lap/project.json b/demo/magicleap/lre/pipeline/lap/project.json index b409d80a..0b2d85e4 100644 --- a/demo/magicleap/lre/pipeline/lap/project.json +++ b/demo/magicleap/lre/pipeline/lap/project.json @@ -28,7 +28,7 @@ "lap/types/file/wav" ] }, - "checkpoint-hash": "be7c32a96b1e398705b53fe9c7347469ec0e17c02fae27bd9e0d37a793e00b26292244892a424e35094dbc7348da159a0518e37e24c94eb33188f6756fe25737", + "checkpoint-hash": "c518bac956221c272b076912359b67d645f00f14a76f2f9cc3dee2f71cbe4aa1f702f8fd2d19a0b3b59af6ab227b83fedcbef788077d6757a9b5e691bd0f4398", "templates": [ "lap/template/converted_texture_from_bmp", "lap/template/converted_texture_from_tga", diff --git a/demo/magicleap/lre/scenes/PathfinderDemo.design b/demo/magicleap/lre/scenes/PathfinderDemo.design index 35c232e7..e87e27ab 100644 --- a/demo/magicleap/lre/scenes/PathfinderDemo.design +++ b/demo/magicleap/lre/scenes/PathfinderDemo.design @@ -32,7 +32,6 @@ - @@ -60,7 +59,6 @@ - @@ -90,7 +88,6 @@ - @@ -120,7 +117,6 @@ - @@ -150,7 +146,6 @@ - diff --git a/demo/magicleap/lre/scenes/PathfinderDemo.scene.xml b/demo/magicleap/lre/scenes/PathfinderDemo.scene.xml index 09523fc6..fa1d7425 100644 --- a/demo/magicleap/lre/scenes/PathfinderDemo.scene.xml +++ b/demo/magicleap/lre/scenes/PathfinderDemo.scene.xml @@ -1,9 +1,9 @@ - - - - - + + + + + diff --git a/demo/magicleap/src/landscape.cpp b/demo/magicleap/src/landscape.cpp index ae5bcc5c..482512c3 100644 --- a/demo/magicleap/src/landscape.cpp +++ b/demo/magicleap/src/landscape.cpp @@ -19,10 +19,15 @@ int main(int argc, char **argv) return myApp.run(); } -const int NUM_QUADS = 1; +const int NUM_QUADS = 6; const char* QUAD_NAMES[NUM_QUADS] = { - "quad1" + "quad1", + "quad2", + "quad3", + "quad4", + "quad5", + "quad6", }; PathfinderDemo::PathfinderDemo() { @@ -75,10 +80,11 @@ int PathfinderDemo::init() { return 1; } + for (int i=0; ifindNode(QUAD_NAMES[0], root_node)); + lumin::QuadNode* quad_node = lumin::QuadNode::CastFrom(prism_->findNode(QUAD_NAMES[i], root_node)); if (!quad_node) { - ML_LOG(Error, "Pathfinder Failed to get quad node"); + ML_LOG(Error, "Pathfinder Failed to get quad node %d.", i); abort(); return 1; } @@ -105,13 +111,17 @@ int PathfinderDemo::init() { eglMakeCurrent(dpy, surf, surf, ctx); // Initialize pathfinder - ML_LOG(Info, "Pathfinder initializing"); - pathfinder_ = magicleap_pathfinder_init(); - ML_LOG(Info, "Pathfinder initialized"); + if (!pathfinder_) { + ML_LOG(Info, "Pathfinder initializing"); + pathfinder_ = magicleap_pathfinder_init(dpy, surf); + ML_LOG(Info, "Pathfinder initialized"); + } // Render the SVG - magicleap_pathfinder_render(pathfinder_, dpy, surf, svg_filenames_[0]); + magicleap_pathfinder_render(pathfinder_, dpy, surf, svg_filenames_[i % svg_filecount_]); eglSwapBuffers(dpy, surf); + } + return 0; } diff --git a/demo/magicleap/src/landscape.h b/demo/magicleap/src/landscape.h index 3268e25e..e8fd466b 100644 --- a/demo/magicleap/src/landscape.h +++ b/demo/magicleap/src/landscape.h @@ -114,6 +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_init(EGLDisplay, EGLSurface); extern "C" void magicleap_pathfinder_render(void*, EGLDisplay, EGLSurface, char*); extern "C" void magicleap_pathfinder_deinit(void*); diff --git a/demo/magicleap/src/lib.rs b/demo/magicleap/src/lib.rs index ef7356b2..c2a7dca2 100644 --- a/demo/magicleap/src/lib.rs +++ b/demo/magicleap/src/lib.rs @@ -7,6 +7,8 @@ use egl::EGLContext; use egl::EGLDisplay; use egl::EGLSurface; +use gl::types::GLuint; + use log::debug; use log::info; @@ -18,12 +20,35 @@ use pathfinder_demo::window::Mode; use pathfinder_demo::window::SVGPath; use pathfinder_demo::window::WindowSize; use pathfinder_geometry::basic::point::Point2DI32; +use pathfinder_geometry::basic::point::Point2DF32; +use pathfinder_geometry::basic::rect::RectI32; +use pathfinder_geometry::basic::transform2d::Transform2DF32; +use pathfinder_gl::GLDevice; +use pathfinder_gl::GLVersion; +use pathfinder_gpu::Device; +use pathfinder_gpu::resources::FilesystemResourceLoader; +use pathfinder_renderer::gpu::renderer::Renderer; +use pathfinder_simd::default::F32x4; +use pathfinder_renderer::scene::Scene; +use pathfinder_renderer::z_buffer::ZBuffer; +use pathfinder_renderer::gpu_data::BuiltScene; +use pathfinder_renderer::builder::SceneBuilder; +use pathfinder_renderer::builder::RenderOptions; +use pathfinder_renderer::builder::RenderTransform; +use pathfinder_svg::BuiltSVG; +use pathfinder_gpu::resources::ResourceLoader; +use rayon::ThreadPoolBuilder; + +use std::collections::HashMap; use std::ffi::CStr; use std::ffi::CString; use std::os::raw::c_char; use std::os::raw::c_void; +use usvg::Options as UsvgOptions; +use usvg::Tree; + mod c_api; mod magicleap; @@ -69,10 +94,11 @@ pub extern "C" fn magicleap_pathfinder_demo(egl_display: EGLDisplay, egl_context } const SVG_FILENAMES: &[*const c_char] = &[ - &b"svg/Ghostscript_Tiger.svg\0"[0], - &b"svg/paper.svg\0"[0], - &b"svg/julius-caesar-with-bg.svg\0"[0], &b"svg/nba-notext.svg\0"[0], + &b"svg/paper.svg\0"[0], + &b"svg/Ghostscript_Tiger.svg\0"[0], + &b"svg/julius-caesar-with-bg.svg\0"[0], + &b"svg/julius-caesar.svg\0"[0], &b"svg/pathfinder_logo.svg\0"[0], ]; @@ -86,8 +112,22 @@ pub extern "C" fn magicleap_pathfinder_svg_filenames() -> *const *const c_char { &SVG_FILENAMES[0] } +struct MagicLeapPathfinder { + surfaces: HashMap, + resources: FilesystemResourceLoader, +} + +struct MagicLeapPathfinderSurface { + surf: EGLSurface, + size: Point2DI32, + viewport: RectI32, + bg_color: F32x4, + renderer: Renderer, + scene: Scene, +} + #[no_mangle] -pub extern "C" fn magicleap_pathfinder_init() -> *mut c_void { +pub extern "C" fn magicleap_pathfinder_init(dpy: EGLDisplay, surf: EGLSurface) -> *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(); @@ -97,42 +137,126 @@ pub extern "C" fn magicleap_pathfinder_init() -> *mut c_void { 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"); + let mut thread_pool_builder = ThreadPoolBuilder::new() + .build_global().unwrap(); + info!("Initialized rayon"); + + gl::load_with(|s| egl::get_proc_address(s) as *const c_void); + info!("Initialized gl"); - Box::into_raw(Box::new(app)) as *mut c_void + let pf = MagicLeapPathfinder { + surfaces: HashMap::new(), + resources: FilesystemResourceLoader::locate(), + }; + info!("Initialized pf"); + + Box::into_raw(Box::new(pf)) 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; - 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(); +pub unsafe extern "C" fn magicleap_pathfinder_render(pf: *mut c_void, dpy: EGLDisplay, surf: EGLSurface, svg_filename: *const c_char) { + let pf = pf as *mut MagicLeapPathfinder; + if let Some(pf) = pf.as_mut() { + let resources = &pf.resources; + let pfs = pf.surfaces.entry(surf).or_insert_with(|| { + let mut width = 0; + let mut height = 0; + let mut fbo = 0; + egl::query_surface(dpy, surf, egl::EGL_WIDTH, &mut width); + egl::query_surface(dpy, surf, egl::EGL_HEIGHT, &mut height); + gl::GetIntegerv(gl::DRAW_FRAMEBUFFER_BINDING, &mut fbo); + let device = GLDevice::new(GLVersion::GLES3, fbo as GLuint); + let size = Point2DI32::new(width, height); + let viewport = RectI32::new(Point2DI32::default(), size); + let renderer = Renderer::new(device, resources, viewport, size); + let bg_color = F32x4::new(0.5, 0.5, 0.5, 1.0); + let svg_filename = CStr::from_ptr(svg_filename).to_string_lossy(); + let data = resources.slurp(&*svg_filename).unwrap(); + let svg = BuiltSVG::from_tree(Tree::from_data(&data, &UsvgOptions::default()).unwrap()); + let mut scene = svg.scene; + scene.view_box = viewport.to_f32(); + MagicLeapPathfinderSurface { + surf, + size, + viewport, + bg_color, + renderer, + scene, + } + }); + pfs.renderer.set_main_framebuffer_size(pfs.size); + pfs.renderer.set_viewport(pfs.viewport); + pfs.renderer.device.bind_default_framebuffer(pfs.viewport); + pfs.renderer.device.clear(Some(pfs.bg_color), Some(1.0), Some(0)); + pfs.renderer.disable_depth(); + + let z_buffer = ZBuffer::new(pfs.scene.view_box); + + let scale = i32::min(pfs.viewport.size().x(), pfs.viewport.size().y()) as f32 / + f32::max(pfs.scene.bounds.size().x(), pfs.scene.bounds.size().y()); + let transform = Transform2DF32::from_translation(&pfs.scene.bounds.size().scale(-0.5)) + .post_mul(&Transform2DF32::from_scale(&Point2DF32::splat(scale))) + .post_mul(&Transform2DF32::from_translation(&pfs.viewport.size().to_f32().scale(0.5))); + + let render_options = RenderOptions { + transform: RenderTransform::Transform2D(transform), + dilation: Point2DF32::default(), + barrel_distortion: None, + }; + + let built_options = render_options.prepare(pfs.scene.bounds); + let quad = built_options.quad(); + + let built_objects = pfs.scene.build_objects(built_options, &z_buffer); + + let mut built_scene = BuiltScene::new(pfs.scene.view_box, &quad, pfs.scene.objects.len() as u32); + built_scene.shaders = pfs.scene.build_shaders(); + + let mut scene_builder = SceneBuilder::new(built_objects, z_buffer, pfs.scene.view_box); + built_scene.solid_tiles = scene_builder.build_solid_tiles(); + while let Some(batch) = scene_builder.build_batch() { + built_scene.batches.push(batch); + } + + pfs.renderer.render_scene(&built_scene); + + // let mut width = 0; + // let mut height = 0; + // let mut fbo = 0; + // egl::query_surface(dpy, surf, egl::EGL_WIDTH, &mut width); + // egl::query_surface(dpy, surf, egl::EGL_HEIGHT, &mut height); + // gl::GetIntegerv(gl::DRAW_FRAMEBUFFER_BINDING, &mut fbo); + // gl::Viewport(0, 0, width, height); + // let svg_filename = CStr::from_ptr(svg_filename).to_string_lossy().into_owned(); + // info!("svg={}, w={}, h={}, fbo={}.", svg_filename, width, height, fbo); + // if (app.window.dpy != dpy) || (app.window.surf != surf) { + // app.render_to_current_gl_context(); + // app.window.surf = surf; + // app.window.dpy = dpy; + // } + // app.window.fbo = fbo as GLuint; + // app.window.set_size(width, height); + // app.options.background = if let Background::Dark = app.options.background { + // Background::Light + // } else { + // Background::Dark + // }; + // 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(); + // while app.dirty { + // 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); +pub unsafe extern "C" fn magicleap_pathfinder_deinit(pf: *mut c_void) { + Box::from_raw(pf as *mut MagicLeapPathfinder); } \ No newline at end of file diff --git a/demo/magicleap/src/magicleap.rs b/demo/magicleap/src/magicleap.rs index 3b55bac9..5b196f49 100644 --- a/demo/magicleap/src/magicleap.rs +++ b/demo/magicleap/src/magicleap.rs @@ -35,6 +35,7 @@ use egl; use egl::EGL_NO_SURFACE; use egl::EGLContext; use egl::EGLDisplay; +use egl::EGLSurface; use gl; use gl::types::GLuint; @@ -298,6 +299,9 @@ impl Drop for MagicLeapWindow { // Magic Leap landscape app pub struct MagicLeapLandscape { + pub dpy: EGLDisplay, + pub surf: EGLSurface, + pub fbo: GLuint, size: Point2DI32, resource_loader: FilesystemResourceLoader, } @@ -311,6 +315,10 @@ impl Window for MagicLeapLandscape { GLVersion::GLES3 } + fn gl_default_framebuffer(&self) -> GLuint { + self.fbo + } + fn mouse_position(&self) -> Point2DI32 { Point2DI32::new(0, 0) } @@ -342,11 +350,15 @@ impl Window for MagicLeapLandscape { } impl MagicLeapLandscape { - pub fn new() -> MagicLeapLandscape { + pub fn new(dpy: EGLDisplay, surf: EGLSurface) -> MagicLeapLandscape { gl::load_with(get_proc_address); let size = Point2DI32::new(512, 512); + let fbo = 0; let resource_loader = FilesystemResourceLoader::locate(); MagicLeapLandscape { + dpy, + surf, + fbo, size, resource_loader, } From 9fd479d60435665beb4bdfaf4a5b57640ac7192b Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Thu, 4 Apr 2019 11:21:41 -0500 Subject: [PATCH 13/32] Expose a C API for getting pathfinder to render to an EGL surface --- demo/magicleap/src/landscape.cpp | 32 ++++-- demo/magicleap/src/landscape.h | 18 ++-- demo/magicleap/src/lib.rs | 161 ++++++++++++------------------- 3 files changed, 96 insertions(+), 115 deletions(-) diff --git a/demo/magicleap/src/landscape.cpp b/demo/magicleap/src/landscape.cpp index 482512c3..798d81b9 100644 --- a/demo/magicleap/src/landscape.cpp +++ b/demo/magicleap/src/landscape.cpp @@ -30,12 +30,19 @@ const char* QUAD_NAMES[NUM_QUADS] = { "quad6", }; +const char* SVG_NAMES[NUM_QUADS] = { + "svg/nba-notext.svg", + "svg/paper.svg", + "svg/Ghostscript_Tiger.svg", + "svg/julius-caesar-with-bg.svg", + "svg/julius-caesar.svg", + "svg/pathfinder_logo.svg", +}; + PathfinderDemo::PathfinderDemo() { ML_LOG(Debug, "PathfinderDemo Constructor."); // Place your constructor implementation here. - svg_filecount_ = magicleap_pathfinder_svg_filecount(); - svg_filenames_ = magicleap_pathfinder_svg_filenames(); } PathfinderDemo::~PathfinderDemo() { @@ -113,12 +120,23 @@ int PathfinderDemo::init() { // Initialize pathfinder if (!pathfinder_) { ML_LOG(Info, "Pathfinder initializing"); - pathfinder_ = magicleap_pathfinder_init(dpy, surf); + pathfinder_ = magicleap_pathfinder_init(); ML_LOG(Info, "Pathfinder initialized"); } + uint32_t width = plane->getWidth(); + uint32_t height = plane->getHeight(); + // Render the SVG - magicleap_pathfinder_render(pathfinder_, dpy, surf, svg_filenames_[i % svg_filecount_]); + MagicLeapPathfinderRenderOptions options = { + dpy, + surf, + { 0.5, 0.5, 0.5, 1.0 }, + { 0, 0, width, height }, + SVG_NAMES[i], + }; + + magicleap_pathfinder_render(pathfinder_, &options); eglSwapBuffers(dpy, surf); } @@ -202,17 +220,17 @@ bool PathfinderDemo::eventListener(lumin::ServerEvent* event) { bool PathfinderDemo::onClick() { lumin::RootNode* root_node = prism_->getRootNode(); - for (int i=0; ifindNode(QUAD_NAMES[i], root_node); if (node->getNodeId() == focus_node_) { - dispatch(svg_filenames_[i]); + dispatch(SVG_NAMES[i]); return true; } } return false; } -void PathfinderDemo::dispatch(char* svg_filename) { +void PathfinderDemo::dispatch(const char* svg_filename) { ML_LOG(Info, "Dispatching %s", svg_filename); MLDispatchPacket* dispatcher; diff --git a/demo/magicleap/src/landscape.h b/demo/magicleap/src/landscape.h index e8fd466b..b79f1f7b 100644 --- a/demo/magicleap/src/landscape.h +++ b/demo/magicleap/src/landscape.h @@ -91,7 +91,7 @@ protected: /** * Dispatch an SVG file to the immersive app */ - void dispatch(char* svg_filename); + void dispatch(const char* svg_filename); /** * Run application login @@ -107,13 +107,17 @@ 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; }; -extern "C" uint64_t magicleap_pathfinder_svg_filecount(); -extern "C" char** magicleap_pathfinder_svg_filenames(); -extern "C" void* magicleap_pathfinder_init(EGLDisplay, EGLSurface); -extern "C" void magicleap_pathfinder_render(void*, EGLDisplay, EGLSurface, char*); +typedef struct MagicLeapPathfinderRenderOptions { + EGLDisplay display; + EGLSurface surface; + float bg_color[4]; + uint32_t viewport[4]; + const char* svg_filename; +} MagicLeapPathfinderRenderOptions; + +extern "C" void* magicleap_pathfinder_init(); +extern "C" void magicleap_pathfinder_render(void*, MagicLeapPathfinderRenderOptions*); extern "C" void magicleap_pathfinder_deinit(void*); diff --git a/demo/magicleap/src/lib.rs b/demo/magicleap/src/lib.rs index c2a7dca2..b5680569 100644 --- a/demo/magicleap/src/lib.rs +++ b/demo/magicleap/src/lib.rs @@ -93,27 +93,9 @@ pub extern "C" fn magicleap_pathfinder_demo(egl_display: EGLDisplay, egl_context } } -const SVG_FILENAMES: &[*const c_char] = &[ - &b"svg/nba-notext.svg\0"[0], - &b"svg/paper.svg\0"[0], - &b"svg/Ghostscript_Tiger.svg\0"[0], - &b"svg/julius-caesar-with-bg.svg\0"[0], - &b"svg/julius-caesar.svg\0"[0], - &b"svg/pathfinder_logo.svg\0"[0], -]; - -#[no_mangle] -pub extern "C" fn magicleap_pathfinder_svg_filecount() -> usize { - SVG_FILENAMES.len() -} - -#[no_mangle] -pub extern "C" fn magicleap_pathfinder_svg_filenames() -> *const *const c_char { - &SVG_FILENAMES[0] -} - struct MagicLeapPathfinder { - surfaces: HashMap, + renderers: HashMap<(EGLSurface, EGLDisplay), Renderer>, + svgs: HashMap, resources: FilesystemResourceLoader, } @@ -126,8 +108,17 @@ struct MagicLeapPathfinderSurface { scene: Scene, } +#[repr(C)] +pub struct MagicLeapPathfinderRenderOptions { + display: EGLDisplay, + surface: EGLSurface, + bg_color: [f32; 4], + viewport: [u32; 4], + svg_filename: *const c_char, +} + #[no_mangle] -pub extern "C" fn magicleap_pathfinder_init(dpy: EGLDisplay, surf: EGLSurface) -> *mut c_void { +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(); @@ -145,7 +136,8 @@ pub extern "C" fn magicleap_pathfinder_init(dpy: EGLDisplay, surf: EGLSurface) - info!("Initialized gl"); let pf = MagicLeapPathfinder { - surfaces: HashMap::new(), + renderers: HashMap::new(), + svgs: HashMap::new(), resources: FilesystemResourceLoader::locate(), }; info!("Initialized pf"); @@ -154,49 +146,52 @@ pub extern "C" fn magicleap_pathfinder_init(dpy: EGLDisplay, surf: EGLSurface) - } #[no_mangle] -pub unsafe extern "C" fn magicleap_pathfinder_render(pf: *mut c_void, dpy: EGLDisplay, surf: EGLSurface, svg_filename: *const c_char) { +pub unsafe extern "C" fn magicleap_pathfinder_render(pf: *mut c_void, options: *const MagicLeapPathfinderRenderOptions) { let pf = pf as *mut MagicLeapPathfinder; - if let Some(pf) = pf.as_mut() { + if let (Some(pf), Some(options)) = (pf.as_mut(), options.as_ref()) { let resources = &pf.resources; - let pfs = pf.surfaces.entry(surf).or_insert_with(|| { - let mut width = 0; - let mut height = 0; - let mut fbo = 0; - egl::query_surface(dpy, surf, egl::EGL_WIDTH, &mut width); - egl::query_surface(dpy, surf, egl::EGL_HEIGHT, &mut height); - gl::GetIntegerv(gl::DRAW_FRAMEBUFFER_BINDING, &mut fbo); - let device = GLDevice::new(GLVersion::GLES3, fbo as GLuint); - let size = Point2DI32::new(width, height); - let viewport = RectI32::new(Point2DI32::default(), size); - let renderer = Renderer::new(device, resources, viewport, size); - let bg_color = F32x4::new(0.5, 0.5, 0.5, 1.0); - let svg_filename = CStr::from_ptr(svg_filename).to_string_lossy(); + + let svg_filename = CStr::from_ptr(options.svg_filename).to_string_lossy().into_owned(); + let svg = pf.svgs.entry(svg_filename).or_insert_with(|| { + let svg_filename = CStr::from_ptr(options.svg_filename).to_string_lossy(); let data = resources.slurp(&*svg_filename).unwrap(); - let svg = BuiltSVG::from_tree(Tree::from_data(&data, &UsvgOptions::default()).unwrap()); - let mut scene = svg.scene; - scene.view_box = viewport.to_f32(); - MagicLeapPathfinderSurface { - surf, - size, - viewport, - bg_color, - renderer, - scene, - } - }); - pfs.renderer.set_main_framebuffer_size(pfs.size); - pfs.renderer.set_viewport(pfs.viewport); - pfs.renderer.device.bind_default_framebuffer(pfs.viewport); - pfs.renderer.device.clear(Some(pfs.bg_color), Some(1.0), Some(0)); - pfs.renderer.disable_depth(); + let tree = Tree::from_data(&data, &UsvgOptions::default()).unwrap(); + BuiltSVG::from_tree(tree) + }); - let z_buffer = ZBuffer::new(pfs.scene.view_box); + let mut width = 0; + let mut height = 0; + egl::query_surface(options.display, options.surface, egl::EGL_WIDTH, &mut width); + egl::query_surface(options.display, options.surface, egl::EGL_HEIGHT, &mut height); + let size = Point2DI32::new(width, height); - let scale = i32::min(pfs.viewport.size().x(), pfs.viewport.size().y()) as f32 / - f32::max(pfs.scene.bounds.size().x(), pfs.scene.bounds.size().y()); - let transform = Transform2DF32::from_translation(&pfs.scene.bounds.size().scale(-0.5)) + let viewport_origin = Point2DI32::new(options.viewport[0] as i32, options.viewport[1] as i32); + let viewport_size = Point2DI32::new(options.viewport[2] as i32, options.viewport[3] as i32); + let viewport = RectI32::new(viewport_origin, viewport_size); + + let renderer = pf.renderers.entry((options.display, options.surface)).or_insert_with(|| { + let mut fbo = 0; + gl::GetIntegerv(gl::DRAW_FRAMEBUFFER_BINDING, &mut fbo); + let device = GLDevice::new(GLVersion::GLES3, fbo as GLuint); + Renderer::new(device, resources, viewport, size) + }); + + let bg_color = F32x4::new(options.bg_color[0], options.bg_color[1], options.bg_color[2], options.bg_color[3]); + + svg.scene.view_box = viewport.to_f32(); + renderer.set_main_framebuffer_size(size); + renderer.set_viewport(viewport); + renderer.device.bind_default_framebuffer(viewport); + renderer.device.clear(Some(bg_color), Some(1.0), Some(0)); + renderer.disable_depth(); + + let z_buffer = ZBuffer::new(svg.scene.view_box); + + let scale = i32::min(viewport_size.x(), viewport_size.y()) as f32 / + f32::max(svg.scene.bounds.size().x(), svg.scene.bounds.size().y()); + let transform = Transform2DF32::from_translation(&svg.scene.bounds.size().scale(-0.5)) .post_mul(&Transform2DF32::from_scale(&Point2DF32::splat(scale))) - .post_mul(&Transform2DF32::from_translation(&pfs.viewport.size().to_f32().scale(0.5))); + .post_mul(&Transform2DF32::from_translation(&viewport_size.to_f32().scale(0.5))); let render_options = RenderOptions { transform: RenderTransform::Transform2D(transform), @@ -204,55 +199,19 @@ pub unsafe extern "C" fn magicleap_pathfinder_render(pf: *mut c_void, dpy: EGLDi barrel_distortion: None, }; - let built_options = render_options.prepare(pfs.scene.bounds); + let built_options = render_options.prepare(svg.scene.bounds); let quad = built_options.quad(); + let built_objects = svg.scene.build_objects(built_options, &z_buffer); + let mut scene_builder = SceneBuilder::new(built_objects, z_buffer, svg.scene.view_box); + let mut built_scene = BuiltScene::new(svg.scene.view_box, &quad, svg.scene.objects.len() as u32); - let built_objects = pfs.scene.build_objects(built_options, &z_buffer); - - let mut built_scene = BuiltScene::new(pfs.scene.view_box, &quad, pfs.scene.objects.len() as u32); - built_scene.shaders = pfs.scene.build_shaders(); - - let mut scene_builder = SceneBuilder::new(built_objects, z_buffer, pfs.scene.view_box); + built_scene.shaders = svg.scene.build_shaders(); built_scene.solid_tiles = scene_builder.build_solid_tiles(); while let Some(batch) = scene_builder.build_batch() { built_scene.batches.push(batch); } - pfs.renderer.render_scene(&built_scene); - - // let mut width = 0; - // let mut height = 0; - // let mut fbo = 0; - // egl::query_surface(dpy, surf, egl::EGL_WIDTH, &mut width); - // egl::query_surface(dpy, surf, egl::EGL_HEIGHT, &mut height); - // gl::GetIntegerv(gl::DRAW_FRAMEBUFFER_BINDING, &mut fbo); - // gl::Viewport(0, 0, width, height); - // let svg_filename = CStr::from_ptr(svg_filename).to_string_lossy().into_owned(); - // info!("svg={}, w={}, h={}, fbo={}.", svg_filename, width, height, fbo); - // if (app.window.dpy != dpy) || (app.window.surf != surf) { - // app.render_to_current_gl_context(); - // app.window.surf = surf; - // app.window.dpy = dpy; - // } - // app.window.fbo = fbo as GLuint; - // app.window.set_size(width, height); - // app.options.background = if let Background::Dark = app.options.background { - // Background::Light - // } else { - // Background::Dark - // }; - // 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(); - // while app.dirty { - // app.prepare_frame(vec![]); - // app.draw_scene(0); - // app.finish_drawing_frame(); - // } + renderer.render_scene(&built_scene); } } From 6f5a72229c6c8aa9263b9e4c0a113ac1ac353bc2 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Thu, 4 Apr 2019 12:00:06 -0500 Subject: [PATCH 14/32] Add focusing to the magicleap demo cube --- demo/magicleap/src/landscape.cpp | 67 +++++++++++++++++++++++++------- demo/magicleap/src/landscape.h | 13 ++++++- 2 files changed, 63 insertions(+), 17 deletions(-) diff --git a/demo/magicleap/src/landscape.cpp b/demo/magicleap/src/landscape.cpp index 798d81b9..0498fc7f 100644 --- a/demo/magicleap/src/landscape.cpp +++ b/demo/magicleap/src/landscape.cpp @@ -19,8 +19,6 @@ int main(int argc, char **argv) return myApp.run(); } -const int NUM_QUADS = 6; - const char* QUAD_NAMES[NUM_QUADS] = { "quad1", "quad2", @@ -95,6 +93,7 @@ int PathfinderDemo::init() { abort(); return 1; } + quad_nodes_[i] = quad_node->getNodeId(); // Create the EGL surface for it to draw to lumin::ResourceIDType plane_id = prism_->createPlanarEGLResourceId(); @@ -103,19 +102,35 @@ int PathfinderDemo::init() { abort(); return 1; } - lumin::PlanarResource* plane = static_cast(prism_->getResource(plane_id)); + quad_node->setRenderResource(plane_id); + + renderNode(quad_node->getNodeId()); + } + + return 0; +} + +void PathfinderDemo::renderNode(lumin::NodeIDType node_id) { + if (node_id == lumin::INVALID_NODE_ID) { return; } + + lumin::QuadNode* quad_node = static_cast(prism_->getNode(node_id)); + if (!quad_node) { + ML_LOG(Error, "Pathfinder Failed to get quad node"); + return; + } + + lumin::PlanarResource* plane = const_cast(static_cast(quad_node->getRenderResource())); if (!plane) { ML_LOG(Error, "Pathfinder Failed to get plane"); - abort(); - return 1; + return; } - quad_node->setRenderResource(plane_id); - + // Get the EGL context, surface and display. + uint32_t width = plane->getWidth(); + uint32_t height = plane->getHeight(); EGLContext ctx = plane->getEGLContext(); EGLSurface surf = plane->getEGLSurface(); EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); - eglMakeCurrent(dpy, surf, surf, ctx); // Initialize pathfinder if (!pathfinder_) { @@ -124,23 +139,39 @@ int PathfinderDemo::init() { ML_LOG(Info, "Pathfinder initialized"); } - uint32_t width = plane->getWidth(); - uint32_t height = plane->getHeight(); + // Get the SVG filename + const char* svg_filename; + for (int i=0; i #include +const uint32_t NUM_QUADS = 6; + /** * PathfinderDemo Landscape Application */ @@ -92,7 +94,12 @@ protected: * Dispatch an SVG file to the immersive app */ void dispatch(const char* svg_filename); - + + /** + * Render a node in the scene + */ + void renderNode(lumin::NodeIDType node_id); + /** * Run application login */ @@ -106,7 +113,9 @@ protected: private: lumin::Prism* prism_ = nullptr; // represents the bounded space where the App renders. PrismSceneManager* prismSceneManager_ = nullptr; - void* pathfinder_ = nullptr; + void* pathfinder_ = nullptr; + lumin::NodeIDType quad_nodes_[NUM_QUADS] = {lumin::INVALID_NODE_ID}; + lumin::NodeIDType highlighted_node_ = lumin::INVALID_NODE_ID; lumin::NodeIDType focus_node_ = lumin::INVALID_NODE_ID; }; From 3bd825196efdcdefb6114a24cd5454f944740306 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Thu, 4 Apr 2019 12:55:24 -0500 Subject: [PATCH 15/32] Get the magicleap immersive mode demo to take a filename argument --- demo/magicleap/src/lib.rs | 8 ++++-- demo/magicleap/src/main.cpp | 50 ++++++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/demo/magicleap/src/lib.rs b/demo/magicleap/src/lib.rs index b5680569..546ed394 100644 --- a/demo/magicleap/src/lib.rs +++ b/demo/magicleap/src/lib.rs @@ -56,7 +56,7 @@ mod magicleap; mod mocked_c_api; #[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]) }; let tag = CString::new("Pathfinder Demo").unwrap(); @@ -75,7 +75,11 @@ pub extern "C" fn magicleap_pathfinder_demo(egl_display: EGLDisplay, egl_context options.mode = Mode::VR; options.jobs = Some(3); 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); debug!("Initialized app"); diff --git a/demo/magicleap/src/main.cpp b/demo/magicleap/src/main.cpp index 6de3d895..d526e414 100644 --- a/demo/magicleap/src/main.cpp +++ b/demo/magicleap/src/main.cpp @@ -24,12 +24,13 @@ #include #include #include +#include #include #include #include // 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 extern "C" void init_scene_thread(uint64_t id) { @@ -181,13 +182,56 @@ int main() { 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! - ML_LOG(Info, "%s: Begin demo.", application_name); - MLResult status = magicleap_pathfinder_demo(graphics_context.egl_display, graphics_context.egl_context); + ML_LOG(Info, "%s: Begin demo (%s).", application_name, file_name); + 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); // Shut down MLPerceptionShutdown(); + MLLifecycleFreeInitArgList(&arg_list); return 0; } From 1c1eaf20d16ad6d8694cb2a7a9bfee2fc7519909 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Thu, 4 Apr 2019 17:09:34 -0500 Subject: [PATCH 16/32] Get the magicleap immersive demo to respond to new file name arguments --- demo/magicleap/manifest.xml | 4 +- demo/magicleap/src/lib.rs | 60 ++++++++++----- demo/magicleap/src/main.cpp | 144 +++++++++++++++++++----------------- 3 files changed, 120 insertions(+), 88 deletions(-) diff --git a/demo/magicleap/manifest.xml b/demo/magicleap/manifest.xml index 9ed77b74..a0c9d703 100644 --- a/demo/magicleap/manifest.xml +++ b/demo/magicleap/manifest.xml @@ -12,7 +12,7 @@ diff --git a/demo/magicleap/src/lib.rs b/demo/magicleap/src/lib.rs index 546ed394..6715ff02 100644 --- a/demo/magicleap/src/lib.rs +++ b/demo/magicleap/src/lib.rs @@ -45,6 +45,7 @@ use std::ffi::CStr; use std::ffi::CString; use std::os::raw::c_char; use std::os::raw::c_void; +use std::sync::mpsc; use usvg::Options as UsvgOptions; use usvg::Tree; @@ -55,8 +56,14 @@ mod magicleap; #[cfg(feature = "mocked")] mod mocked_c_api; +struct ImmersiveApp { + sender: mpsc::Sender, + receiver: mpsc::Receiver, + demo: DemoApp, +} + #[no_mangle] -pub unsafe extern "C" fn magicleap_pathfinder_demo(egl_display: EGLDisplay, egl_context: EGLContext, file_name: *const c_char) { +pub unsafe extern "C" fn magicleap_pathfinder_demo_init(egl_display: EGLDisplay, egl_context: EGLContext) -> *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(); @@ -64,7 +71,7 @@ pub unsafe extern "C" fn magicleap_pathfinder_demo(egl_display: EGLDisplay, egl_ let logger = MagicLeapLogger::new(tag, level); log::set_boxed_logger(Box::new(logger)).unwrap(); log::set_max_level(level); - debug!("Initialized logging"); + info!("Initialized logging"); let window = MagicLeapWindow::new(egl_display, egl_context); let window_size = window.size(); @@ -75,25 +82,42 @@ pub unsafe extern "C" fn magicleap_pathfinder_demo(egl_display: EGLDisplay, egl_ options.mode = Mode::VR; options.jobs = Some(3); 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); - debug!("Initialized app"); + let demo = DemoApp::new(window, window_size, options); + info!("Initialized app"); - while app.window.running() { - let mut events = Vec::new(); - while let Some(event) = app.window.try_get_event() { - events.push(event); - } + let (sender, receiver) = mpsc::channel(); + Box::into_raw(Box::new(ImmersiveApp { sender, receiver, demo })) as *mut c_void +} - let scene_count = app.prepare_frame(events); - for scene_index in 0..scene_count { - app.draw_scene(scene_index); - } - app.finish_drawing_frame(); +#[no_mangle] +pub unsafe extern "C" fn magicleap_pathfinder_demo_run(app: *mut c_void) { + let app = app as *mut ImmersiveApp; + if let Some(app) = app.as_mut() { + while app.demo.window.running() { + let mut events = Vec::new(); + while let Some(event) = app.demo.window.try_get_event() { + events.push(event); + } + while let Ok(event) = app.receiver.try_recv() { + events.push(event); + } + let scene_count = app.demo.prepare_frame(events); + for scene_index in 0..scene_count { + app.demo.draw_scene(scene_index); + } + app.demo.finish_drawing_frame(); + } + } +} + +#[no_mangle] +pub unsafe extern "C" fn magicleap_pathfinder_demo_load(app: *mut c_void, svg_filename: *const c_char) { + let app = app as *mut ImmersiveApp; + if let Some(app) = app.as_mut() { + let svg_filename = CStr::from_ptr(svg_filename).to_string_lossy().into_owned(); + info!("Loading {}.", svg_filename); + let _ = app.sender.send(Event::OpenSVG(SVGPath::Resource(svg_filename))); } } diff --git a/demo/magicleap/src/main.cpp b/demo/magicleap/src/main.cpp index d526e414..2f547a9f 100644 --- a/demo/magicleap/src/main.cpp +++ b/demo/magicleap/src/main.cpp @@ -29,8 +29,10 @@ #include #include -// Entry point to the Rust code -extern "C" MLResult magicleap_pathfinder_demo(EGLDisplay egl_display, EGLContext egl_context, const char* file_name); +// Entry points to the Rust code +extern "C" void* magicleap_pathfinder_demo_init(EGLDisplay egl_display, EGLContext egl_context); +extern "C" void magicleap_pathfinder_demo_load(void* app, const char* file_name); +extern "C" void magicleap_pathfinder_demo_run(void* app); // Initialization of the scene thread extern "C" void init_scene_thread(uint64_t id) { @@ -47,10 +49,6 @@ extern "C" void init_scene_thread(uint64_t id) { const char application_name[] = "com.mozilla.pathfinder.demo"; // Structures -struct application_context_t { - int dummy_value; -}; - struct graphics_context_t { EGLDisplay egl_display; @@ -116,24 +114,72 @@ graphics_context_t::~graphics_context_t() { } // Callbacks -static void onStop(void* application_context) +static void onStop(void* app) { - ((struct application_context_t*)application_context)->dummy_value = 0; ML_LOG(Info, "%s: On stop called.", application_name); } -static void onPause(void* application_context) +static void onPause(void* app) { - ((struct application_context_t*)application_context)->dummy_value = 1; ML_LOG(Info, "%s: On pause called.", application_name); } -static void onResume(void* application_context) +static void onResume(void* app) { - ((struct application_context_t*)application_context)->dummy_value = 2; ML_LOG(Info, "%s: On resume called.", application_name); } +static void onNewInitArg(void* app) +{ + ML_LOG(Info, "%s: On new init arg called.", application_name); + + // 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; + } + + if (MLResult_Ok != MLLifecycleGetInitArgListLength(arg_list, &arg_list_len)) { + ML_LOG(Error, "%s: Failed to get init arg length.", application_name); + return; + } + + if (arg_list_len) { + if (MLResult_Ok != MLLifecycleGetInitArgByIndex(arg_list, 0, &arg)) { + ML_LOG(Error, "%s: Failed to get init arg.", application_name); + return; + } + + if (MLResult_Ok != MLLifecycleGetFileInfoListLength(arg, &file_list_len)) { + ML_LOG(Error, "%s: Failed to get file list length.", application_name); + return; + } + } + + if (file_list_len) { + if (MLResult_Ok != MLLifecycleGetFileInfoByIndex(arg, 0, &file_info)) { + ML_LOG(Error, "%s: Failed to get file info.", application_name); + return; + } + + if (MLResult_Ok != MLFileInfoGetFileName(file_info, &file_name)) { + ML_LOG(Error, "%s: Failed to get file name.", application_name); + return; + } + } + + // Tell pathfinder to load the file + magicleap_pathfinder_demo_load(app, file_name); + MLLifecycleFreeInitArgList(&arg_list); +} + extern "C" void logMessage(MLLogLevel lvl, char* msg) { if (MLLoggingLogLevelIsEnabled(lvl)) { MLLoggingLog(lvl, ML_DEFAULT_LOG_TAG, msg); @@ -144,20 +190,7 @@ int main() { // set up host-specific graphics surface graphics_context_t graphics_context; - // let system know our app has started - MLLifecycleCallbacks lifecycle_callbacks = {}; - lifecycle_callbacks.on_stop = onStop; - lifecycle_callbacks.on_pause = onPause; - lifecycle_callbacks.on_resume = onResume; - - struct application_context_t application_context; - application_context.dummy_value = 2; - - if (MLResult_Ok != MLLifecycleInit(&lifecycle_callbacks, (void*)&application_context)) { - ML_LOG(Error, "%s: Failed to initialize lifecycle.", application_name); - return -1; - } - + // Check privileges if (MLResult_Ok != MLPrivilegesStartup()) { ML_LOG(Error, "%s: Failed to initialize privileges.", application_name); return -1; @@ -182,56 +215,31 @@ int main() { 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); + // Initialize pathfinder + void* app = magicleap_pathfinder_demo_init(graphics_context.egl_display, graphics_context.egl_context); + + // let system know our app has started + MLLifecycleCallbacks lifecycle_callbacks = {}; + lifecycle_callbacks.on_stop = onStop; + lifecycle_callbacks.on_pause = onPause; + lifecycle_callbacks.on_resume = onResume; + lifecycle_callbacks.on_new_initarg = onNewInitArg; + + if (MLResult_Ok != MLLifecycleInit(&lifecycle_callbacks, app)) { + ML_LOG(Error, "%s: Failed to initialize lifecycle.", 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; - } - } + // Get the initial argument if there is one. + onNewInitArg(app); // Run the demo! - ML_LOG(Info, "%s: Begin demo (%s).", application_name, file_name); - 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: Begin demo.", application_name); + magicleap_pathfinder_demo_run(app); + ML_LOG(Info, "%s: End demo.", application_name); // Shut down MLPerceptionShutdown(); - MLLifecycleFreeInitArgList(&arg_list); return 0; } From bd70cb0135a51a1039339e2503edd508729c4328 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Fri, 5 Apr 2019 16:27:01 -0500 Subject: [PATCH 17/32] Changed some of the magicleap demo SVGs --- demo/magicleap/lre/PathfinderDemo.draft | 177 - demo/magicleap/src/landscape.cpp | 6 +- resources/svg/julius-caesar-with-bg.svg | 10599 ++++++++ resources/svg/magicleap-quickstart-p03.svg | 2685 ++ resources/svg/nba-notext.svg | 77 + resources/svg/paper.svg | 25021 ++++++++++++++++++ resources/svg/pathfinder-magicleap-demo.svg | 4099 +++ 7 files changed, 42484 insertions(+), 180 deletions(-) delete mode 100644 demo/magicleap/lre/PathfinderDemo.draft create mode 100644 resources/svg/julius-caesar-with-bg.svg create mode 100644 resources/svg/magicleap-quickstart-p03.svg create mode 100644 resources/svg/nba-notext.svg create mode 100644 resources/svg/paper.svg create mode 100644 resources/svg/pathfinder-magicleap-demo.svg diff --git a/demo/magicleap/lre/PathfinderDemo.draft b/demo/magicleap/lre/PathfinderDemo.draft deleted file mode 100644 index e87e27ab..00000000 --- a/demo/magicleap/lre/PathfinderDemo.draft +++ /dev/null @@ -1,177 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/demo/magicleap/src/landscape.cpp b/demo/magicleap/src/landscape.cpp index 0498fc7f..04ccc8ac 100644 --- a/demo/magicleap/src/landscape.cpp +++ b/demo/magicleap/src/landscape.cpp @@ -30,11 +30,11 @@ const char* QUAD_NAMES[NUM_QUADS] = { const char* SVG_NAMES[NUM_QUADS] = { "svg/nba-notext.svg", - "svg/paper.svg", "svg/Ghostscript_Tiger.svg", "svg/julius-caesar-with-bg.svg", - "svg/julius-caesar.svg", - "svg/pathfinder_logo.svg", + "svg/magicleap-quickstart-p03.svg", + "svg/paper.svg", + "svg/pathfinder-magicleap-demo.svg", }; PathfinderDemo::PathfinderDemo() { diff --git a/resources/svg/julius-caesar-with-bg.svg b/resources/svg/julius-caesar-with-bg.svg new file mode 100644 index 00000000..8ec6bddb --- /dev/null +++ b/resources/svg/julius-caesar-with-bg.svg @@ -0,0 +1,10599 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/svg/magicleap-quickstart-p03.svg b/resources/svg/magicleap-quickstart-p03.svg new file mode 100644 index 00000000..62d4b33f --- /dev/null +++ b/resources/svg/magicleap-quickstart-p03.svg @@ -0,0 +1,2685 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/svg/nba-notext.svg b/resources/svg/nba-notext.svg new file mode 100644 index 00000000..898650f5 --- /dev/null +++ b/resources/svg/nba-notext.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/svg/paper.svg b/resources/svg/paper.svg new file mode 100644 index 00000000..5544d478 --- /dev/null +++ b/resources/svg/paper.svg @@ -0,0 +1,25021 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/svg/pathfinder-magicleap-demo.svg b/resources/svg/pathfinder-magicleap-demo.svg new file mode 100644 index 00000000..59fea0b7 --- /dev/null +++ b/resources/svg/pathfinder-magicleap-demo.svg @@ -0,0 +1,4099 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 41dc65596753db97dbf6ea748e36bdb61bd4ee30 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Tue, 9 Apr 2019 14:35:52 -0500 Subject: [PATCH 18/32] Update for current Window interface --- demo/magicleap/src/lib.rs | 6 ++++-- demo/magicleap/src/magicleap.rs | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/demo/magicleap/src/lib.rs b/demo/magicleap/src/lib.rs index 6715ff02..25f7cea8 100644 --- a/demo/magicleap/src/lib.rs +++ b/demo/magicleap/src/lib.rs @@ -15,6 +15,7 @@ use log::info; use pathfinder_demo::Background; use pathfinder_demo::DemoApp; use pathfinder_demo::Options; +use pathfinder_demo::UIVisibility; use pathfinder_demo::window::Event; use pathfinder_demo::window::Mode; use pathfinder_demo::window::SVGPath; @@ -77,11 +78,11 @@ pub unsafe extern "C" fn magicleap_pathfinder_demo_init(egl_display: EGLDisplay, let window_size = window.size(); let mut options = Options::default(); - options.ui = false; + options.ui = UIVisibility::None; options.background = Background::None; options.mode = Mode::VR; options.jobs = Some(3); - options.pipeline = 0; + options.pipeline = false; let demo = DemoApp::new(window, window_size, options); info!("Initialized app"); @@ -225,6 +226,7 @@ pub unsafe extern "C" fn magicleap_pathfinder_render(pf: *mut c_void, options: * transform: RenderTransform::Transform2D(transform), dilation: Point2DF32::default(), barrel_distortion: None, + subpixel_aa_enabled: false, }; let built_options = render_options.prepare(svg.scene.bounds); diff --git a/demo/magicleap/src/magicleap.rs b/demo/magicleap/src/magicleap.rs index 5b196f49..f2912187 100644 --- a/demo/magicleap/src/magicleap.rs +++ b/demo/magicleap/src/magicleap.rs @@ -101,7 +101,7 @@ impl Window for MagicLeapWindow { self.framebuffer_id } - fn customize_rayon(&self, thread_pool_builder: ThreadPoolBuilder) -> ThreadPoolBuilder { + fn adjust_thread_pool_settings(&self, thread_pool_builder: ThreadPoolBuilder) -> ThreadPoolBuilder { thread_pool_builder.start_handler(|id| unsafe { init_scene_thread(id) }) } @@ -123,7 +123,7 @@ impl Window for MagicLeapWindow { Err(()) } - fn view_box_size(&self, _mode: Mode, _subpixel_aa: bool) -> Point2DI32 { + fn view_box_size(&self, _mode: Mode) -> Point2DI32 { self.size } @@ -131,7 +131,7 @@ impl Window for MagicLeapWindow { BarrelDistortionCoefficients { k0: 0.0, k1: 0.0 } } - fn make_current(&mut self, _mode: Mode, _subpixel_aa: bool, eye: Option) -> RectI32 { + fn make_current(&mut self, _mode: Mode, eye: Option) -> RectI32 { self.begin_frame(); let eye = match eye { Some(eye) if (eye as usize) < ML_VIRTUAL_CAMERA_COUNT => eye as usize, @@ -337,11 +337,11 @@ impl Window for MagicLeapLandscape { Err(()) } - fn view_box_size(&self, _mode: Mode, _subpixel_aa: bool) -> Point2DI32 { + fn view_box_size(&self, _mode: Mode) -> Point2DI32 { self.size } - fn make_current(&mut self, _mode: Mode, _subpixel_aa: bool, _eye: Option) -> RectI32 { + fn make_current(&mut self, _mode: Mode, _eye: Option) -> RectI32 { RectI32::new(Point2DI32::new(0, 0), self.size) } From 0f0062351dab9f7a8302ae2602b0f0ac98916c0c Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Tue, 9 Apr 2019 11:33:57 -0500 Subject: [PATCH 19/32] Make pathfinder_immersive_demo a shared library. --- demo/magicleap/PathfinderImmersiveDemo.mabu | 4 +--- demo/magicleap/PathfinderLandscapeDemo.mabu | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/demo/magicleap/PathfinderImmersiveDemo.mabu b/demo/magicleap/PathfinderImmersiveDemo.mabu index 90209f53..7a40d404 100644 --- a/demo/magicleap/PathfinderImmersiveDemo.mabu +++ b/demo/magicleap/PathfinderImmersiveDemo.mabu @@ -9,10 +9,8 @@ LIBPATHS.release = \ USES = ml_sdk OpenGL stdc++ -STLIBS = \ - pathfinder_magicleap_demo - SHLIBS = \ + pathfinder_magicleap_demo \ ml_privileges DATAS = \ diff --git a/demo/magicleap/PathfinderLandscapeDemo.mabu b/demo/magicleap/PathfinderLandscapeDemo.mabu index be11ba0e..7a7c7d15 100644 --- a/demo/magicleap/PathfinderLandscapeDemo.mabu +++ b/demo/magicleap/PathfinderLandscapeDemo.mabu @@ -15,5 +15,5 @@ USES = \ lumin_runtime \ lre/code/srcs -STLIBS = \ +SHLIBS = \ pathfinder_magicleap_demo From 06b5e3330d72ad9ec25bf6d5ee8ac642ca1eead3 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Tue, 9 Apr 2019 11:35:04 -0500 Subject: [PATCH 20/32] Get the pathfinder magicleap demo to compile with v0.20.0 of the SDK --- demo/magicleap/manifest.xml | 4 +-- demo/magicleap/src/landscape.cpp | 57 +++++++++++++++----------------- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/demo/magicleap/manifest.xml b/demo/magicleap/manifest.xml index a0c9d703..bc84d1e6 100644 --- a/demo/magicleap/manifest.xml +++ b/demo/magicleap/manifest.xml @@ -5,8 +5,8 @@ ml:version_name="1.0"> + ml:sdk_version="0.20.0" + ml:min_api_level="4"> diff --git a/demo/magicleap/src/landscape.cpp b/demo/magicleap/src/landscape.cpp index 04ccc8ac..b14728ff 100644 --- a/demo/magicleap/src/landscape.cpp +++ b/demo/magicleap/src/landscape.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -218,40 +219,36 @@ bool PathfinderDemo::updateLoop(float fDelta) { bool PathfinderDemo::eventListener(lumin::ServerEvent* event) { // Place your event handling here. - lumin::ServerEventType typ = event->getServerEventType(); - switch (typ) { - case lumin::ServerEventType::kControlPose6DofInputEvent: { - requestWorldRayCast(getHeadposeWorldPosition(), getHeadposeWorldForwardVector(), 0); - return false; - } - case lumin::ServerEventType::kRayCastEvent: { - lumin::RayCastEventData* raycast_event = static_cast(event); - std::shared_ptr raycast_result = raycast_event->getHitData(); - switch (raycast_result->getType()) { - case lumin::RaycastResultType::kQuadNode: { - std::shared_ptr quad_result = std::static_pointer_cast(raycast_result); - focus_node_ = quad_result->getNodeId(); - return false; - } - default: { - focus_node_ = lumin::INVALID_NODE_ID; - return false; - } + lumin::ServerEventTypeValue typ = event->getServerEventTypeValue(); + if (typ == lumin::ControlPose6DofInputEventData::GetServerEventTypeValue()) { + requestWorldRayCast(getHeadposeWorldPosition(), getHeadposeWorldForwardVector(), 0); + return false; + } else if (typ == lumin::RayCastEventData::GetServerEventTypeValue()) { + lumin::RayCastEventData* raycast_event = static_cast(event); + std::shared_ptr raycast_result = raycast_event->getHitData(); + switch (raycast_result->getType()) { + case lumin::RaycastResultType::kQuadNode: { + std::shared_ptr quad_result = std::static_pointer_cast(raycast_result); + focus_node_ = quad_result->getNodeId(); + return false; + } + default: { + focus_node_ = lumin::INVALID_NODE_ID; + return false; } } - case lumin::ServerEventType::kGestureInputEvent: { - lumin::GestureInputEventData* gesture_event = static_cast(event); - switch (gesture_event->getGesture()) { - case lumin::input::GestureType::TriggerClick: { - return onClick(); - } - default: { - return false; - } + } else if (typ == lumin::GestureInputEventData::GetServerEventTypeValue()) { + lumin::GestureInputEventData* gesture_event = static_cast(event); + switch (gesture_event->getGesture()) { + case lumin::input::GestureType::TriggerClick: { + return onClick(); + } + default: { + return false; } } - default: - return false; + } else { + return false; } } From 4c1e532f7f4a2003cb264e389fe71ec1c7d5bc31 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Tue, 9 Apr 2019 14:32:06 -0500 Subject: [PATCH 21/32] Regenerated Cargo.lock --- Cargo.lock | 490 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 490 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index fc401538..4d15767f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,6 +21,24 @@ dependencies = [ "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "andrew" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "line_drawing 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rusttype 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)", + "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "xdg 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "android_glue" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "ansi_term" version = "0.11.0" @@ -29,6 +47,14 @@ dependencies = [ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "approx" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "area-lut" version = "0.2.0" @@ -102,6 +128,11 @@ name = "bitflags" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "block" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "byteorder" version = "1.3.1" @@ -122,6 +153,15 @@ name = "cfg-if" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "cgl" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "clap" version = "2.32.0" @@ -144,6 +184,20 @@ dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "cocoa" +version = "0.18.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", + "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", + "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "objc 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "color_quant" version = "1.0.1" @@ -161,6 +215,31 @@ dependencies = [ "unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "core-foundation" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "core-foundation-sys" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "core-graphics" +version = "0.17.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", + "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crc32fast" version = "1.1.2" @@ -225,6 +304,19 @@ dependencies = [ "sdl2-sys 0.32.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "dlib" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "downcast-rs" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "egl" version = "0.2.7" @@ -291,6 +383,19 @@ dependencies = [ "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "fs_extra" version = "1.1.0" @@ -342,6 +447,56 @@ dependencies = [ "xml-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "gl_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "khronos_api 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "gl_generator" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "khronos_api 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "gleam" +version = "0.6.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "glutin" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "android_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cgl 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cocoa 0.18.4 (registry+https://github.com/rust-lang/crates.io-index)", + "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", + "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", + "gl_generator 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "objc 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "osmesa-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "shared_library 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-client 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winit 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)", + "x11-dl 2.18.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "hashbrown" version = "0.1.8" @@ -472,6 +627,11 @@ name = "khronos_api" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "khronos_api" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "lazy_static" version = "1.3.0" @@ -497,6 +657,32 @@ dependencies = [ "crc32fast 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "libloading" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "line_drawing" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "lock_api" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "log" version = "0.3.9" @@ -528,6 +714,14 @@ name = "lzw" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "malloc_buf" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "memchr" version = "0.1.11" @@ -541,6 +735,15 @@ name = "memchr" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "memmap" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "memoffset" version = "0.2.1" @@ -554,6 +757,18 @@ dependencies = [ "gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "nix" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "nodrop" version = "0.1.13" @@ -627,6 +842,59 @@ dependencies = [ "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "objc" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "ordered-float" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "osmesa-sys" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "shared_library 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "owning_ref" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "parking_lot" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "parking_lot_core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "pathfinder_android_demo" version = "0.1.0" @@ -695,6 +963,27 @@ dependencies = [ "rustache 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "pathfinder_magicleap_demo" +version = "0.1.0" +dependencies = [ + "egl 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "gl 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "glutin 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "pathfinder_demo 0.1.0", + "pathfinder_geometry 0.3.0", + "pathfinder_gl 0.1.0", + "pathfinder_gpu 0.1.0", + "pathfinder_renderer 0.1.0", + "pathfinder_simd 0.3.0", + "pathfinder_svg 0.1.0", + "pathfinder_ui 0.1.0", + "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "usvg 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "pathfinder_renderer" version = "0.1.0" @@ -743,6 +1032,11 @@ dependencies = [ "serde_json 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "percent-encoding" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "phf" version = "0.7.24" @@ -759,6 +1053,11 @@ dependencies = [ "siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "pkg-config" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "png" version = "0.12.0" @@ -1048,6 +1347,17 @@ dependencies = [ "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rusttype" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "approx 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "stb_truetype 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "ryu" version = "0.2.7" @@ -1140,6 +1450,15 @@ dependencies = [ "serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "shared_library" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "simplecss" version = "0.1.0" @@ -1160,6 +1479,35 @@ name = "smallvec" version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "smithay-client-toolkit" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "andrew 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "dlib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-client 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-commons 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-protocols 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "stable_deref_trait" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "stb_truetype" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "strsim" version = "0.7.0" @@ -1326,6 +1674,60 @@ dependencies = [ "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "wayland-client" +version = "0.21.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "downcast-rs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-commons 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-scanner 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-sys 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wayland-commons" +version = "0.21.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-sys 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wayland-protocols" +version = "0.21.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-client 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-commons 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-scanner 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-sys 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wayland-scanner" +version = "0.21.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", + "xml-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wayland-sys" +version = "0.21.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "dlib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "winapi" version = "0.2.8" @@ -1372,6 +1774,43 @@ dependencies = [ "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "winit" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "android_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "cocoa 0.18.4 (registry+https://github.com/rust-lang/crates.io-index)", + "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", + "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "objc 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "smithay-client-toolkit 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-client 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "x11-dl 2.18.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "x11-dl" +version = "2.18.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "xdg" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "xml-rs" version = "0.7.0" @@ -1380,6 +1819,11 @@ dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "xml-rs" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "xmlparser" version = "0.8.1" @@ -1389,7 +1833,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7e522997b529f05601e05166c07ed17789691f562762c7f3b987263d2dedee5c" "checksum aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ca972c2ea5f742bfce5687b9aef75506a764f61d37f8f649047846a9686ddb66" "checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5" +"checksum andrew 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9b7f09f89872c2b6b29e319377b1fbe91c6f5947df19a25596e121cf19a7b35e" +"checksum android_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "000444226fcff248f2bc4c7625be32c63caccfecc2723a2b9f78a7487a49c407" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +"checksum approx 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0e60b75072ecd4168020818c0107f2857bb6c4e64252d8d3983f6263b40a5c3" "checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71" "checksum ascii 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a5fc969a8ce2c9c0c4b0429bb8431544f6658283c8326ba5ff8c762b75369335" "checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" @@ -1398,19 +1845,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6" "checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" +"checksum block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" "checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" "checksum cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)" = "4390a3b5f4f6bce9c1d0c00128379df433e53777fdd30e92f16a529332baec4e" "checksum cesu8 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" "checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" +"checksum cgl 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "55e7ec0b74fe5897894cbc207092c577e87c52f8a59e8ca8d97ef37551f60a49" "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +"checksum cocoa 0.18.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cf79daa4e11e5def06e55306aa3601b87de6b5149671529318da048f67cdd77b" "checksum color_quant 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0dbbb57365263e881e805dc77d94697c9118fd94d8da011240555aa7b23445bd" "checksum combine 3.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "d2623b3542b48f4427e15ddd4995186decb594ebbd70271463886584b4a114b9" +"checksum core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "25b9e03f145fd4f2bf705e07b900cd41fc636598fe5dc452fd0db1441c3f496d" +"checksum core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e7ca8a5221364ef15ce201e8ed2f609fc312682a8f4e0e3d4aa5879764e0fa3b" +"checksum core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)" = "56790968ab1c8a1202a102e6de05fc6e1ec87da99e4e93e9a7d13efbfc1e95a9" "checksum crc32fast 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e91d5240c6975ef33aeb5f148f35275c25eda8e8a5f95abe421978b05b8bf192" "checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" "checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" "checksum deflate 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)" = "8a6abb26e16e8d419b5c78662aa9f82857c2386a073da266840e474d5055ec86" +"checksum dlib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "77e51249a9d823a4cb79e3eca6dcd756153e8ed0157b6c04775d04bf1b13b76a" +"checksum downcast-rs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b92dfd5c2f75260cbf750572f95d387e7ca0ba5e3fbe9e1a33f23025be020f" "checksum egl 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a373bc9844200b1ff15bd1b245931d1c20d09d06e4ec09f361171f29a4b0752d" "checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0" "checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38" @@ -1419,12 +1874,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum euclid_macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fdcb84c18ea5037a1c5a23039b4ff29403abce2e0d6b1daa11cf0bde2b30be15" "checksum fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33" "checksum float-cmp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "134a8fa843d80a51a5b77d36d42bc2def9edcb0262c914861d08129fd1926600" +"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +"checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" "checksum fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" "checksum gif 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4bca55ac1f213920ce3527ccd62386f1f15fa3f1714aeee1cf93f2c416903f" "checksum gl 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1c73b90c285f02059b34a6c66bc645ba5faa18c0e3ab332e0725654fc71db441" +"checksum gl_generator 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a0ffaf173cf76c73a73e080366bf556b4776ece104b06961766ff11449f38604" +"checksum gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "39a23d5e872a275135d66895d954269cf5e8661d234eb1c2480f4ce0d586acbd" "checksum gl_generator 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "75d69f914b49d9ff32fdf394cbd798f8c716d74fd19f9cc29da3e99797b2a78d" +"checksum gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "39bb69499005e11b7b7cc0af38404a1bc0f53d954bffa8adcdb6e8d5b14f75d5" +"checksum glutin 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "535c6eda58adbb227604b2db10a022ffd6339d7ea3e970f338e7d98aeb24fcc3" "checksum hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3bae29b6653b3412c2e71e9d486db9f9df5d701941d86683005efb9f2d28e3da" "checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114" "checksum image 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ebdff791af04e30089bde8ad2a632b86af433b40c04db8d70ad4b21487db7a6a" @@ -1439,18 +1900,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum khronos 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c0711aaa80e6ba6eb1fa8978f1f46bfcb38ceb2f3f33f3736efbff39dac89f50" "checksum khronos_api 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "037ab472c33f67b5fbd3e9163a2645319e5356fcd355efa6d4eb7fff4bbcb554" +"checksum khronos_api 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum libc 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "e32a70cf75e5846d53a673923498228bbec6a8624708a9ea5645f075d6276122" "checksum libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)" = "e962c7641008ac010fa60a7dfdc1712449f29c44ef2d4702394aea943ee75047" "checksum libflate 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "54d1ddf9c52870243c5689d7638d888331c1116aa5b398f3ba1acfa7d8758ca1" +"checksum libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3ad660d7cb8c5822cd83d10897b0f1f1526792737a179e73896152f85b88c2" +"checksum line_drawing 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5cc7ad3d82c845bdb5dde34ffdcc7a5fb4d2996e1e1ee0f19c33bc80e15196b9" +"checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum lyon_geom 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2b60eaa9061c87affcd671e88289ce6971324269ec6548b677e02624ef3ef63c" "checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084" +"checksum malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" "checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20" "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" +"checksum memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum nfd 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8e752e3c216bc8a491c5b59fa46da10f1379ae450b19ac688e07f4bb55042e98" +"checksum nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46f0f3210768d796e8fa79ec70ee6af172dacbe7147f5e69be5240a47778302b" "checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" "checksum num-derive 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d9fe8fcafd1b86a37ce8a1cfa15ae504817e0c8c2e7ad42767371461ac1d316d" @@ -1460,8 +1928,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum num-rational 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4e96f040177bb3da242b5b1ecf3f54b5d5af3efbbfb18608977a5d2767b22f10" "checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" "checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba" +"checksum objc 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "31d20fd2b37e07cf5125be68357b588672e8cefe9a96f8c17a9d46053b3e590d" +"checksum ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "18869315e81473c951eb56ad5558bbc56978562d3ecfb87abb7a1e944cea4518" +"checksum osmesa-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "88cfece6e95d2e717e0872a7f53a8684712ad13822a7979bc760b9c77ec0013b" +"checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13" +"checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" +"checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" +"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum phf 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "b3da44b85f8e8dfaec21adae67f95d93244b2ecf6ad2a692320598dcc8e6dd18" "checksum phf_shared 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "234f71a15de2288bcb7e3b6515828d22af7ec8598ee6d24c3b526fa0a80b67a0" +"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c" "checksum png 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f54b9600d584d3b8a739e1662a595fab051329eff43f20e7d8cc22872962145b" "checksum png 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9adebf7fb91ccf5eac9da1a8e00e83cb8ae882c3e8d8e4ad59da73cb8c82a2c9" "checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915" @@ -1495,6 +1971,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +"checksum rusttype 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ce3926a2057b315b3e8bca6d1cec1e97f19436a8f9127621cd538cda9c96a38b" "checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" "checksum safe-transmute 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9604873ffe1980bc1f179103704a65c8aca141c248d9e52b7af95ff10578166e" "checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" @@ -1508,10 +1985,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)" = "9f301d728f2b94c9a7691c90f07b0b4e8a4517181d9461be94c04bddeb4bd850" "checksum serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)" = "beed18e6f5175aef3ba670e57c60ef3b1b74d250d962a26604bff4c80e970dd4" "checksum serde_json 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)" = "27dce848e7467aa0e2fcaf0a413641499c0b745452aaca1194d24dedde9e13c9" +"checksum shared_library 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11" "checksum simplecss 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "135685097a85a64067df36e28a243e94a94f76d829087ce0be34eeb014260c0e" "checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" +"checksum smithay-client-toolkit 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "aa4899558362a65589b53313935099835acf999740915e134dff20cca7c6a28b" +"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" +"checksum stb_truetype 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "69b7df505db8e81d54ff8be4693421e5b543e08214bd8d99eb761fcb4d5668ba" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" "checksum svgdom 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a9b53b3ed152fc6b871f7232a8772c640567fd25d056941450637ecba32924d" "checksum svgtypes 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c43c25e6de7264024b5e351eb0c342039eb5acf51f2e9d0099bbd324b661453b" @@ -1533,6 +2014,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1" +"checksum wayland-client 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)" = "e77d1e6887f07ea2e5d79a3d7d03a875e62d3746334a909b5035d779d849a523" +"checksum wayland-commons 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)" = "dff69a5399ca212efa4966f3ee2a3773f19960d0fa329b9aca046a8508a0e09f" +"checksum wayland-protocols 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ccddf6a4407d982898e0f0a1172217843f3d40fe4272f828060b56a2d40d81" +"checksum wayland-scanner 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)" = "63bc5efa7dcdb8f04d2e5d1571c0d0577fc47076d133d68e056bdb299f1b60e2" +"checksum wayland-sys 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)" = "e76af81a601b84d400744f85f083381daa77ac01f6c8711e57e662dc3a35d69d" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" @@ -1540,5 +2026,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "561ed901ae465d6185fa7864d63fbd5720d0ef718366c9a4dc83cf6170d7e9ba" +"checksum winit 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c57c15bd4c0ef18dff33e263e452abe32d00e2e05771cacaa410a14cc1c0776" +"checksum x11-dl 2.18.3 (registry+https://github.com/rust-lang/crates.io-index)" = "940586acb859ea05c53971ac231685799a7ec1dee66ac0bccc0e6ad96e06b4e3" +"checksum xdg 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57" "checksum xml-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c1cb601d29fe2c2ac60a2b2e5e293994d87a1f6fa9687a31a15270f909be9c2" +"checksum xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "541b12c998c5b56aa2b4e6f18f03664eef9a4fd0a246a55594efae6cc2d964b5" "checksum xmlparser 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d78a7f29bb57edf63321d545d84f99360df71df36929a090bc067e1bcb65e34d" From bc89d88222c6aa7117db1238293c5a9c765e7b4b Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Tue, 9 Apr 2019 14:58:28 -0500 Subject: [PATCH 22/32] Dead code elimination --- Cargo.lock | 1 - demo/magicleap/src/lib.rs | 21 +-------- demo/magicleap/src/magicleap.rs | 81 --------------------------------- 3 files changed, 1 insertion(+), 102 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4d15767f..ad8fc6bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -945,7 +945,6 @@ 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", diff --git a/demo/magicleap/src/lib.rs b/demo/magicleap/src/lib.rs index 25f7cea8..31ff4db2 100644 --- a/demo/magicleap/src/lib.rs +++ b/demo/magicleap/src/lib.rs @@ -1,4 +1,3 @@ -use crate::magicleap::MagicLeapLandscape; use crate::magicleap::MagicLeapLogger; use crate::magicleap::MagicLeapWindow; @@ -9,7 +8,6 @@ use egl::EGLSurface; use gl::types::GLuint; -use log::debug; use log::info; use pathfinder_demo::Background; @@ -19,7 +17,6 @@ use pathfinder_demo::UIVisibility; 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 pathfinder_geometry::basic::point::Point2DF32; use pathfinder_geometry::basic::rect::RectI32; @@ -30,7 +27,6 @@ use pathfinder_gpu::Device; use pathfinder_gpu::resources::FilesystemResourceLoader; use pathfinder_renderer::gpu::renderer::Renderer; use pathfinder_simd::default::F32x4; -use pathfinder_renderer::scene::Scene; use pathfinder_renderer::z_buffer::ZBuffer; use pathfinder_renderer::gpu_data::BuiltScene; use pathfinder_renderer::builder::SceneBuilder; @@ -39,8 +35,6 @@ use pathfinder_renderer::builder::RenderTransform; use pathfinder_svg::BuiltSVG; use pathfinder_gpu::resources::ResourceLoader; -use rayon::ThreadPoolBuilder; - use std::collections::HashMap; use std::ffi::CStr; use std::ffi::CString; @@ -64,7 +58,7 @@ struct ImmersiveApp { } #[no_mangle] -pub unsafe extern "C" fn magicleap_pathfinder_demo_init(egl_display: EGLDisplay, egl_context: EGLContext) -> *mut c_void { +pub extern "C" fn magicleap_pathfinder_demo_init(egl_display: EGLDisplay, egl_context: EGLContext) -> *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(); @@ -128,15 +122,6 @@ struct MagicLeapPathfinder { resources: FilesystemResourceLoader, } -struct MagicLeapPathfinderSurface { - surf: EGLSurface, - size: Point2DI32, - viewport: RectI32, - bg_color: F32x4, - renderer: Renderer, - scene: Scene, -} - #[repr(C)] pub struct MagicLeapPathfinderRenderOptions { display: EGLDisplay, @@ -156,10 +141,6 @@ pub extern "C" fn magicleap_pathfinder_init() -> *mut c_void { log::set_boxed_logger(Box::new(logger)).unwrap(); log::set_max_level(level); info!("Initialized logging"); - - let mut thread_pool_builder = ThreadPoolBuilder::new() - .build_global().unwrap(); - info!("Initialized rayon"); gl::load_with(|s| egl::get_proc_address(s) as *const c_void); info!("Initialized gl"); diff --git a/demo/magicleap/src/magicleap.rs b/demo/magicleap/src/magicleap.rs index f2912187..12b52e57 100644 --- a/demo/magicleap/src/magicleap.rs +++ b/demo/magicleap/src/magicleap.rs @@ -35,7 +35,6 @@ use egl; use egl::EGL_NO_SURFACE; use egl::EGLContext; use egl::EGLDisplay; -use egl::EGLSurface; use gl; use gl::types::GLuint; @@ -296,86 +295,6 @@ impl Drop for MagicLeapWindow { } } -// Magic Leap landscape app - -pub struct MagicLeapLandscape { - pub dpy: EGLDisplay, - pub surf: EGLSurface, - pub fbo: GLuint, - 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 gl_default_framebuffer(&self) -> GLuint { - self.fbo - } - - 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 { - Err(()) - } - - fn view_box_size(&self, _mode: Mode) -> Point2DI32 { - self.size - } - - fn make_current(&mut self, _mode: Mode, _eye: Option) -> RectI32 { - RectI32::new(Point2DI32::new(0, 0), self.size) - } - - fn present(&mut self) { - } -} - -impl MagicLeapLandscape { - pub fn new(dpy: EGLDisplay, surf: EGLSurface) -> MagicLeapLandscape { - gl::load_with(get_proc_address); - let size = Point2DI32::new(512, 512); - let fbo = 0; - let resource_loader = FilesystemResourceLoader::locate(); - MagicLeapLandscape { - dpy, - surf, - fbo, - 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 { From 8d5b44140bc7aad49a1f73c2c1a2eaff666e0f5b Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Tue, 9 Apr 2019 15:01:48 -0500 Subject: [PATCH 23/32] Magicleap demo is less chatty --- demo/magicleap/src/magicleap.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/demo/magicleap/src/magicleap.rs b/demo/magicleap/src/magicleap.rs index 12b52e57..2fc2cf7e 100644 --- a/demo/magicleap/src/magicleap.rs +++ b/demo/magicleap/src/magicleap.rs @@ -42,7 +42,6 @@ use gl::types::GLuint; use log; use log::debug; use log::info; -use log::warn; use pathfinder_demo::window::CameraTransform; use pathfinder_demo::window::Event; @@ -134,7 +133,7 @@ impl Window for MagicLeapWindow { self.begin_frame(); let eye = match eye { Some(eye) if (eye as usize) < ML_VIRTUAL_CAMERA_COUNT => eye as usize, - _ => { warn!("Asked for eye out of range {:?}", eye); 0 } + _ => { debug!("Asked for eye out of range {:?}", eye); 0 } }; debug!("Making {} current.", eye); let viewport = self.virtual_camera_array.viewport; From 1605a47956fe306e70cb0357b5035299f637a7cd Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Wed, 10 Apr 2019 11:32:03 -0500 Subject: [PATCH 24/32] Updated to new PF3 API --- demo/magicleap/src/lib.rs | 98 ++++++++++++++++++--------------- demo/magicleap/src/magicleap.rs | 15 +++-- 2 files changed, 61 insertions(+), 52 deletions(-) diff --git a/demo/magicleap/src/lib.rs b/demo/magicleap/src/lib.rs index 31ff4db2..df6f10ec 100644 --- a/demo/magicleap/src/lib.rs +++ b/demo/magicleap/src/lib.rs @@ -10,30 +10,30 @@ use gl::types::GLuint; use log::info; -use pathfinder_demo::Background; use pathfinder_demo::DemoApp; use pathfinder_demo::Options; use pathfinder_demo::UIVisibility; +use pathfinder_demo::BackgroundColor; +use pathfinder_demo::Mode; use pathfinder_demo::window::Event; -use pathfinder_demo::window::Mode; use pathfinder_demo::window::SVGPath; -use pathfinder_geometry::basic::point::Point2DI32; use pathfinder_geometry::basic::point::Point2DF32; +use pathfinder_geometry::basic::point::Point2DI32; use pathfinder_geometry::basic::rect::RectI32; use pathfinder_geometry::basic::transform2d::Transform2DF32; use pathfinder_gl::GLDevice; use pathfinder_gl::GLVersion; use pathfinder_gpu::Device; use pathfinder_gpu::resources::FilesystemResourceLoader; -use pathfinder_renderer::gpu::renderer::Renderer; -use pathfinder_simd::default::F32x4; -use pathfinder_renderer::z_buffer::ZBuffer; -use pathfinder_renderer::gpu_data::BuiltScene; -use pathfinder_renderer::builder::SceneBuilder; +use pathfinder_gpu::resources::ResourceLoader; use pathfinder_renderer::builder::RenderOptions; use pathfinder_renderer::builder::RenderTransform; +use pathfinder_renderer::builder::SceneBuilder; +use pathfinder_renderer::builder::SceneBuilderContext; +use pathfinder_renderer::gpu::renderer::Renderer; +use pathfinder_renderer::gpu_data::BuiltScene; +use pathfinder_simd::default::F32x4; use pathfinder_svg::BuiltSVG; -use pathfinder_gpu::resources::ResourceLoader; use std::collections::HashMap; use std::ffi::CStr; @@ -59,7 +59,9 @@ struct ImmersiveApp { #[no_mangle] pub extern "C" fn magicleap_pathfinder_demo_init(egl_display: EGLDisplay, egl_context: EGLContext) -> *mut c_void { - 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".as_ptr() as *const _, + b"Initializing\0".as_ptr() as *const _) }; let tag = CString::new("Pathfinder Demo").unwrap(); let level = log::LevelFilter::Warn; @@ -72,11 +74,10 @@ pub extern "C" fn magicleap_pathfinder_demo_init(egl_display: EGLDisplay, egl_co let window_size = window.size(); let mut options = Options::default(); - options.ui = UIVisibility::None; - options.background = Background::None; + options.ui = UIVisibility::Stats; + options.background_color = BackgroundColor::Transparent; options.mode = Mode::VR; options.jobs = Some(3); - options.pipeline = false; let demo = DemoApp::new(window, window_size, options); info!("Initialized app"); @@ -102,7 +103,7 @@ pub unsafe extern "C" fn magicleap_pathfinder_demo_run(app: *mut c_void) { app.demo.draw_scene(scene_index); } app.demo.finish_drawing_frame(); - } + } } } @@ -120,6 +121,7 @@ struct MagicLeapPathfinder { renderers: HashMap<(EGLSurface, EGLDisplay), Renderer>, svgs: HashMap, resources: FilesystemResourceLoader, + scene_builder_context: SceneBuilderContext, } #[repr(C)] @@ -133,7 +135,9 @@ pub struct MagicLeapPathfinderRenderOptions { #[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]) }; + unsafe { c_api::MLLoggingLog(c_api::MLLogLevel::Info, + b"Pathfinder Demo\0".as_ptr() as *const _, + b"Initializing\0".as_ptr() as *const _) }; let tag = CString::new("Pathfinder Demo").unwrap(); let level = log::LevelFilter::Info; @@ -149,6 +153,7 @@ pub extern "C" fn magicleap_pathfinder_init() -> *mut c_void { renderers: HashMap::new(), svgs: HashMap::new(), resources: FilesystemResourceLoader::locate(), + scene_builder_context: SceneBuilderContext::new(), }; info!("Initialized pf"); @@ -162,71 +167,76 @@ pub unsafe extern "C" fn magicleap_pathfinder_render(pf: *mut c_void, options: * let resources = &pf.resources; let svg_filename = CStr::from_ptr(options.svg_filename).to_string_lossy().into_owned(); - let svg = pf.svgs.entry(svg_filename).or_insert_with(|| { + let svg = pf.svgs.entry(svg_filename).or_insert_with(|| { let svg_filename = CStr::from_ptr(options.svg_filename).to_string_lossy(); - let data = resources.slurp(&*svg_filename).unwrap(); - let tree = Tree::from_data(&data, &UsvgOptions::default()).unwrap(); + let data = resources.slurp(&*svg_filename).unwrap(); + let tree = Tree::from_data(&data, &UsvgOptions::default()).unwrap(); BuiltSVG::from_tree(tree) }); let mut width = 0; - let mut height = 0; - egl::query_surface(options.display, options.surface, egl::EGL_WIDTH, &mut width); - egl::query_surface(options.display, options.surface, egl::EGL_HEIGHT, &mut height); + let mut height = 0; + egl::query_surface(options.display, options.surface, egl::EGL_WIDTH, &mut width); + egl::query_surface(options.display, options.surface, egl::EGL_HEIGHT, &mut height); let size = Point2DI32::new(width, height); let viewport_origin = Point2DI32::new(options.viewport[0] as i32, options.viewport[1] as i32); - let viewport_size = Point2DI32::new(options.viewport[2] as i32, options.viewport[3] as i32); + let viewport_size = Point2DI32::new(options.viewport[2] as i32, options.viewport[3] as i32); let viewport = RectI32::new(viewport_origin, viewport_size); - let renderer = pf.renderers.entry((options.display, options.surface)).or_insert_with(|| { - let mut fbo = 0; - gl::GetIntegerv(gl::DRAW_FRAMEBUFFER_BINDING, &mut fbo); + let bg_color = F32x4::new(options.bg_color[0], options.bg_color[1], options.bg_color[2], options.bg_color[3]); + + let renderer = pf.renderers.entry((options.display, options.surface)).or_insert_with(|| { + let mut fbo = 0; + gl::GetIntegerv(gl::DRAW_FRAMEBUFFER_BINDING, &mut fbo); let device = GLDevice::new(GLVersion::GLES3, fbo as GLuint); Renderer::new(device, resources, viewport, size) }); - let bg_color = F32x4::new(options.bg_color[0], options.bg_color[1], options.bg_color[2], options.bg_color[3]); - - svg.scene.view_box = viewport.to_f32(); renderer.set_main_framebuffer_size(size); renderer.set_viewport(viewport); - renderer.device.bind_default_framebuffer(viewport); + renderer.device.bind_default_framebuffer(viewport); renderer.device.clear(Some(bg_color), Some(1.0), Some(0)); renderer.disable_depth(); - let z_buffer = ZBuffer::new(svg.scene.view_box); + svg.scene.view_box = viewport.to_f32(); let scale = i32::min(viewport_size.x(), viewport_size.y()) as f32 / - f32::max(svg.scene.bounds.size().x(), svg.scene.bounds.size().y()); + f32::max(svg.scene.bounds.size().x(), svg.scene.bounds.size().y()); let transform = Transform2DF32::from_translation(&svg.scene.bounds.size().scale(-0.5)) - .post_mul(&Transform2DF32::from_scale(&Point2DF32::splat(scale))) + .post_mul(&Transform2DF32::from_scale(&Point2DF32::splat(scale))) .post_mul(&Transform2DF32::from_translation(&viewport_size.to_f32().scale(0.5))); - + let render_options = RenderOptions { transform: RenderTransform::Transform2D(transform), dilation: Point2DF32::default(), barrel_distortion: None, - subpixel_aa_enabled: false, - }; + subpixel_aa_enabled: false, + }; let built_options = render_options.prepare(svg.scene.bounds); let quad = built_options.quad(); - let built_objects = svg.scene.build_objects(built_options, &z_buffer); - let mut scene_builder = SceneBuilder::new(built_objects, z_buffer, svg.scene.view_box); - let mut built_scene = BuiltScene::new(svg.scene.view_box, &quad, svg.scene.objects.len() as u32); + let mut built_scene = BuiltScene::new(svg.scene.view_box, &quad, svg.scene.objects.len() as u32); built_scene.shaders = svg.scene.build_shaders(); - built_scene.solid_tiles = scene_builder.build_solid_tiles(); - while let Some(batch) = scene_builder.build_batch() { - built_scene.batches.push(batch); + + let (command_sender, command_receiver) = mpsc::channel(); + let command_sender_clone = command_sender.clone(); + + SceneBuilder::new(&pf.scene_builder_context, &svg.scene, &built_options) + .build_sequentially(Box::new(move |command| { let _ = command_sender.send(Some(command)); })); + + let _ = command_sender_clone.send(None); + + renderer.begin_scene(&built_scene); + while let Ok(Some(command)) = command_receiver.recv() { + renderer.render_command(&command); } - - renderer.render_scene(&built_scene); + renderer.end_scene(); } } #[no_mangle] pub unsafe extern "C" fn magicleap_pathfinder_deinit(pf: *mut c_void) { Box::from_raw(pf as *mut MagicLeapPathfinder); -} \ No newline at end of file +} diff --git a/demo/magicleap/src/magicleap.rs b/demo/magicleap/src/magicleap.rs index 2fc2cf7e..1939cce1 100644 --- a/demo/magicleap/src/magicleap.rs +++ b/demo/magicleap/src/magicleap.rs @@ -45,7 +45,7 @@ use log::info; use pathfinder_demo::window::CameraTransform; use pathfinder_demo::window::Event; -use pathfinder_demo::window::Mode; +use pathfinder_demo::window::View; use pathfinder_demo::window::Window; use pathfinder_demo::window::WindowSize; use pathfinder_geometry::basic::point::Point2DI32; @@ -121,19 +121,19 @@ impl Window for MagicLeapWindow { Err(()) } - fn view_box_size(&self, _mode: Mode) -> Point2DI32 { - self.size + fn viewport(&self, _view: View) -> RectI32 { + RectI32::new(Point2DI32::default(), self.size) } fn barrel_distortion_coefficients(&self) -> BarrelDistortionCoefficients { BarrelDistortionCoefficients { k0: 0.0, k1: 0.0 } } - fn make_current(&mut self, _mode: Mode, eye: Option) -> RectI32 { + fn make_current(&mut self, view: View) { self.begin_frame(); - let eye = match eye { - Some(eye) if (eye as usize) < ML_VIRTUAL_CAMERA_COUNT => eye as usize, - _ => { debug!("Asked for eye out of range {:?}", eye); 0 } + let eye = match view { + View::Stereo(eye) if (eye as usize) < ML_VIRTUAL_CAMERA_COUNT => eye as usize, + _ => { debug!("Asked for unexpected view: {:?}", view); 0 } }; debug!("Making {} current.", eye); let viewport = self.virtual_camera_array.viewport; @@ -147,7 +147,6 @@ impl Window for MagicLeapWindow { gl::Viewport(viewport.x as i32, viewport.y as i32, viewport.w as i32, viewport.h as i32); } debug!("Made {} current.", eye); - RectI32::new(Point2DI32::new(0, 0), self.size) } fn present(&mut self) { From 360332443779018f78274777d6d42178cc20aaf5 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Wed, 10 Apr 2019 21:10:17 -0500 Subject: [PATCH 25/32] Added copyright statement to magicleap demo files --- demo/magicleap/src/c_api.rs | 12 ++++++++++++ demo/magicleap/src/landscape.cpp | 12 ++++++++++++ demo/magicleap/src/landscape.h | 23 ++++++++++++++--------- demo/magicleap/src/lib.rs | 12 ++++++++++++ demo/magicleap/src/magicleap.rs | 2 +- demo/magicleap/src/main.cpp | 12 ++++++++++++ demo/magicleap/src/mocked_c_api.rs | 12 ++++++++++++ 7 files changed, 75 insertions(+), 10 deletions(-) diff --git a/demo/magicleap/src/c_api.rs b/demo/magicleap/src/c_api.rs index 6f0992f6..52f92244 100644 --- a/demo/magicleap/src/c_api.rs +++ b/demo/magicleap/src/c_api.rs @@ -1,3 +1,15 @@ +// pathfinder/demo/magicleap/src/c_api.rs +// +// Copyright © 2019 The Pathfinder Project Developers. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Bindings to the C MagicLeap API + #![allow(dead_code)] use gl::types::GLuint; diff --git a/demo/magicleap/src/landscape.cpp b/demo/magicleap/src/landscape.cpp index b14728ff..80b8b067 100644 --- a/demo/magicleap/src/landscape.cpp +++ b/demo/magicleap/src/landscape.cpp @@ -1,3 +1,15 @@ +// pathfinder/demo/magicleap/src/landscape.cpp +// +// Copyright © 2019 The Pathfinder Project Developers. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +// +// A launcher for the ML1 pathfinder demo + #include #include #include diff --git a/demo/magicleap/src/landscape.h b/demo/magicleap/src/landscape.h index d4b43fa8..aef95950 100644 --- a/demo/magicleap/src/landscape.h +++ b/demo/magicleap/src/landscape.h @@ -1,16 +1,21 @@ -// %BANNER_BEGIN% -// --------------------------------------------------------------------- -// %COPYRIGHT_BEGIN% +// pathfinder/demo/magicleap/src/landscape.h // +// Copyright © 2019 The Pathfinder Project Developers. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +// +// A launcher for the ML1 pathfinder demo + +// Based on code generated by the Magic Leap Lumin Runtime Editor. +// Original copyright: + // Copyright (c) 2018 Magic Leap, Inc. All Rights Reserved. // Use of this file is governed by the Creator Agreement, located // here: https://id.magicleap.com/creator-terms -// -// %COPYRIGHT_END% -// --------------------------------------------------------------------- -// %BANNER_END% - -// %SRC_VERSION%: 1 #include #include diff --git a/demo/magicleap/src/lib.rs b/demo/magicleap/src/lib.rs index df6f10ec..4a5523d2 100644 --- a/demo/magicleap/src/lib.rs +++ b/demo/magicleap/src/lib.rs @@ -1,3 +1,15 @@ +// pathfinder/demo/magicleap/src/lib.rs +// +// Copyright © 2019 The Pathfinder Project Developers. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! A demo app for Pathfinder on ML1. + use crate::magicleap::MagicLeapLogger; use crate::magicleap::MagicLeapWindow; diff --git a/demo/magicleap/src/magicleap.rs b/demo/magicleap/src/magicleap.rs index 1939cce1..65d4f77b 100644 --- a/demo/magicleap/src/magicleap.rs +++ b/demo/magicleap/src/magicleap.rs @@ -1,4 +1,4 @@ -// pathfinder/demo/magicleap/magicleap.rs +// pathfinder/demo/magicleap/src/magicleap.rs // // Copyright © 2019 The Pathfinder Project Developers. // diff --git a/demo/magicleap/src/main.cpp b/demo/magicleap/src/main.cpp index 2f547a9f..3b4224cc 100644 --- a/demo/magicleap/src/main.cpp +++ b/demo/magicleap/src/main.cpp @@ -1,3 +1,15 @@ +// pathfinder/demo/magicleap/src/main.cpp +// +// Copyright © 2019 The Pathfinder Project Developers. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// The immersive mode pathfinder magicleap demo + #include #include diff --git a/demo/magicleap/src/mocked_c_api.rs b/demo/magicleap/src/mocked_c_api.rs index 37159c68..1a62f51b 100644 --- a/demo/magicleap/src/mocked_c_api.rs +++ b/demo/magicleap/src/mocked_c_api.rs @@ -1,3 +1,15 @@ +// pathfinder/demo/magicleap/src/mocked_c_api.rs +// +// Copyright © 2019 The Pathfinder Project Developers. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! A mocked Rust implementation of the Magic Leap C API, to allow it to build without the ML SDK + #![allow(unused_variables)] #![allow(dead_code)] #![allow(non_snake_case)] From 24a7801820a9b727f57b73e905f295403683d02b Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Thu, 11 Apr 2019 16:42:13 -0500 Subject: [PATCH 26/32] The magicleap demo library is a shared library --- demo/magicleap/Cargo.toml | 2 +- demo/magicleap/PathfinderDemo.package | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/demo/magicleap/Cargo.toml b/demo/magicleap/Cargo.toml index ea310522..2e159f9e 100644 --- a/demo/magicleap/Cargo.toml +++ b/demo/magicleap/Cargo.toml @@ -14,7 +14,7 @@ smallvec = "0.6" glutin = { version = "0.19", optional = true } [lib] -crate-type = ["staticlib"] +crate-type = ["cdylib"] [features] mocked = ["glutin"] diff --git a/demo/magicleap/PathfinderDemo.package b/demo/magicleap/PathfinderDemo.package index b0f672c6..d0a506ec 100644 --- a/demo/magicleap/PathfinderDemo.package +++ b/demo/magicleap/PathfinderDemo.package @@ -1,3 +1,8 @@ USES = "lre/scenes" + REFS = PathfinderImmersiveDemo PathfinderLandscapeDemo + OPTIONS=package/debuggable/on + +DATAS = \ + ../../target/aarch64-linux-android/release/*.so : bin/ From 6b19234a446b2eb409133ecf9ea718581b9acab4 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Fri, 12 Apr 2019 13:40:15 -0500 Subject: [PATCH 27/32] Removed stats from magicleap demo --- demo/magicleap/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/magicleap/src/lib.rs b/demo/magicleap/src/lib.rs index 4a5523d2..3694d691 100644 --- a/demo/magicleap/src/lib.rs +++ b/demo/magicleap/src/lib.rs @@ -86,7 +86,7 @@ pub extern "C" fn magicleap_pathfinder_demo_init(egl_display: EGLDisplay, egl_co let window_size = window.size(); let mut options = Options::default(); - options.ui = UIVisibility::Stats; + options.ui = UIVisibility::None; options.background_color = BackgroundColor::Transparent; options.mode = Mode::VR; options.jobs = Some(3); From f20a023ba7d23946e0990eaf7dce54b57164f817 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Fri, 12 Apr 2019 13:40:42 -0500 Subject: [PATCH 28/32] Rearranged magicleap demo svgs --- demo/magicleap/src/landscape.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/magicleap/src/landscape.cpp b/demo/magicleap/src/landscape.cpp index 80b8b067..3a7843f3 100644 --- a/demo/magicleap/src/landscape.cpp +++ b/demo/magicleap/src/landscape.cpp @@ -42,11 +42,11 @@ const char* QUAD_NAMES[NUM_QUADS] = { }; const char* SVG_NAMES[NUM_QUADS] = { - "svg/nba-notext.svg", "svg/Ghostscript_Tiger.svg", + "svg/nba-notext.svg", "svg/julius-caesar-with-bg.svg", "svg/magicleap-quickstart-p03.svg", - "svg/paper.svg", + "svg/pathfinder_logo.svg", "svg/pathfinder-magicleap-demo.svg", }; From 7cd8452ffc343d193912b5117da7b52ef77e7e41 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Fri, 12 Apr 2019 14:10:54 -0500 Subject: [PATCH 29/32] Update magicleap README for SDK 0.20.0 --- demo/magicleap/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/magicleap/README.md b/demo/magicleap/README.md index 9dacb8af..fdad43f4 100644 --- a/demo/magicleap/README.md +++ b/demo/magicleap/README.md @@ -1,8 +1,8 @@ # Magic Leap demo -First, install the Magic Leap SDK. By default this is installed in `MagicLeap/mlsdk/`, for example: +First, install v0.20.0 or later of the Magic Leap SDK. By default this is installed in `MagicLeap/mlsdk/`, for example: ``` - export MAGICLEAP_SDK=~/MagicLeap/mlsdk/v0.19.0 + export MAGICLEAP_SDK=~/MagicLeap/mlsdk/v0.20.0 ``` You will also need a signing certificate. ``` From bf55026a717447029f5358ec6062b5d48f76b8c6 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 15 Apr 2019 13:24:54 -0400 Subject: [PATCH 30/32] Add basic travis CI for native and magicleap demos. --- .travis.yml | 12 ++++++++++++ demo/magicleap/Makefile | 9 +++++++++ 2 files changed, 21 insertions(+) create mode 100644 .travis.yml create mode 100644 demo/magicleap/Makefile diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..886ec066 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: rust +addons: + apt: + packages: + - libegl1-mesa-dev + - libgtk-3-dev + - libsdl2-dev +script: + - cd demo/native + - cargo build + - cd ../magicleap + - cargo build \ No newline at end of file diff --git a/demo/magicleap/Makefile b/demo/magicleap/Makefile new file mode 100644 index 00000000..43be8317 --- /dev/null +++ b/demo/magicleap/Makefile @@ -0,0 +1,9 @@ +.PHONY: debug release + +debug: + cargo build --target aarch64-linux-android + $(MAGICLEAP_SDK)/mabu -t lumin_debug PathfinderDemo.package + +release: + cargo build --release --target aarch64-linux-android + $(MAGICLEAP_SDK)/mabu -t lumin_release PathfinderDemo.package From 8b3bf7d0642cc9f95a243d0abb932c7cdca93004 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 15 Apr 2019 13:56:17 -0400 Subject: [PATCH 31/32] Use linker directly to to avoid linker errors. --- demo/magicleap/fake-ld.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/magicleap/fake-ld.sh b/demo/magicleap/fake-ld.sh index 88f32377..5efcaf5e 100755 --- a/demo/magicleap/fake-ld.sh +++ b/demo/magicleap/fake-ld.sh @@ -8,8 +8,8 @@ set -o nounset set -o pipefail TARGET=${TARGET:-"aarch64-linux-android"} -LD=${LD:-"${MAGICLEAP_SDK}/tools/toolchains/bin/${TARGET}-gcc"} -LDFLAGS=${LDFLAGS:-"--sysroot=${MAGICLEAP_SDK}/lumin -L${MAGICLEAP_SDK}/tools/toolchains/lib/gcc/${TARGET}/4.9.x ${MAGICLEAP_SDK}/lumin/usr/lib/crtbegin_so.o"} +LD=${LD:-"${MAGICLEAP_SDK}/tools/toolchains/bin/${TARGET}-ld"} +LDFLAGS=${LDFLAGS:-"--sysroot=${MAGICLEAP_SDK}/lumin -L${MAGICLEAP_SDK}/lumin/usr/lib -L${MAGICLEAP_SDK}/tools/toolchains/lib/gcc/${TARGET}/4.9.x ${MAGICLEAP_SDK}/lumin/usr/lib/crtbegin_so.o"} # Remove the -landroid flag, grr ARGS=("$@") From 214ad9de720052fc9e455fdfeda2a42b0607d480 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 15 Apr 2019 13:56:33 -0400 Subject: [PATCH 32/32] Replace readme directions with makefile targets. --- demo/magicleap/Makefile | 12 +++++++++--- demo/magicleap/README.md | 15 +++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/demo/magicleap/Makefile b/demo/magicleap/Makefile index 43be8317..32012c97 100644 --- a/demo/magicleap/Makefile +++ b/demo/magicleap/Makefile @@ -1,9 +1,15 @@ -.PHONY: debug release +.PHONY: debug release install debug: cargo build --target aarch64-linux-android - $(MAGICLEAP_SDK)/mabu -t lumin_debug PathfinderDemo.package + $(MAGICLEAP_SDK)/mabu -t debug_device PathfinderDemo.package -s $(MLCERT) release: cargo build --release --target aarch64-linux-android - $(MAGICLEAP_SDK)/mabu -t lumin_release PathfinderDemo.package + $(MAGICLEAP_SDK)/mabu -t release_device PathfinderDemo.package -s $(MLCERT) + +install: .out/PathfinderDemo/PathfinderDemo.mpk + $(MAGICLEAP_SDK)/tools/mldb/mldb install -u .out/PathfinderDemo/PathfinderDemo.mpk + +run: + ${MAGICLEAP_SDK}/tools/mldb/mldb launch -w com.mozilla.pathfinder.demo diff --git a/demo/magicleap/README.md b/demo/magicleap/README.md index fdad43f4..45eebb6f 100644 --- a/demo/magicleap/README.md +++ b/demo/magicleap/README.md @@ -9,22 +9,17 @@ First, install v0.20.0 or later of the Magic Leap SDK. By default this is instal export MLCERT=~/MagicLeap/cert/mycert.cert ``` -Now build the pathfilder demo library: +Now build the pathfinder demo library and `.mpk` archive: ``` - CFLAGS="-I${MAGICLEAP_SDK}/lumin/usr/include --sysroot=${MAGICLEAP_SDK}/lumin/usr" \ - PATH=$PATH:${MAGICLEAP_SDK}/tools/toolchains/bin/ \ - cargo build --release --target=aarch64-linux-android + cd demo/pathfinder + make release ``` -Then build the `.mpk` archive: -``` - ${MAGICLEAP_SDK}/mabu PathfinderDemo.package -t release_device -s ${MLCERT} -``` The `.mpk` can be installed: ``` - ${MAGICLEAP_SDK}/tools/mldb/mldb install -u .out/PathfinderDemo/PathfinderDemo.mpk + make install ``` and run: ``` - ${MAGICLEAP_SDK}/tools/mldb/mldb launch -w com.mozilla.pathfinder.demo + make run ```