Framebuffer
Source: Framebuffer.ts:69
Class represents framebuffer.
Constructor
new Framebuffer(
handler: Handler,
options?: IFrameBufferParams,
): FramebufferParameters
handler(Handler) — WebGL handler.options(IFrameBufferParams, optional) — Framebuffer options:
Instance Methods
init()
Framebuffer initialization.
readPixelBuffers()
Synchronously reads all configured async pixel buffers for the current framebuffer state. Use when the same-frame CPU readback is required.
readPixels(
res: TypedArray,
nx: number,
ny: number,
w?: number,
h?: number,
index?: number,
)
Gets pixel RGBA color from framebuffer by coordinates.
Parameters
res(TypedArray) — Normalized x - coordinate.nx(number) — Normalized x - coordinate.ny(number) — Normalized y - coordinate.w(number, optional, default: 1) — Normalized width.h(number, optional, default: 1) — Normalized height.index(number, optional, default: 0) — color attachment index.
readAllPixels(res: TypedArray, attachmentIndex?: number)
Reads all pixels(RGBA colors) from framebuffer.
Parameters
res(TypedArray) — Result array.attachmentIndex(number, optional, default: 0) — color attachment index.
getImage(): HTMLImageElement
Gets JavaScript image that in the framebuffer.
Returns
HTMLImageElement
readData(
nx: number,
ny: number,
outData: NumberArray4 | Float32Array,
attachmentIndex?: number,
): void
Reads pixel data from the buffer at the specified normalized coordinates.
Parameters
nx(number) — Normalized X coordinate in the range [0, 1], multiplied by the buffer width.ny(number) — Normalized Y coordinate in the range [0, 1], multiplied by the buffer height.outData(NumberArray4 | Float32Array) — Output array where the RGBA pixel values will be written.attachmentIndex(number, optional, default: 0) — Index of the color attachment (buffer) to read from.
Returns
void
Example
CODE
const color = new Float32Array(4);
framebuffer.readData(0.5, 0.5, color); // Reads the color at the center of the buffer