Skip to content
This repository has been archived by the owner on Jan 31, 2025. It is now read-only.

Commit

Permalink
Auto merge of #33 - asajeffrey:optional-glsync, r=Manishearth
Browse files Browse the repository at this point in the history
Make GLsync object optional

If a webxr device and webgl are both running on the same thread, then there's no need for a GLsync object.
  • Loading branch information
bors-servo authored Jul 27, 2019
2 parents 35559ae + d441781 commit 96c964c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
7 changes: 6 additions & 1 deletion webxr-api/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ pub trait Device: 'static {
/// This method should render a GL texture to the device.
/// While this method is being called, the device has unique access
/// to the texture. The texture should be sync'd using glWaitSync before being used.
fn render_animation_frame(&mut self, texture_id: u32, size: UntypedSize2D<i32>, sync: GLsync);
fn render_animation_frame(
&mut self,
texture_id: u32,
size: UntypedSize2D<i32>,
sync: Option<GLsync>,
);

/// Inputs registered with the device on initialization. More may be added, which
/// should be communicated through a yet-undecided event mechanism
Expand Down
2 changes: 1 addition & 1 deletion webxr-api/webgl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub type WebGLTextureId = GLuint;
// the matching webrender trait.
pub trait WebGLExternalImageApi: Send {
/// Lock the WebGL context, and get back a sync object for its current state.
fn lock(&self, id: WebGLContextId) -> GLsync;
fn lock(&self, id: WebGLContextId) -> Option<GLsync>;

/// Unlock the WebGL context.
fn unlock(&self, id: WebGLContextId);
Expand Down
13 changes: 11 additions & 2 deletions webxr/glwindow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ impl Device for GlWindowDevice {
}
}

fn render_animation_frame(&mut self, texture_id: u32, size: UntypedSize2D<i32>, sync: GLsync) {
fn render_animation_frame(
&mut self,
texture_id: u32,
size: UntypedSize2D<i32>,
sync: Option<GLsync>,
) {
self.window.make_current();

let width = size.width as GLsizei;
Expand All @@ -121,9 +126,13 @@ impl Device for GlWindowDevice {

self.gl.clear_color(0.2, 0.3, 0.3, 1.0);
self.gl.clear(gl::COLOR_BUFFER_BIT);
self.gl.wait_sync(sync, 0, gl::TIMEOUT_IGNORED);
debug_assert_eq!(self.gl.get_error(), gl::NO_ERROR);

if let Some(sync) = sync {
self.gl.wait_sync(sync, 0, gl::TIMEOUT_IGNORED);
debug_assert_eq!(self.gl.get_error(), gl::NO_ERROR);
}

self.gl
.bind_framebuffer(gl::READ_FRAMEBUFFER, self.read_fbo);
debug_assert_eq!(self.gl.get_error(), gl::NO_ERROR);
Expand Down
7 changes: 5 additions & 2 deletions webxr/headless/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,11 @@ impl Device for HeadlessDevice {
Frame { transform, inputs }
}

fn render_animation_frame(&mut self, _: GLuint, _: Size2D<i32>, sync: GLsync) {
self.gl.wait_sync(sync, 0, gl::TIMEOUT_IGNORED);
fn render_animation_frame(&mut self, _: GLuint, _: Size2D<i32>, sync: Option<GLsync>) {
if let Some(sync) = sync {
self.gl.wait_sync(sync, 0, gl::TIMEOUT_IGNORED);
debug_assert_eq!(self.gl.get_error(), gl::NO_ERROR);
}
}

fn initial_inputs(&self) -> Vec<InputSource> {
Expand Down

0 comments on commit 96c964c

Please sign in to comment.