diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2019-09-04 14:20:29 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-04 14:20:29 -0400 |
commit | 4260063220a132641e6685bf95d426def6e3b75d (patch) | |
tree | 620b996baf6c4c3c5a09faea24b747c59280007e /components/script | |
parent | 068997cd30be6f2988f4b89ab39995aa3266cc39 (diff) | |
parent | a0cb841d2a175a09f2aeb478513ee976e9047e92 (diff) | |
download | servo-4260063220a132641e6685bf95d426def6e3b75d.tar.gz servo-4260063220a132641e6685bf95d426def6e3b75d.zip |
Auto merge of #24094 - asajeffrey:webxr-depth-n-stencil, r=jdm
Create depth and stencil attachments for XRWebGLLayer
<!-- Please describe your changes on the following line: -->
Creates depth and stencil attachments for an XRWebGLLayer if requested.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #24082
- [x] These changes do not require tests because not sure how we'd test for this
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24094)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/webglrenderingcontext.rs | 4 | ||||
-rw-r--r-- | components/script/dom/xrwebgllayer.rs | 64 |
2 files changed, 63 insertions, 5 deletions
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index c4c580cda32..e50d70cb916 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -1102,6 +1102,10 @@ impl WebGLRenderingContext { self.bound_framebuffer.get() } + pub fn bound_renderbuffer(&self) -> Option<DomRoot<WebGLRenderbuffer>> { + self.bound_renderbuffer.get() + } + pub fn extension_manager(&self) -> &WebGLExtensions { &self.extension_manager } diff --git a/components/script/dom/xrwebgllayer.rs b/components/script/dom/xrwebgllayer.rs index 713546e1129..a1e912252e9 100644 --- a/components/script/dom/xrwebgllayer.rs +++ b/components/script/dom/xrwebgllayer.rs @@ -91,20 +91,25 @@ impl XRWebGLLayer { let cx = global.get_cx(); let old_fbo = context.bound_framebuffer(); + let old_rbo = context.bound_renderbuffer(); let old_texture = context .textures() .active_texture_for_image_target(TexImageTarget::Texture2D); - // Step 8.2. "Initialize layer’s framebuffer to a new opaque framebuffer created with context." + // Step 9.2. "Initialize layer’s framebuffer to a new opaque framebuffer created with + // context and layerInit’s depth, stencil, and alpha values." let framebuffer = context.CreateFramebuffer().ok_or(Error::Operation)?; - // Step 8.3. "Allocate and initialize resources compatible with session’s XR device, + // Step 9.3. "Allocate and initialize resources compatible with session’s XR device, // including GPU accessible memory buffers, as required to support the compositing of layer." // Create a new texture with size given by the session's recommended resolution let texture = context.CreateTexture().ok_or(Error::Operation)?; + let render_buffer = context.CreateRenderbuffer().ok_or(Error::Operation)?; let resolution = session.with_session(|s| s.recommended_framebuffer_resolution()); let mut pixels = CustomAutoRooter::new(None); + let mut clear_bits = constants::COLOR_BUFFER_BIT; + context.BindTexture(constants::TEXTURE_2D, Some(&texture)); let sc = context.TexImage2D( constants::TEXTURE_2D, @@ -128,15 +133,64 @@ impl XRWebGLLayer { 0, ); + // Create backing store and bind a renderbuffer if requested + if init.depth || init.stencil { + let (internal_format, attachment) = if init.depth && init.stencil { + clear_bits |= constants::DEPTH_BUFFER_BIT | constants::STENCIL_BUFFER_BIT; + ( + constants::DEPTH_STENCIL, + constants::DEPTH_STENCIL_ATTACHMENT, + ) + } else if init.depth { + clear_bits |= constants::DEPTH_BUFFER_BIT; + (constants::DEPTH_COMPONENT16, constants::DEPTH_ATTACHMENT) + } else { + clear_bits |= constants::STENCIL_BUFFER_BIT; + (constants::STENCIL_INDEX8, constants::STENCIL_ATTACHMENT) + }; + context.BindRenderbuffer(constants::RENDERBUFFER, Some(&render_buffer)); + context.RenderbufferStorage( + constants::RENDERBUFFER, + internal_format, + resolution.width, + resolution.height, + ); + context.FramebufferRenderbuffer( + constants::FRAMEBUFFER, + attachment, + constants::RENDERBUFFER, + Some(&render_buffer), + ); + } + + context.initialize_framebuffer(clear_bits); + // Restore the WebGL state while complaining about global mutable state + let fb_status = context.CheckFramebufferStatus(constants::FRAMEBUFFER); + let gl_status = context.GetError(); context.BindTexture(constants::TEXTURE_2D, old_texture.as_ref().map(|t| &**t)); context.BindFramebuffer(constants::FRAMEBUFFER, old_fbo.as_ref().map(|f| &**f)); + context.BindRenderbuffer(constants::RENDERBUFFER, old_rbo.as_ref().map(|f| &**f)); - // Step 8.4: "If layer’s resources were unable to be created for any reason, + // Step 9.4: "If layer’s resources were unable to be created for any reason, // throw an OperationError and abort these steps." - sc.or(Err(Error::Operation))?; + if let Err(err) = sc { + error!("TexImage2D error {:?} while creating XR context", err); + return Err(Error::Operation); + } + if fb_status != constants::FRAMEBUFFER_COMPLETE { + error!( + "Framebuffer error {:x} while creating XR context", + fb_status + ); + return Err(Error::Operation); + } + if gl_status != constants::NO_ERROR { + error!("GL error {:x} while creating XR context", gl_status); + return Err(Error::Operation); + } - // Step 9. "Return layer." + // Step 10. "Return layer." Ok(XRWebGLLayer::new( &global.global(), session, |