Framebuffer

Class represents framebuffer.

Constructor

new Framebuffer(handler, optionsopt)

Parameters:
NameTypeAttributesDescription
handlerHandler

WebGL handler.

optionsIFrameBufferParams<optional>

Framebuffer options:

Methods

bindOutputTexture(texture, glAttachmentopt)

Bind buffer texture.

Parameters:
NameTypeAttributesDefaultDescription
textureWebGLTexture

Output texture.

glAttachmentnumber<optional>
0

color attachment index.

getImage() → {HTMLImageElement}

Gets JavaScript image that in the framebuffer.

Returns:
Type: 
HTMLImageElement

init()

Framebuffer initialization.

readAllPixels(res, attachmentIndexopt)

Reads all pixels(RGBA colors) from framebuffer.

Parameters:
NameTypeAttributesDefaultDescription
resTypedArray

Result array.

attachmentIndexnumber<optional>
0

color attachment index.

readData(nx, ny, outData, attachmentIndexopt) → {void}

Reads pixel data from the buffer at the specified normalized coordinates.

Parameters:
NameTypeAttributesDefaultDescription
nxnumber

Normalized X coordinate in the range [0, 1], multiplied by the buffer width.

nynumber

Normalized Y coordinate in the range [0, 1], multiplied by the buffer height.

outDataNumberArray4 | Float32Array

Output array where the RGBA pixel values will be written.

attachmentIndexnumber<optional>
0

Index of the color attachment (buffer) to read from.

Returns:
Type: 
void
Example
const color = new Float32Array(4);
framebuffer.readData(0.5, 0.5, color); // Reads the color at the center of the buffer

readPixels(res, nx, ny, wopt, hopt, indexopt)

Gets pixel RGBA color from framebuffer by coordinates.

Parameters:
NameTypeAttributesDefaultDescription
resTypedArray

Normalized x - coordinate.

nxnumber

Normalized x - coordinate.

nynumber

Normalized y - coordinate.

wnumber<optional>
1

Normalized width.

hnumber<optional>
1

Normalized height.

indexnumber<optional>
0

color attachment index.