Atlaslog
Atlaslog / luma.gl / API reference / CommandEncoder
luma.gl · API reference

CommandEncoder

Quick answer

CommandEncoder records an ordered stream of commands: it begins render and compute passes, copies buffers and textures, and resolves queries, then finish() seals an immutable CommandBuffer. Create one per frame with device.createCommandEncoder and finish it before submitting. It mirrors the WebGPU GPUCommandEncoder interface.

Last verified 2026-11-03 · luma.gl 9.4 · Cite this page
device. createCommandEncoder ( props ?) → CommandEncoder
Key points
Example
const encoder = device.createCommandEncoder({ id: 'frame' });

/* 第一趟:离屏渲染 */
const offscreen = encoder.beginRenderPass({
  framebuffer: fbo,
  clearColor: [0, 0, 0, 1]
});
offscreen.setPipeline(offscreenPipeline);
offscreen.setVertexArray(quadArray);
offscreen.draw({ vertexCount: 6 });
offscreen.end();

/* 第二趟:画到画布 */
const screen = encoder.beginRenderPass({
  clearColor: [0.04, 0.06, 0.09, 1]
});
screen.setPipeline(postPipeline);
screen.setVertexArray(quadArray);
screen.setBindings({ uScene: colorTexture });
screen.draw({ vertexCount: 6 });
screen.end();

const commandBuffer = encoder.finish();
device.submit(commandBuffer);
const encoder = device.createCommandEncoder();

const pass = encoder.beginRenderPass({
  framebuffer: fbo,
  clearColor: [0.1, 0.2, 0.3, 1]
});
pass.end();

encoder.copyTextureToBuffer(copyOptions);

device.submit(encoder.finish());

const pixels = await readbackBuffer.readAsync();
Notes
Runnable examplesChinese originalAll API references
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). CommandEncoder. https://www.jingweizhi.com/en/lumagl/api/command-encoder.html (accessed 2026-11-03).