Skip to content

Commit

Permalink
Use surfman that has glow instead of GL_gen
Browse files Browse the repository at this point in the history
Signed-off-by: sagudev <[email protected]>
  • Loading branch information
sagudev committed Jan 8, 2025
1 parent 4fd38cf commit c9e5a36
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 42 deletions.
6 changes: 3 additions & 3 deletions webxr-api/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<NonZeroU32>
pub depth_stencil_texture: Option<u32>,
pub color_texture: Option<NonZeroU32>,
pub depth_stencil_texture: Option<NonZeroU32>,
pub texture_array_index: Option<u32>,
pub viewport: Rect<i32, Viewport>,
}
2 changes: 1 addition & 1 deletion webxr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ openxr = { version = "0.19", optional = true }
serde = { version = "1.0", optional = true }
glow = "0.16"
raw-window-handle = "0.6"
surfman = { git = "https://github.com/servo/surfman", rev = "300789ddbda45c89e9165c31118bf1c4c07f89f6", features = [
surfman = { git = "https://github.com/sagudev/surfman", branch = "no_gl_gen", features = [
"chains",
"sm-raw-window-handle-06",
] }
Expand Down
22 changes: 8 additions & 14 deletions webxr/gl_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ use webxr_api::ContextId;
use webxr_api::GLContexts;
use webxr_api::LayerId;

pub(crate) fn framebuffer(framebuffer: u32) -> Option<gl::NativeFramebuffer> {
NonZero::new(framebuffer).map(gl::NativeFramebuffer)
}

// A utility to clear a color texture and optional depth/stencil texture
pub(crate) struct GlClearer {
fbos: HashMap<
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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];
Expand All @@ -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[..]);
Expand All @@ -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],
Expand Down
15 changes: 6 additions & 9 deletions webxr/glwindow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
* 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 raw_window_handle::DisplayHandle;
use std::num::NonZeroU32;
use std::rc::Rc;
use surfman::chains::{PreserveBuffer, SwapChain, SwapChainAPI, SwapChains, SwapChainsAPI};
use surfman::{
Expand Down Expand Up @@ -220,10 +218,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(),
Expand Down Expand Up @@ -251,10 +249,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(
Expand Down Expand Up @@ -390,8 +387,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)
Expand Down
15 changes: 6 additions & 9 deletions webxr/openxr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -802,15 +801,13 @@ impl LayerManagerAPI<SurfmanGL> 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),
});
Expand All @@ -819,8 +816,8 @@ impl LayerManagerAPI<SurfmanGL> 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,
})
Expand All @@ -830,7 +827,7 @@ impl LayerManagerAPI<SurfmanGL> for OpenXrLayerManager {
contexts,
context_id,
layer_id,
NonZeroU32::new(color_texture).map(glow::NativeTexture),
color_texture,
color_target,
openxr_layer.depth_stencil_texture,
);
Expand Down
11 changes: 5 additions & 6 deletions webxr/surfman_layer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -163,8 +162,8 @@ impl LayerManagerAPI<SurfmanGL> 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),
});
Expand All @@ -173,8 +172,8 @@ impl LayerManagerAPI<SurfmanGL> 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,
})
Expand All @@ -185,7 +184,7 @@ impl LayerManagerAPI<SurfmanGL> for SurfmanLayerManager {
contexts,
context_id,
layer_id,
NonZeroU32::new(color_texture).map(gl::NativeTexture),
color_texture,
color_target,
depth_stencil_texture,
);
Expand Down

0 comments on commit c9e5a36

Please sign in to comment.