Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use surfman that has glow instead of GL_gen #255

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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",
] }

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
16 changes: 6 additions & 10 deletions webxr/glwindow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
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
Loading