ExternalTexture
Quick answer
ExternalTexture binds a video element or VideoFrame as a texture without copying pixels into GPU memory. Create it with device.createExternalTexture({source, sampler}), then sample it like any texture. It suits live camera feeds and video layers, whereas static images belong in a regular Texture.
device. createExternalTexture ({ source, sampler }) → ExternalTexture
Key points
- Creation takes source, optional width and height, sampler and colorSpace.
- setSampler(sampler) swaps filtering without rebuilding the binding.
- Content updates are tracked by updateTimestamp for redraw decisions.
Example
const video = document.querySelector('video');
await video.play();
const videoTexture = device.createExternalTexture({
source: video,
sampler: {
minFilter: 'linear',
magFilter: 'linear',
addressModeU: 'clamp-to-edge',
addressModeV: 'clamp-to-edge'
}
});
const model = new Model(device, {
vs: screenVS,
fs: screenFS,
bindings: {
uVideo: videoTexture,
uVideoSampler: videoTexture.sampler
},
vertexCount: 6,
topology: 'triangle-list'
});let lastStamp = -1;
function frame() {
if (videoTexture.updateTimestamp !== lastStamp) {
lastStamp = videoTexture.updateTimestamp;
const pass = device.beginRenderPass({ clearColor: [0, 0, 0, 1] });
model.draw(pass);
pass.end();
device.submit();
}
requestAnimationFrame(frame);
}
frame();
Notes
- A video that has not started playing yields a black or zero-sized texture.
- External textures cannot be render targets or read back to the CPU.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). ExternalTexture. https://www.jingweizhi.com/en/lumagl/api/external-texture.html (accessed 2026-11-03).