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

Save / restore state when updating opaque framebuffer bindings #27316

Merged
merged 2 commits into from
Jul 20, 2020
Merged
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 29 additions & 2 deletions components/script/dom/xrwebgllayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,27 @@ impl XRWebGLLayer {
WebGLTextureId::maybe_new(sub_images.sub_image.as_ref()?.color_texture)?;
let color_texture = WebGLTexture::new(context, color_texture_id);
let target = self.texture_target();
// TODO: rebind the current bindings

// Save the current bindings
let saved_framebuffer = context.get_draw_framebuffer_slot().get();
let saved_framebuffer_target = framebuffer.target();
let saved_texture_id = context
.textures()
.active_texture_slot(target, context.webgl_version())
.ok()
.and_then(|slot| slot.get().map(|texture| texture.id()));

// We have to pick a framebuffer target.
// If there is a draw framebuffer, we use its target,
// otherwise we just use DRAW_FRAMEBUFFER.
let framebuffer_target = saved_framebuffer
.as_ref()
.and_then(|fb| fb.target())
.unwrap_or(constants::DRAW_FRAMEBUFFER);

// Update the attachments
context.send_command(WebGLCommand::BindTexture(target, Some(color_texture_id)));
framebuffer.bind(constants::FRAMEBUFFER);
framebuffer.bind(framebuffer_target);
framebuffer
.texture2d_even_if_opaque(
constants::COLOR_ATTACHMENT0,
Expand All @@ -253,6 +271,15 @@ impl XRWebGLLayer {
)
.ok()?;
}

// Restore the old bindings
context.send_command(WebGLCommand::BindTexture(target, saved_texture_id));
if let Some(framebuffer_target) = saved_framebuffer_target {
framebuffer.bind(framebuffer_target);
}
if let Some(framebuffer) = saved_framebuffer {
framebuffer.bind(framebuffer_target);
}
Some(())
}

Expand Down