diff --git a/Cargo.lock b/Cargo.lock index ba24425d..18ff3a79 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -148,6 +148,19 @@ name = "byteorder" version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "canvas_glutin_minimal" +version = "0.1.0" +dependencies = [ + "gl 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "glutin 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", + "pathfinder_canvas 0.1.0", + "pathfinder_geometry 0.3.0", + "pathfinder_gl 0.1.0", + "pathfinder_gpu 0.1.0", + "pathfinder_renderer 0.1.0", +] + [[package]] name = "canvas_minimal" version = "0.1.0" @@ -419,6 +432,16 @@ dependencies = [ "sdl2-sys 0.32.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "derivative" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "dirs" version = "1.0.5" @@ -707,6 +730,72 @@ dependencies = [ "x11-dl 2.18.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "glutin" +version = "0.21.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)", + "derivative 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "glutin_egl_sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "glutin_emscripten_sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "glutin_gles2_sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "glutin_glx_sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "glutin_wgl_sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libloading 0.5.0 (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)", + "parking_lot 0.7.1 (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.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winit 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "glutin_egl_sys" +version = "0.1.3" +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)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "glutin_emscripten_sys" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "glutin_gles2_sys" +version = "0.1.3" +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)", + "objc 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "glutin_glx_sys" +version = "0.1.5" +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)", + "x11-dl 2.18.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "glutin_wgl_sys" +version = "0.1.3" +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 = "harfbuzz" version = "0.3.1" @@ -2115,6 +2204,29 @@ dependencies = [ "x11-dl 2.18.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "winit" +version = "0.19.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.15 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.0.4 (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.54 (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.7 (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" @@ -2191,6 +2303,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" "checksum crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f8306fcef4a7b563b76b7dd949ca48f52bc1141aa067d2ea09565f3e2652aa5c" "checksum deflate 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)" = "8a6abb26e16e8d419b5c78662aa9f82857c2386a073da266840e474d5055ec86" +"checksum derivative 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6073e9676dbebdddeabaeb63e3b7cefd23c86f5c41d381ee1237cc77b1079898" "checksum dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" "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" @@ -2221,6 +2334,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum gl_generator 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "75d69f914b49d9ff32fdf394cbd798f8c716d74fd19f9cc29da3e99797b2a78d" "checksum gleam 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)" = "7f46fd8874e043ffac0d638ed1567a2584f7814f6d72b4db37ab1689004a26c4" "checksum glutin 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "535c6eda58adbb227604b2db10a022ffd6339d7ea3e970f338e7d98aeb24fcc3" +"checksum glutin 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cb26027a84c3b9e1949ef0df0b6a3db8d0c124243a5c161ea25c7def90cb1474" +"checksum glutin_egl_sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "23f48987ab6cb2b61ad903b59e54a2fd0c380a7baff68cffd6826b69a73dd326" +"checksum glutin_emscripten_sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "245b3fdb08df6ffed7585365851f8404af9c7e2dd4b59f15262e968b6a95a0c7" +"checksum glutin_gles2_sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "89996c30857ae1b4de4b5189abf1ea822a20a9fe9e1c93e5e7b862ff0bdd5cdf" +"checksum glutin_glx_sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1290a5ca5e46fcfa7f66f949cc9d9194b2cb6f2ed61892c8c2b82343631dba57" +"checksum glutin_wgl_sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f801bbc91efc22dd1c4818a47814fc72bf74d024510451b119381579bfa39021" "checksum harfbuzz 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "46f7426266a5ece3e49eae6f48e602c0f8c39917354a847eac9c06437dcde8da" "checksum harfbuzz-sys 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e1042ab0b3e7bc1ff64f7f5935778b644ff2194a1cae5ec52167127d3fd23961" "checksum hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3bae29b6653b3412c2e71e9d486db9f9df5d701941d86683005efb9f2d28e3da" @@ -2365,6 +2484,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "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 winit 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d233301129ddd33260b47f76900b50e154b7254546e2edba0e5468a1a5fe4de3" "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" diff --git a/Cargo.toml b/Cargo.toml index eaa64cae..a975a99e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ members = [ "demo/common", "demo/magicleap", "demo/native", + "examples/canvas_glutin_minimal", "examples/canvas_minimal", "examples/canvas_moire", "examples/canvas_text", diff --git a/demo/common/src/lib.rs b/demo/common/src/lib.rs index e55dc0e8..2121a93d 100644 --- a/demo/common/src/lib.rs +++ b/demo/common/src/lib.rs @@ -25,6 +25,7 @@ use clap::{App, Arg}; use pathfinder_geometry::basic::vector::{Vector2F, Vector2I}; use pathfinder_geometry::basic::rect::RectF; use pathfinder_geometry::basic::transform2d::Transform2DF; +use pathfinder_geometry::basic::transform3d::Transform3DF; use pathfinder_geometry::color::ColorU; use pathfinder_gl::GLDevice; use pathfinder_gpu::Device; @@ -53,6 +54,9 @@ const CAMERA_SCALE_SPEED_2D: f32 = 6.0; // How much the scene is scaled when a zoom button is clicked. const CAMERA_ZOOM_AMOUNT_2D: f32 = 0.1; +// Half of the eye separation distance. +const DEFAULT_EYE_OFFSET: f32 = 0.025; + const LIGHT_BG_COLOR: ColorU = ColorU { r: 248, g: 248, @@ -323,11 +327,23 @@ impl DemoApp where W: Window { } Event::SetEyeTransforms(new_eye_transforms) => { if let Camera::ThreeD { + ref mut scene_transform, ref mut eye_transforms, .. } = self.camera { *eye_transforms = new_eye_transforms; + // Calculate the new scene transform by lerp'ing the eye transforms. + *scene_transform = eye_transforms[0]; + for (index, eye_transform) in eye_transforms.iter().enumerate().skip(1) { + let weight = 1.0 / (index + 1) as f32; + scene_transform.perspective.transform = scene_transform.perspective.transform.lerp(weight, &eye_transform.perspective.transform); + scene_transform.modelview_to_eye = scene_transform.modelview_to_eye.lerp(weight, &eye_transform.modelview_to_eye); + } + // TODO: calculate the eye offset from the eye transforms? + let z_offset = -DEFAULT_EYE_OFFSET * scene_transform.perspective.transform.c0.x(); + scene_transform.modelview_to_eye = scene_transform.modelview_to_eye + .pre_mul(&Transform3DF::from_translation(0.0, 0.0, z_offset)); } } Event::KeyDown(Keycode::Alphanumeric(b'w')) => { diff --git a/demo/magicleap/src/main.cpp b/demo/magicleap/src/main.cpp index 8cddb51e..c44a0c99 100644 --- a/demo/magicleap/src/main.cpp +++ b/demo/magicleap/src/main.cpp @@ -163,28 +163,36 @@ static void onNewInitArg(void* app_handle) return; } - if (arg_list_len) { - if (MLResult_Ok != MLLifecycleGetInitArgByIndex(arg_list, 0, &arg)) { - ML_LOG(Error, "%s: Failed to get init arg.", application_name); + if (!arg_list_len) { 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 != MLLifecycleGetInitArgByIndex(arg_list, 0, &arg)) { + ML_LOG(Error, "%s: Failed to get init arg.", application_name); + } - if (MLResult_Ok != MLFileInfoGetFileName(file_info, &file_name)) { - ML_LOG(Error, "%s: Failed to get file name.", 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) { + return; + } + + 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; + } + + if (!file_name) { + ML_LOG(Error, "%s: File name is null.", application_name); + return; } // Tell pathfinder to load the file @@ -198,6 +206,7 @@ static void onNewInitArg(void* app_handle) return; } + ML_LOG(Info, "%s: Loading %s.", application_name, file_name); magicleap_pathfinder_demo_load(app, file_name); MLLifecycleFreeInitArgList(&arg_list); } diff --git a/examples/canvas_glutin_minimal/Cargo.toml b/examples/canvas_glutin_minimal/Cargo.toml new file mode 100644 index 00000000..37b25e22 --- /dev/null +++ b/examples/canvas_glutin_minimal/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "canvas_glutin_minimal" +version = "0.1.0" +authors = ["Patrick Walton "] +edition = "2018" + +[dependencies] +gl = "0.6" +glutin = "0.21" + +[dependencies.pathfinder_canvas] +path = "../../canvas" + +[dependencies.pathfinder_geometry] +path = "../../geometry" + +[dependencies.pathfinder_gl] +path = "../../gl" + +[dependencies.pathfinder_gpu] +path = "../../gpu" + +[dependencies.pathfinder_renderer] +path = "../../renderer" + diff --git a/examples/canvas_glutin_minimal/src/main.rs b/examples/canvas_glutin_minimal/src/main.rs new file mode 100644 index 00000000..ce9360f4 --- /dev/null +++ b/examples/canvas_glutin_minimal/src/main.rs @@ -0,0 +1,97 @@ +// pathfinder/examples/canvas_glutin_minimal/src/main.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. + +//! Demonstrates how to use the Pathfinder canvas API with `glutin`. + +use glutin::dpi::PhysicalSize; +use glutin::{ContextBuilder, ControlFlow, Event, EventsLoop, GlProfile, GlRequest, KeyboardInput}; +use glutin::{VirtualKeyCode, WindowBuilder, WindowEvent}; +use pathfinder_canvas::{CanvasFontContext, CanvasRenderingContext2D, Path2D}; +use pathfinder_geometry::basic::vector::{Vector2F, Vector2I}; +use pathfinder_geometry::basic::rect::RectF; +use pathfinder_geometry::color::ColorF; +use pathfinder_gl::{GLDevice, GLVersion}; +use pathfinder_gpu::resources::FilesystemResourceLoader; +use pathfinder_gpu::{ClearParams, Device}; +use pathfinder_renderer::concurrent::rayon::RayonExecutor; +use pathfinder_renderer::concurrent::scene_proxy::SceneProxy; +use pathfinder_renderer::gpu::renderer::{DestFramebuffer, Renderer}; +use pathfinder_renderer::options::RenderOptions; + +fn main() { + // Calculate the right logical size of the window. + let mut event_loop = EventsLoop::new(); + let hidpi_factor = event_loop.get_primary_monitor().get_hidpi_factor(); + let window_size = Vector2I::new(640, 480); + let physical_window_size = PhysicalSize::new(window_size.x() as f64, window_size.y() as f64); + let logical_window_size = physical_window_size.to_logical(hidpi_factor); + + // Open a window. + let window_builder = WindowBuilder::new().with_title("Minimal example") + .with_dimensions(logical_window_size); + + // Create an OpenGL 3.x context for Pathfinder to use. + let gl_context = ContextBuilder::new().with_gl(GlRequest::Latest) + .with_gl_profile(GlProfile::Core) + .build_windowed(window_builder, &event_loop) + .unwrap(); + + // Load OpenGL, and make the context current. + let gl_context = unsafe { gl_context.make_current().unwrap() }; + gl::load_with(|name| gl_context.get_proc_address(name) as *const _); + + // Create a Pathfinder renderer. + let mut renderer = Renderer::new(GLDevice::new(GLVersion::GL3, 0), + &FilesystemResourceLoader::locate(), + DestFramebuffer::full_window(window_size)); + + // Clear to white. + renderer.device.clear(&ClearParams { color: Some(ColorF::white()), ..ClearParams::default() }); + + // Make a canvas. We're going to draw a house. + let mut canvas = CanvasRenderingContext2D::new(CanvasFontContext::new(), window_size.to_f32()); + + // Set line width. + canvas.set_line_width(10.0); + + // Draw walls. + canvas.stroke_rect(RectF::new(Vector2F::new(75.0, 140.0), Vector2F::new(150.0, 110.0))); + + // Draw door. + canvas.fill_rect(RectF::new(Vector2F::new(130.0, 190.0), Vector2F::new(40.0, 60.0))); + + // Draw roof. + let mut path = Path2D::new(); + path.move_to(Vector2F::new(50.0, 140.0)); + path.line_to(Vector2F::new(150.0, 60.0)); + path.line_to(Vector2F::new(250.0, 140.0)); + path.close_path(); + canvas.stroke_path(path); + + // Render the canvas to screen. + let scene = SceneProxy::from_scene(canvas.into_scene(), RayonExecutor); + scene.build_and_render(&mut renderer, RenderOptions::default()); + gl_context.swap_buffers().unwrap(); + + // Wait for a keypress. + event_loop.run_forever(|event| { + match event { + Event::WindowEvent { event: WindowEvent::CloseRequested, .. } | + Event::WindowEvent { + event: WindowEvent::KeyboardInput { + input: KeyboardInput { virtual_keycode: Some(VirtualKeyCode::Escape), .. }, + .. + }, + .. + } => ControlFlow::Break, + _ => ControlFlow::Continue, + } + }) +} diff --git a/geometry/src/basic/transform3d.rs b/geometry/src/basic/transform3d.rs index 9b7aa4bd..bdd71c0c 100644 --- a/geometry/src/basic/transform3d.rs +++ b/geometry/src/basic/transform3d.rs @@ -176,6 +176,15 @@ impl Transform3DF { ) } + /// Linearly interpolate between transforms + pub fn lerp(&self, weight: f32, other: &Transform3DF) -> Transform3DF { + let c0 = self.c0 * F32x4::splat(weight) + other.c0 * F32x4::splat(1.0 - weight); + let c1 = self.c1 * F32x4::splat(weight) + other.c1 * F32x4::splat(1.0 - weight); + let c2 = self.c2 * F32x4::splat(weight) + other.c2 * F32x4::splat(1.0 - weight); + let c3 = self.c3 * F32x4::splat(weight) + other.c3 * F32x4::splat(1.0 - weight); + Transform3DF { c0, c1, c2, c3 } + } + /// Just like `gluPerspective()`. #[inline] pub fn from_perspective(fov_y: f32, aspect: f32, z_near: f32, z_far: f32) -> Transform3DF { diff --git a/gl/src/lib.rs b/gl/src/lib.rs index 030f63f9..aa08233a 100644 --- a/gl/src/lib.rs +++ b/gl/src/lib.rs @@ -304,12 +304,16 @@ impl Device for GLDevice { } } - fn get_vertex_attr(&self, program: &Self::Program, name: &str) -> GLVertexAttr { + fn get_vertex_attr(&self, program: &Self::Program, name: &str) -> Option { let name = CString::new(format!("a{}", name)).unwrap(); let attr = unsafe { - gl::GetAttribLocation(program.gl_program, name.as_ptr() as *const GLchar) as GLuint + gl::GetAttribLocation(program.gl_program, name.as_ptr() as *const GLchar) }; ck(); - GLVertexAttr { attr } + if attr < 0 { + None + } else { + Some(GLVertexAttr { attr: attr as GLuint }) + } } fn get_uniform(&self, program: &GLProgram, name: &str) -> GLUniform { diff --git a/gpu/src/lib.rs b/gpu/src/lib.rs index cfe4b4ee..7d1fde49 100644 --- a/gpu/src/lib.rs +++ b/gpu/src/lib.rs @@ -44,7 +44,7 @@ pub trait Device { vertex_shader: Self::Shader, fragment_shader: Self::Shader, ) -> Self::Program; - fn get_vertex_attr(&self, program: &Self::Program, name: &str) -> Self::VertexAttr; + fn get_vertex_attr(&self, program: &Self::Program, name: &str) -> Option; fn get_uniform(&self, program: &Self::Program, name: &str) -> Self::Uniform; fn use_program(&self, program: &Self::Program); fn configure_vertex_attr(&self, attr: &Self::VertexAttr, descriptor: &VertexAttrDescriptor); diff --git a/renderer/src/gpu/renderer.rs b/renderer/src/gpu/renderer.rs index 0579d0f2..80bdc477 100644 --- a/renderer/src/gpu/renderer.rs +++ b/renderer/src/gpu/renderer.rs @@ -944,12 +944,12 @@ where BufferUploadMode::Dynamic, ); - let tess_coord_attr = device.get_vertex_attr(&fill_program.program, "TessCoord"); - let from_px_attr = device.get_vertex_attr(&fill_program.program, "FromPx"); - let to_px_attr = device.get_vertex_attr(&fill_program.program, "ToPx"); - let from_subpx_attr = device.get_vertex_attr(&fill_program.program, "FromSubpx"); - let to_subpx_attr = device.get_vertex_attr(&fill_program.program, "ToSubpx"); - let tile_index_attr = device.get_vertex_attr(&fill_program.program, "TileIndex"); + let tess_coord_attr = device.get_vertex_attr(&fill_program.program, "TessCoord").unwrap(); + let from_px_attr = device.get_vertex_attr(&fill_program.program, "FromPx").unwrap(); + let to_px_attr = device.get_vertex_attr(&fill_program.program, "ToPx").unwrap(); + let from_subpx_attr = device.get_vertex_attr(&fill_program.program, "FromSubpx").unwrap(); + let to_subpx_attr = device.get_vertex_attr(&fill_program.program, "ToSubpx").unwrap(); + let tile_index_attr = device.get_vertex_attr(&fill_program.program, "TileIndex").unwrap(); device.bind_vertex_array(&vertex_array); device.use_program(&fill_program.program); @@ -1029,10 +1029,14 @@ where ) -> AlphaTileVertexArray { let (vertex_array, vertex_buffer) = (device.create_vertex_array(), device.create_buffer()); - let tess_coord_attr = device.get_vertex_attr(&alpha_tile_program.program, "TessCoord"); - let tile_origin_attr = device.get_vertex_attr(&alpha_tile_program.program, "TileOrigin"); - let backdrop_attr = device.get_vertex_attr(&alpha_tile_program.program, "Backdrop"); - let tile_index_attr = device.get_vertex_attr(&alpha_tile_program.program, "TileIndex"); + let tess_coord_attr = device.get_vertex_attr(&alpha_tile_program.program, "TessCoord") + .unwrap(); + let tile_origin_attr = device.get_vertex_attr(&alpha_tile_program.program, "TileOrigin") + .unwrap(); + let backdrop_attr = device.get_vertex_attr(&alpha_tile_program.program, "Backdrop") + .unwrap(); + let tile_index_attr = device.get_vertex_attr(&alpha_tile_program.program, "TileIndex") + .unwrap(); let color_tex_coord_attr = device.get_vertex_attr(&alpha_tile_program.program, "ColorTexCoord"); @@ -1074,14 +1078,16 @@ where offset: 6, divisor: 1, }); - device.configure_vertex_attr(&color_tex_coord_attr, &VertexAttrDescriptor { - size: 2, - class: VertexAttrClass::FloatNorm, - attr_type: VertexAttrType::U16, - stride: MASK_TILE_INSTANCE_SIZE, - offset: 8, - divisor: 1, - }); + if let Some(color_tex_coord_attr) = color_tex_coord_attr { + device.configure_vertex_attr(&color_tex_coord_attr, &VertexAttrDescriptor { + size: 2, + class: VertexAttrClass::FloatNorm, + attr_type: VertexAttrType::U16, + stride: MASK_TILE_INSTANCE_SIZE, + offset: 8, + divisor: 1, + }); + } device.bind_buffer(quad_vertex_indices_buffer, BufferTarget::Index); AlphaTileVertexArray { vertex_array, vertex_buffer } @@ -1108,8 +1114,10 @@ where ) -> SolidTileVertexArray { let (vertex_array, vertex_buffer) = (device.create_vertex_array(), device.create_buffer()); - let tess_coord_attr = device.get_vertex_attr(&solid_tile_program.program, "TessCoord"); - let tile_origin_attr = device.get_vertex_attr(&solid_tile_program.program, "TileOrigin"); + let tess_coord_attr = device.get_vertex_attr(&solid_tile_program.program, "TessCoord") + .unwrap(); + let tile_origin_attr = device.get_vertex_attr(&solid_tile_program.program, "TileOrigin") + .unwrap(); let color_tex_coord_attr = device.get_vertex_attr(&solid_tile_program.program, "ColorTexCoord"); @@ -1135,14 +1143,16 @@ where offset: 0, divisor: 1, }); - device.configure_vertex_attr(&color_tex_coord_attr, &VertexAttrDescriptor { - size: 2, - class: VertexAttrClass::FloatNorm, - attr_type: VertexAttrType::U16, - stride: SOLID_TILE_INSTANCE_SIZE, - offset: 4, - divisor: 1, - }); + if let Some(color_tex_coord_attr) = color_tex_coord_attr { + device.configure_vertex_attr(&color_tex_coord_attr, &VertexAttrDescriptor { + size: 2, + class: VertexAttrClass::FloatNorm, + attr_type: VertexAttrType::U16, + stride: SOLID_TILE_INSTANCE_SIZE, + offset: 4, + divisor: 1, + }); + } device.bind_buffer(quad_vertex_indices_buffer, BufferTarget::Index); SolidTileVertexArray { vertex_array, vertex_buffer } @@ -1409,7 +1419,8 @@ where quad_vertex_indices_buffer: &D::Buffer, ) -> PostprocessVertexArray { let vertex_array = device.create_vertex_array(); - let position_attr = device.get_vertex_attr(&postprocess_program.program, "Position"); + let position_attr = device.get_vertex_attr(&postprocess_program.program, "Position") + .unwrap(); device.bind_vertex_array(&vertex_array); device.use_program(&postprocess_program.program); @@ -1462,8 +1473,7 @@ where let vertex_array = device.create_vertex_array(); let (vertex_buffer, index_buffer) = (device.create_buffer(), device.create_buffer()); - let position_attr = device.get_vertex_attr(&stencil_program.program, "Position"); - + let position_attr = device.get_vertex_attr(&stencil_program.program, "Position").unwrap(); device.bind_vertex_array(&vertex_array); device.use_program(&stencil_program.program); device.bind_buffer(&vertex_buffer, BufferTarget::Vertex); @@ -1529,8 +1539,8 @@ where ) -> ReprojectionVertexArray { let vertex_array = device.create_vertex_array(); - let position_attr = device.get_vertex_attr(&reprojection_program.program, "Position"); - + let position_attr = device.get_vertex_attr(&reprojection_program.program, "Position") + .unwrap(); device.bind_vertex_array(&vertex_array); device.use_program(&reprojection_program.program); device.bind_buffer(quad_vertex_positions_buffer, BufferTarget::Vertex); diff --git a/resources/svg/julius-caesar-with-bg.svg b/resources/svg/julius-caesar-with-bg.svg index 8ec6bddb..bdcd8f2a 100644 --- a/resources/svg/julius-caesar-with-bg.svg +++ b/resources/svg/julius-caesar-with-bg.svg @@ -23,7 +23,7 @@ image/svg+xml - + @@ -36,13 +36,13 @@ guidetolerance="10" inkscape:pageopacity="0" inkscape:pageshadow="2" - inkscape:window-width="1105" - inkscape:window-height="1261" + inkscape:window-width="1762" + inkscape:window-height="1278" id="namedview11456" showgrid="false" - inkscape:zoom="1.0809887" - inkscape:cx="300.4245" - inkscape:cy="526.37" + inkscape:zoom="1.5287489" + inkscape:cx="608.99861" + inkscape:cy="552.88589" inkscape:window-x="0" inkscape:window-y="0" inkscape:window-maximized="0" @@ -567,7 +567,7 @@ height="747.23267" x="-0.00037672394" y="18.039042" - style="stroke-width:0.75;fill:#ffffff" /> + style="stroke-width:0.75;fill:#fff6d5" /> diff --git a/resources/svg/magicleap-quickstart-p03.svg b/resources/svg/magicleap-quickstart-p03.svg index 62d4b33f..dce06ca0 100644 --- a/resources/svg/magicleap-quickstart-p03.svg +++ b/resources/svg/magicleap-quickstart-p03.svg @@ -36,8 +36,8 @@ guidetolerance="10" inkscape:pageopacity="0" inkscape:pageshadow="2" - inkscape:window-width="1056" - inkscape:window-height="873" + inkscape:window-width="2049" + inkscape:window-height="838" id="namedview30747" showgrid="false" inkscape:zoom="0.5" @@ -446,11 +446,11 @@ + DebugTextureVertexArray where D: Device { let (vertex_buffer, index_buffer) = (device.create_buffer(), device.create_buffer()); let vertex_array = device.create_vertex_array(); - let position_attr = device.get_vertex_attr(&debug_texture_program.program, "Position"); - let tex_coord_attr = device.get_vertex_attr(&debug_texture_program.program, "TexCoord"); + let position_attr = device.get_vertex_attr(&debug_texture_program.program, "Position") + .unwrap(); + let tex_coord_attr = device.get_vertex_attr(&debug_texture_program.program, "TexCoord") + .unwrap(); device.bind_vertex_array(&vertex_array); device.use_program(&debug_texture_program.program); @@ -624,7 +626,8 @@ impl DebugSolidVertexArray where D: Device { let (vertex_buffer, index_buffer) = (device.create_buffer(), device.create_buffer()); let vertex_array = device.create_vertex_array(); - let position_attr = device.get_vertex_attr(&debug_solid_program.program, "Position"); + let position_attr = device.get_vertex_attr(&debug_solid_program.program, "Position") + .unwrap(); device.bind_vertex_array(&vertex_array); device.use_program(&debug_solid_program.program); device.bind_buffer(&vertex_buffer, BufferTarget::Vertex);