webgl-utils

Methods

(static) createProgram(shaders, opt_attribsopt, opt_locationsopt, opt_errorCallback)

Creates a program, attaches shaders, binds attrib locations, links the
program and calls useProgram.

Parameters:
Name Type Attributes Description
shaders Array.<WebGLShader>

The shaders to attach

opt_attribs Array.<string> <optional>

An array of attribs names. Locations will be assigned by index if not passed in

opt_locations Array.<number> <optional>

The locations for the. A parallel array to opt_attribs letting you assign locations.

opt_errorCallback module:webgl-utils.ErrorCallback

callback for errors. By default it just prints an error to the console
on error. If you want something else pass an callback. It's passed an error message.

(static) createProgramFromScripts(gl, shaderScriptIds, opt_attribsopt, opt_locationsopt, opt_errorCallback) → {WebGLProgram}

Creates a program from 2 script tags.

Parameters:
Name Type Attributes Description
gl WebGLRenderingContext

The WebGLRenderingContext
to use.

shaderScriptIds Array.<string>

Array of ids of the script
tags for the shaders. The first is assumed to be the
vertex shader, the second the fragment shader.

opt_attribs Array.<string> <optional>

An array of attribs names. Locations will be assigned by index if not passed in

opt_locations Array.<number> <optional>

The locations for the. A parallel array to opt_attribs letting you assign locations.

opt_errorCallback module:webgl-utils.ErrorCallback

callback for errors. By default it just prints an error to the console
on error. If you want something else pass an callback. It's passed an error message.

Returns:
Type:
WebGLProgram

The created program.

(static) createProgramFromSources(gl, shaderSourcess, opt_attribsopt, opt_locationsopt, opt_errorCallback) → {WebGLProgram}

Creates a program from 2 sources.

Parameters:
Name Type Attributes Description
gl WebGLRenderingContext

The WebGLRenderingContext
to use.

shaderSourcess Array.<string>

Array of sources for the
shaders. The first is assumed to be the vertex shader,
the second the fragment shader.

opt_attribs Array.<string> <optional>

An array of attribs names. Locations will be assigned by index if not passed in

opt_locations Array.<number> <optional>

The locations for the. A parallel array to opt_attribs letting you assign locations.

opt_errorCallback module:webgl-utils.ErrorCallback

callback for errors. By default it just prints an error to the console
on error. If you want something else pass an callback. It's passed an error message.

Returns:
Type:
WebGLProgram

The created program.

(static) resizeCanvasToDisplaySize(canvas, multiplieropt) → {boolean}

Resize a canvas to match the size its displayed.

Parameters:
Name Type Attributes Description
canvas HTMLCanvasElement

The canvas to resize.

multiplier number <optional>

amount to multiply by.
Pass in window.devicePixelRatio for native pixels.

Returns:
Type:
boolean

true if the canvas was resized.

Type Definitions

ErrorCallback(msg)

Error Callback

Parameters:
Name Type Description
msg string

error message.