mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Use surfman with glow bindings (#34328)
* Use glowing surfman Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Port https://github.com/servo/webxr/pull/255 Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * fixups rebase Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * fmt Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Update surfman Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Fix stale TODO Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
parent
fdbfecf7dd
commit
503bb10c5b
13 changed files with 70 additions and 97 deletions
|
@ -3,7 +3,6 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::num::NonZero;
|
||||
|
||||
use glow as gl;
|
||||
use glow::{Context as Gl, HasContext};
|
||||
|
@ -12,10 +11,6 @@ use webxr_api::{ContextId, GLContexts, LayerId};
|
|||
|
||||
use crate::SurfmanGL;
|
||||
|
||||
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<
|
||||
|
@ -52,10 +47,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();
|
||||
|
@ -83,8 +77,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 +104,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];
|
||||
|
@ -118,8 +111,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[..]);
|
||||
|
@ -140,8 +133,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],
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use core::slice;
|
||||
use std::num::NonZeroU32;
|
||||
use std::rc::Rc;
|
||||
|
||||
use euclid::{
|
||||
|
@ -25,7 +24,6 @@ use webxr_api::{
|
|||
VIEWER,
|
||||
};
|
||||
|
||||
use crate::gl_utils::framebuffer;
|
||||
use crate::{SurfmanGL, SurfmanLayerManager};
|
||||
|
||||
// How far off the ground are the viewer's eyes?
|
||||
|
@ -222,11 +220,10 @@ impl DeviceAPI for GlWindowDevice {
|
|||
.device
|
||||
.context_surface_info(&self.context)
|
||||
.unwrap()
|
||||
.map(|info| info.framebuffer_object)
|
||||
.unwrap_or(0);
|
||||
.and_then(|info| info.framebuffer_object);
|
||||
unsafe {
|
||||
self.gl
|
||||
.bind_framebuffer(gl::FRAMEBUFFER, framebuffer(framebuffer_object));
|
||||
.bind_framebuffer(gl::FRAMEBUFFER, framebuffer_object);
|
||||
debug_assert_eq!(
|
||||
(
|
||||
self.gl.get_error(),
|
||||
|
@ -254,10 +251,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(
|
||||
|
@ -392,9 +388,8 @@ impl GlWindowDevice {
|
|||
let framebuffer_object = device
|
||||
.context_surface_info(&context)
|
||||
.unwrap()
|
||||
.map(|info| info.framebuffer_object)
|
||||
.unwrap_or(0);
|
||||
gl.bind_framebuffer(gl::FRAMEBUFFER, framebuffer(framebuffer_object));
|
||||
.and_then(|info| info.framebuffer_object);
|
||||
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)
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::num::NonZeroU32;
|
||||
use std::ops::Deref;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
|
@ -767,15 +766,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),
|
||||
});
|
||||
|
@ -784,8 +781,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,
|
||||
})
|
||||
|
@ -795,7 +792,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,
|
||||
);
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
//! An implementation of layer management using surfman
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::num::NonZeroU32;
|
||||
|
||||
use euclid::{Point2D, Rect, Size2D};
|
||||
use glow::{self as gl, Context as Gl, HasContext, PixelUnpackData};
|
||||
|
@ -165,8 +164,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),
|
||||
});
|
||||
|
@ -175,8 +174,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,
|
||||
})
|
||||
|
@ -187,7 +186,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,
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue