Framebuffer
Quick answer
Framebuffer combines color and depth attachments into an offscreen render target whose pixels stay in textures for later sampling or readback. Create it with device.createFramebuffer({width, height, colorAttachments, depthStencilAttachment}), then pass it to beginRenderPass to draw offscreen. Recreate it whenever the canvas or attachment size changes.
device. createFramebuffer ({ width, height, colorAttachments, depthStencilAttachment }) → Framebuffer
Key points
- colorAttachments accept Texture, TextureView or a format string.
- Pass the framebuffer to beginRenderPass to redirect rendering.
- Attached textures can be sampled by a later pass.
Example
const color = device.createTexture({
width: 512,
height: 512,
format: 'rgba8unorm',
usage: Texture.SAMPLE | Texture.RENDER | Texture.COPY_DST,
sampler: { minFilter: 'linear', magFilter: 'linear' }
});
const depth = device.createTexture({
width: 512,
height: 512,
format: device.preferredDepthFormat,
usage: Texture.RENDER
});
const fbo = device.createFramebuffer({
width: 512,
height: 512,
colorAttachments: [color],
depthStencilAttachment: depth
});
const pass = device.beginRenderPass({
framebuffer: fbo,
clearColor: [0.04, 0.06, 0.09, 1]
});
pass.setPipeline(pipeline);
pass.setVertexArray(vertexArray);
pass.draw({ vertexCount: 3 });
pass.end();
device.submit();const post = device.createRenderPipeline({
vs: postVS,
fs: postFS,
topology: 'triangle-list',
bufferLayout: [
{ name: 'positions', stepMode: 'vertex', format: 'float32x2' }
]
});
const screen = device.beginRenderPass({ clearColor: [0, 0, 0, 1] });
screen.setPipeline(post);
screen.setVertexArray(quadArray);
screen.setBindings({ uScene: color });
screen.draw({ vertexCount: 6 });
screen.end();
device.submit();
Notes
- Attachments must match the declared width, height and compatible formats.
- Sampling a texture while it is still attached as a render target is invalid.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). Framebuffer. https://www.jingweizhi.com/en/lumagl/api/framebuffer.html (accessed 2026-11-03).