diff --git a/webxr-api/layer.rs b/webxr-api/layer.rs index b0a607f..362adb7 100644 --- a/webxr-api/layer.rs +++ b/webxr-api/layer.rs @@ -10,6 +10,7 @@ use euclid::Rect; use euclid::Size2D; use std::fmt::Debug; +use std::num::NonZeroU32; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; @@ -288,9 +289,8 @@ pub struct SubImages { #[derive(Clone, Debug)] #[cfg_attr(feature = "ipc", derive(Deserialize, Serialize))] pub struct SubImage { - pub color_texture: u32, - // TODO: make this Option - pub depth_stencil_texture: Option, + pub color_texture: Option, + pub depth_stencil_texture: Option, pub texture_array_index: Option, pub viewport: Rect, } diff --git a/webxr/Cargo.toml b/webxr/Cargo.toml index d627107..eb1ec68 100644 --- a/webxr/Cargo.toml +++ b/webxr/Cargo.toml @@ -34,7 +34,7 @@ log = "0.4.6" openxr = { version = "0.19", optional = true } serde = { version = "1.0", optional = true } glow = "0.16" -surfman = { git = "https://github.com/servo/surfman", rev = "c8d6b4b65aeab739ee7651602e29c8d58ceee123", features = [ +surfman = { git = "https://github.com/sagudev/surfman", branch = "no_gl_gen", features = [ "chains", ] } diff --git a/webxr/gl_utils.rs b/webxr/gl_utils.rs index fff7401..5bc2a7b 100644 --- a/webxr/gl_utils.rs +++ b/webxr/gl_utils.rs @@ -13,10 +13,6 @@ use webxr_api::ContextId; use webxr_api::GLContexts; use webxr_api::LayerId; -pub(crate) fn framebuffer(framebuffer: u32) -> Option { - NonZero::new(framebuffer).map(gl::NativeFramebuffer) -} - // A utility to clear a color texture and optional depth/stencil texture pub(crate) struct GlClearer { fbos: HashMap< @@ -53,10 +49,9 @@ impl GlClearer { .entry((layer_id, color, depth_stencil)) .or_insert_with(|| { // Save the current GL state - let mut bound_fbos = [0, 0]; unsafe { - gl.get_parameter_i32_slice(gl::DRAW_FRAMEBUFFER_BINDING, &mut bound_fbos[0..]); - gl.get_parameter_i32_slice(gl::READ_FRAMEBUFFER_BINDING, &mut bound_fbos[1..]); + let draw_fbo = gl.get_parameter_framebuffer(gl::DRAW_FRAMEBUFFER_BINDING); + let read_fbo = gl.get_parameter_framebuffer(gl::READ_FRAMEBUFFER_BINDING); // Generate and set attachments of a new FBO let fbo = gl.create_framebuffer().ok(); @@ -84,8 +79,8 @@ impl GlClearer { } // Restore the GL state - gl.bind_framebuffer(gl::DRAW_FRAMEBUFFER, framebuffer(bound_fbos[0] as _)); - gl.bind_framebuffer(gl::READ_FRAMEBUFFER, framebuffer(bound_fbos[1] as _)); + gl.bind_framebuffer(gl::DRAW_FRAMEBUFFER, draw_fbo); + gl.bind_framebuffer(gl::READ_FRAMEBUFFER, read_fbo); debug_assert_eq!(gl.get_error(), gl::NO_ERROR); fbo @@ -110,7 +105,6 @@ impl GlClearer { let fbo = self.fbo(gl, layer_id, color, color_target, depth_stencil); unsafe { // Save the current GL state - let mut bound_fbos = [0, 0]; let mut clear_color = [0., 0., 0., 0.]; let mut clear_depth = [0.]; let mut clear_stencil = [0]; @@ -120,8 +114,8 @@ impl GlClearer { let scissor_enabled = gl.is_enabled(gl::SCISSOR_TEST); let rasterizer_enabled = gl.is_enabled(gl::RASTERIZER_DISCARD); - gl.get_parameter_i32_slice(gl::DRAW_FRAMEBUFFER_BINDING, &mut bound_fbos[0..]); - gl.get_parameter_i32_slice(gl::READ_FRAMEBUFFER_BINDING, &mut bound_fbos[1..]); + let draw_fbo = gl.get_parameter_framebuffer(gl::DRAW_FRAMEBUFFER_BINDING); + let read_fbo = gl.get_parameter_framebuffer(gl::READ_FRAMEBUFFER_BINDING); gl.get_parameter_f32_slice(gl::COLOR_CLEAR_VALUE, &mut clear_color[..]); gl.get_parameter_f32_slice(gl::DEPTH_CLEAR_VALUE, &mut clear_depth[..]); gl.get_parameter_i32_slice(gl::STENCIL_CLEAR_VALUE, &mut clear_stencil[..]); @@ -142,8 +136,8 @@ impl GlClearer { gl.clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT | gl::STENCIL_BUFFER_BIT); // Restore the GL state - gl.bind_framebuffer(gl::DRAW_FRAMEBUFFER, framebuffer(bound_fbos[0] as _)); - gl.bind_framebuffer(gl::READ_FRAMEBUFFER, framebuffer(bound_fbos[1] as _)); + gl.bind_framebuffer(gl::DRAW_FRAMEBUFFER, draw_fbo); + gl.bind_framebuffer(gl::READ_FRAMEBUFFER, read_fbo); gl.clear_color( clear_color[0], clear_color[1], diff --git a/webxr/glwindow/mod.rs b/webxr/glwindow/mod.rs index 28aee37..74b0968 100644 --- a/webxr/glwindow/mod.rs +++ b/webxr/glwindow/mod.rs @@ -2,15 +2,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -use crate::gl_utils::framebuffer; use crate::{SurfmanGL, SurfmanLayerManager}; use core::slice; use euclid::{ Angle, Point2D, Rect, RigidTransform3D, Rotation3D, Size2D, Transform3D, UnknownUnit, Vector3D, }; use glow::{self as gl, Context as Gl, HasContext}; -use std::ffi::c_void; -use std::num::NonZeroU32; use std::rc::Rc; use surfman::chains::{PreserveBuffer, SwapChain, SwapChainAPI, SwapChains, SwapChainsAPI}; use surfman::{ @@ -214,10 +211,10 @@ impl DeviceAPI for GlWindowDevice { .context_surface_info(&self.context) .unwrap() .map(|info| info.framebuffer_object) - .unwrap_or(0); + .flatten(); unsafe { self.gl - .bind_framebuffer(gl::FRAMEBUFFER, framebuffer(framebuffer_object)); + .bind_framebuffer(gl::FRAMEBUFFER, framebuffer_object); debug_assert_eq!( ( self.gl.get_error(), @@ -245,10 +242,9 @@ impl DeviceAPI for GlWindowDevice { .device .create_surface_texture(&mut self.context, surface) .unwrap(); - let raw_texture_id = self.device.surface_texture_object(&surface_texture); - let texture_id = NonZeroU32::new(raw_texture_id).map(gl::NativeTexture); + let texture_id = self.device.surface_texture_object(&surface_texture); let texture_target = self.device.surface_gl_texture_target(); - log::debug!("Presenting texture {}", raw_texture_id); + log::debug!("Presenting texture {:?}", texture_id); if let Some(ref shader) = self.shader { shader.draw_texture( @@ -384,8 +380,8 @@ impl GlWindowDevice { .context_surface_info(&context) .unwrap() .map(|info| info.framebuffer_object) - .unwrap_or(0); - gl.bind_framebuffer(gl::FRAMEBUFFER, framebuffer(framebuffer_object)); + .flatten(); + gl.bind_framebuffer(gl::FRAMEBUFFER, framebuffer_object); debug_assert_eq!( (gl.get_error(), gl.check_framebuffer_status(gl::FRAMEBUFFER)), (gl::NO_ERROR, gl::FRAMEBUFFER_COMPLETE) diff --git a/webxr/openxr/mod.rs b/webxr/openxr/mod.rs index 2981c91..12d2a5c 100644 --- a/webxr/openxr/mod.rs +++ b/webxr/openxr/mod.rs @@ -24,7 +24,6 @@ use openxr::{ }; use std::collections::HashMap; use std::mem; -use std::num::NonZeroU32; use std::ops::Deref; use std::sync::{Arc, Mutex}; use std::thread; @@ -802,15 +801,13 @@ impl LayerManagerAPI for OpenXrLayerManager { })?; let color_texture = device.surface_texture_object(color_surface_texture); let color_target = device.surface_gl_texture_target(); - let depth_stencil_texture = openxr_layer - .depth_stencil_texture - .map(|texture| texture.0.get()); + let depth_stencil_texture = openxr_layer.depth_stencil_texture; let texture_array_index = None; let origin = Point2D::new(0, 0); let texture_size = openxr_layer.size; let sub_image = Some(SubImage { - color_texture, - depth_stencil_texture, + color_texture: color_texture.map(|t| t.0), + depth_stencil_texture: depth_stencil_texture.map(|t| t.0), texture_array_index, viewport: Rect::new(origin, texture_size), }); @@ -819,8 +816,8 @@ impl LayerManagerAPI for OpenXrLayerManager { .viewports .iter() .map(|&viewport| SubImage { - color_texture, - depth_stencil_texture, + color_texture: color_texture.map(|t| t.0), + depth_stencil_texture: depth_stencil_texture.map(|t| t.0), texture_array_index, viewport, }) @@ -830,7 +827,7 @@ impl LayerManagerAPI for OpenXrLayerManager { contexts, context_id, layer_id, - NonZeroU32::new(color_texture).map(glow::NativeTexture), + color_texture, color_target, openxr_layer.depth_stencil_texture, ); diff --git a/webxr/surfman_layer_manager.rs b/webxr/surfman_layer_manager.rs index 33ef961..7a1a974 100644 --- a/webxr/surfman_layer_manager.rs +++ b/webxr/surfman_layer_manager.rs @@ -8,7 +8,6 @@ use crate::gl_utils::GlClearer; use euclid::{Point2D, Rect, Size2D}; use glow::{self as gl, Context as Gl, HasContext, PixelUnpackData}; use std::collections::HashMap; -use std::num::NonZeroU32; use surfman::chains::{PreserveBuffer, SwapChains, SwapChainsAPI}; use surfman::{Context as SurfmanContext, Device as SurfmanDevice, SurfaceAccess, SurfaceTexture}; use webxr_api::{ @@ -163,8 +162,8 @@ impl LayerManagerAPI for SurfmanLayerManager { let texture_array_index = None; let origin = Point2D::new(0, 0); let sub_image = Some(SubImage { - color_texture, - depth_stencil_texture: depth_stencil_texture.map(|nt| nt.0.get()), + color_texture: color_texture.map(|nt| nt.0), + depth_stencil_texture: depth_stencil_texture.map(|nt| nt.0), texture_array_index, viewport: Rect::new(origin, surface_size), }); @@ -173,8 +172,8 @@ impl LayerManagerAPI for SurfmanLayerManager { .viewports .iter() .map(|&viewport| SubImage { - color_texture, - depth_stencil_texture: depth_stencil_texture.map(|texture| texture.0.get()), + color_texture: color_texture.map(|nt| nt.0), + depth_stencil_texture: depth_stencil_texture.map(|texture| texture.0), texture_array_index, viewport, }) @@ -185,7 +184,7 @@ impl LayerManagerAPI for SurfmanLayerManager { contexts, context_id, layer_id, - NonZeroU32::new(color_texture).map(gl::NativeTexture), + color_texture, color_target, depth_stencil_texture, );