File tree Expand file tree Collapse file tree 1 file changed +42
-5
lines changed Expand file tree Collapse file tree 1 file changed +42
-5
lines changed Original file line number Diff line number Diff line change @@ -3378,12 +3378,49 @@ dictionary GPUExternalTextureDescriptor : GPUObjectDescriptorBase {
3378
3378
</div>
3379
3379
3380
3380
<div class="example">
3381
- Creating an external texture from a video element:
3381
+ Rendering using an video element external texture at the page animation frame rate:
3382
+
3382
3383
<pre highlight="js">
3383
- const videoElement = document.querySelector('video');
3384
- const externalTexture = gpuDevice.importExternalTexture({
3385
- source: videoElement
3386
- });
3384
+ const videoElement = document.createElement('video');
3385
+ // ... set up videoElement, wait for it to be ready...
3386
+
3387
+ let externalTexture;
3388
+
3389
+ function frame() {
3390
+ requestAnimationFrame(frame);
3391
+
3392
+ // Re-import only if necessary
3393
+ if (!externalTexture || externalTexture.expired) {
3394
+ externalTexture = gpuDevice.importExternalTexture({
3395
+ source: videoElement
3396
+ });
3397
+ }
3398
+
3399
+ // ... render using externalTexture...
3400
+ }
3401
+ requestAnimationFrame(frame);
3402
+ </pre>
3403
+ </div>
3404
+
3405
+ <div class="example">
3406
+ Rendering using an video element external texture at the video's frame rate, if
3407
+ `requestVideoFrameCallback` is available:
3408
+
3409
+ <pre highlight="js">
3410
+ const videoElement = document.createElement('video');
3411
+ // ... set up videoElement...
3412
+
3413
+ function frame() {
3414
+ videoElement.requestVideoFrameCallback(frame);
3415
+
3416
+ // Always re-import, because we know the video frame has advanced
3417
+ const externalTexture = gpuDevice.importExternalTexture({
3418
+ source: videoElement
3419
+ });
3420
+
3421
+ // ... render using externalTexture...
3422
+ }
3423
+ videoElement.requestVideoFrameCallback(frame);
3387
3424
</pre>
3388
3425
</div>
3389
3426
You can’t perform that action at this time.
0 commit comments