mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
This reverts commit 503bb10c5b
.
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
parent
90130315a7
commit
0fed99590a
13 changed files with 97 additions and 69 deletions
|
@ -3,6 +3,7 @@
|
|||
* 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};
|
||||
|
@ -11,6 +12,10 @@ 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<
|
||||
|
@ -47,9 +52,10 @@ impl GlClearer {
|
|||
.entry((layer_id, color, depth_stencil))
|
||||
.or_insert_with(|| {
|
||||
// Save the current GL state
|
||||
let mut bound_fbos = [0, 0];
|
||||
unsafe {
|
||||
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_i32_slice(gl::DRAW_FRAMEBUFFER_BINDING, &mut bound_fbos[0..]);
|
||||
gl.get_parameter_i32_slice(gl::READ_FRAMEBUFFER_BINDING, &mut bound_fbos[1..]);
|
||||
|
||||
// Generate and set attachments of a new FBO
|
||||
let fbo = gl.create_framebuffer().ok();
|
||||
|
@ -77,8 +83,8 @@ impl GlClearer {
|
|||
}
|
||||
|
||||
// Restore the GL state
|
||||
gl.bind_framebuffer(gl::DRAW_FRAMEBUFFER, draw_fbo);
|
||||
gl.bind_framebuffer(gl::READ_FRAMEBUFFER, read_fbo);
|
||||
gl.bind_framebuffer(gl::DRAW_FRAMEBUFFER, framebuffer(bound_fbos[0] as _));
|
||||
gl.bind_framebuffer(gl::READ_FRAMEBUFFER, framebuffer(bound_fbos[1] as _));
|
||||
debug_assert_eq!(gl.get_error(), gl::NO_ERROR);
|
||||
|
||||
fbo
|
||||
|
@ -104,6 +110,7 @@ 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];
|
||||
|
@ -111,8 +118,8 @@ impl GlClearer {
|
|||
let scissor_enabled = gl.is_enabled(gl::SCISSOR_TEST);
|
||||
let rasterizer_enabled = gl.is_enabled(gl::RASTERIZER_DISCARD);
|
||||
|
||||
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_i32_slice(gl::DRAW_FRAMEBUFFER_BINDING, &mut bound_fbos[0..]);
|
||||
gl.get_parameter_i32_slice(gl::READ_FRAMEBUFFER_BINDING, &mut bound_fbos[1..]);
|
||||
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[..]);
|
||||
|
@ -133,8 +140,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, draw_fbo);
|
||||
gl.bind_framebuffer(gl::READ_FRAMEBUFFER, read_fbo);
|
||||
gl.bind_framebuffer(gl::DRAW_FRAMEBUFFER, framebuffer(bound_fbos[0] as _));
|
||||
gl.bind_framebuffer(gl::READ_FRAMEBUFFER, framebuffer(bound_fbos[1] as _));
|
||||
gl.clear_color(
|
||||
clear_color[0],
|
||||
clear_color[1],
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
* 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::{
|
||||
|
@ -24,6 +25,7 @@ use webxr_api::{
|
|||
LEFT_EYE, RIGHT_EYE, VIEWER,
|
||||
};
|
||||
|
||||
use crate::gl_utils::framebuffer;
|
||||
use crate::{SurfmanGL, SurfmanLayerManager};
|
||||
|
||||
// How far off the ground are the viewer's eyes?
|
||||
|
@ -220,10 +222,11 @@ impl DeviceAPI for GlWindowDevice {
|
|||
.device
|
||||
.context_surface_info(&self.context)
|
||||
.unwrap()
|
||||
.and_then(|info| info.framebuffer_object);
|
||||
.map(|info| info.framebuffer_object)
|
||||
.unwrap_or(0);
|
||||
unsafe {
|
||||
self.gl
|
||||
.bind_framebuffer(gl::FRAMEBUFFER, framebuffer_object);
|
||||
.bind_framebuffer(gl::FRAMEBUFFER, framebuffer(framebuffer_object));
|
||||
debug_assert_eq!(
|
||||
(
|
||||
self.gl.get_error(),
|
||||
|
@ -251,9 +254,10 @@ impl DeviceAPI for GlWindowDevice {
|
|||
.device
|
||||
.create_surface_texture(&mut self.context, surface)
|
||||
.unwrap();
|
||||
let texture_id = self.device.surface_texture_object(&surface_texture);
|
||||
let raw_texture_id = self.device.surface_texture_object(&surface_texture);
|
||||
let texture_id = NonZeroU32::new(raw_texture_id).map(gl::NativeTexture);
|
||||
let texture_target = self.device.surface_gl_texture_target();
|
||||
log::debug!("Presenting texture {:?}", texture_id);
|
||||
log::debug!("Presenting texture {}", raw_texture_id);
|
||||
|
||||
if let Some(ref shader) = self.shader {
|
||||
shader.draw_texture(
|
||||
|
@ -388,8 +392,9 @@ impl GlWindowDevice {
|
|||
let framebuffer_object = device
|
||||
.context_surface_info(&context)
|
||||
.unwrap()
|
||||
.and_then(|info| info.framebuffer_object);
|
||||
gl.bind_framebuffer(gl::FRAMEBUFFER, framebuffer_object);
|
||||
.map(|info| info.framebuffer_object)
|
||||
.unwrap_or(0);
|
||||
gl.bind_framebuffer(gl::FRAMEBUFFER, framebuffer(framebuffer_object));
|
||||
debug_assert_eq!(
|
||||
(gl.get_error(), gl.check_framebuffer_status(gl::FRAMEBUFFER)),
|
||||
(gl::NO_ERROR, gl::FRAMEBUFFER_COMPLETE)
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
* 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;
|
||||
|
@ -766,13 +767,15 @@ 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;
|
||||
let depth_stencil_texture = openxr_layer
|
||||
.depth_stencil_texture
|
||||
.map(|texture| texture.0.get());
|
||||
let texture_array_index = None;
|
||||
let origin = Point2D::new(0, 0);
|
||||
let texture_size = openxr_layer.size;
|
||||
let sub_image = Some(SubImage {
|
||||
color_texture: color_texture.map(|t| t.0),
|
||||
depth_stencil_texture: depth_stencil_texture.map(|t| t.0),
|
||||
color_texture,
|
||||
depth_stencil_texture,
|
||||
texture_array_index,
|
||||
viewport: Rect::new(origin, texture_size),
|
||||
});
|
||||
|
@ -781,8 +784,8 @@ impl LayerManagerAPI<SurfmanGL> for OpenXrLayerManager {
|
|||
.viewports
|
||||
.iter()
|
||||
.map(|&viewport| SubImage {
|
||||
color_texture: color_texture.map(|t| t.0),
|
||||
depth_stencil_texture: depth_stencil_texture.map(|t| t.0),
|
||||
color_texture,
|
||||
depth_stencil_texture,
|
||||
texture_array_index,
|
||||
viewport,
|
||||
})
|
||||
|
@ -792,7 +795,7 @@ impl LayerManagerAPI<SurfmanGL> for OpenXrLayerManager {
|
|||
contexts,
|
||||
context_id,
|
||||
layer_id,
|
||||
color_texture,
|
||||
NonZeroU32::new(color_texture).map(glow::NativeTexture),
|
||||
color_target,
|
||||
openxr_layer.depth_stencil_texture,
|
||||
);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
//! 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};
|
||||
|
@ -164,8 +165,8 @@ impl LayerManagerAPI<SurfmanGL> for SurfmanLayerManager {
|
|||
let texture_array_index = None;
|
||||
let origin = Point2D::new(0, 0);
|
||||
let sub_image = Some(SubImage {
|
||||
color_texture: color_texture.map(|nt| nt.0),
|
||||
depth_stencil_texture: depth_stencil_texture.map(|nt| nt.0),
|
||||
color_texture,
|
||||
depth_stencil_texture: depth_stencil_texture.map(|nt| nt.0.get()),
|
||||
texture_array_index,
|
||||
viewport: Rect::new(origin, surface_size),
|
||||
});
|
||||
|
@ -174,8 +175,8 @@ impl LayerManagerAPI<SurfmanGL> for SurfmanLayerManager {
|
|||
.viewports
|
||||
.iter()
|
||||
.map(|&viewport| SubImage {
|
||||
color_texture: color_texture.map(|nt| nt.0),
|
||||
depth_stencil_texture: depth_stencil_texture.map(|texture| texture.0),
|
||||
color_texture,
|
||||
depth_stencil_texture: depth_stencil_texture.map(|texture| texture.0.get()),
|
||||
texture_array_index,
|
||||
viewport,
|
||||
})
|
||||
|
@ -186,7 +187,7 @@ impl LayerManagerAPI<SurfmanGL> for SurfmanLayerManager {
|
|||
contexts,
|
||||
context_id,
|
||||
layer_id,
|
||||
color_texture,
|
||||
NonZeroU32::new(color_texture).map(gl::NativeTexture),
|
||||
color_target,
|
||||
depth_stencil_texture,
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue