Skip to content

Instantly share code, notes, and snippets.

@mattebb
Last active April 5, 2023 00:53
Show Gist options
  • Select an option

  • Save mattebb/69aa7c504e292761229ce78fb4db02c1 to your computer and use it in GitHub Desktop.

Select an option

Save mattebb/69aa7c504e292761229ce78fb4db02c1 to your computer and use it in GitHub Desktop.

Revisions

  1. mattebb revised this gist Apr 5, 2023. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions sync.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    // assembled from some stackoverflow answers

    const start = performance.now();

    // Draw the fullscreen quad
  2. mattebb created this gist Apr 5, 2023.
    25 changes: 25 additions & 0 deletions sync.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    const start = performance.now();

    // Draw the fullscreen quad
    twgl.drawBufferInfo(gl, quad_bufferInfo);

    let sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0);

    checkSync = () => {
    const status = gl.clientWaitSync(sync, 0, 0);
    switch (status) {
    case gl.TIMEOUT_EXPIRED:
    return setTimeout(checkSync);
    case gl.WAIT_FAILED:
    throw new Error('should never get here');
    default:
    gl.deleteSync(sync);

    const duration = (performance.now() - start);
    console.log(`finished rendering in ${duration.toFixed(1)}ms`);

    // trigger preview capture now that GL has finished rendering
    triggerPreview();
    }
    }
    setTimeout(checkSync);