Class: WebGLRenderTarget

ol/webgl/RenderTarget~WebGLRenderTarget


import WebGLRenderTarget from 'ol/webgl/RenderTarget';

This class is a wrapper around the association of both a WebGLTexture and a WebGLFramebuffer instances, simplifying initialization and binding for rendering.

new WebGLRenderTarget(helper, opt_size)

Name Type Description
helper module:ol/webgl/Helper~WebGLHelper

WebGL helper; mandatory.

size Array.<number>

Expected size of the render target texture; note: this can be changed later on.

Methods

clearCachedData()

This will cause following calls to #readAll or #readPixel to download the content of the render target into memory, which is an expensive operation. This content will be kept in cache but should be cleared after each new render.

getSize(){Array.<number>}

Returns the size of the render target texture

Returns:
Size of the render target texture

readAll(){Uint8Array}

Returns the full content of the frame buffer as a series of r, g, b, a components in the 0-255 range (unsigned byte).

Returns:
Integer array of color values

readPixel(x, y){Uint8Array}

Reads one pixel of the frame buffer as an array of r, g, b, a components in the 0-255 range (unsigned byte). If x and/or y are outside of existing data, an array filled with 0 is returned.

Name Type Description
x number

Pixel coordinate

y number

Pixel coordinate

Returns:
Integer array with one color value (4 components)

Changes the size of the render target texture. Note: will do nothing if the size is already the same.

Name Type Description
size Array.<number>

Expected size of the render target texture