Handler

A WebGL handler for accessing low-level WebGL capabilities.

Constructor

new Handler(canvasTarget, paramsopt)

Parameters:
NameTypeAttributesDescription
canvasTargetstring | HTMLCanvasElement

Canvas element target. or undefined creates hidden canvas and handler becomes hidden.

paramsObject<optional>

Handler options:

Properties
NameTypeAttributesDescription
anisotropynumber<optional>

Anisotropy filter degree. 8 is default.

widthnumber<optional>

Hidden handler width. 256 is default.

heightnumber<optional>

Hidden handler height. 256 is default.

extensionsArray.<string><optional>

Additional WebGL extension list. Available by default: EXT_texture_filter_anisotropic.

Methods

(protected) _animationFrameCallback()

Make animation.

(protected) _initProgramController(sc)

Used in addProgram

Parameters:
NameTypeDescription
scProgramController

Program controller

(protected) _setDefaults()

Sets default gl render parameters. Used in init function.

addProgram(program, notActivateopt) → {Program}

Adds shader program to the handler.

Parameters:
NameTypeAttributesDefaultDescription
programProgram

Shader program.

notActivateboolean<optional>
false

If it's true program will not compile.

Returns:
Type: 
Program

addPrograms(programsArr)

Adds shader programs to the handler.

Parameters:
NameTypeDescription
programsArrArray.<Program>

Shader program array.

clearFrame()

Clearing gl frame.

createArrayBuffer(array, itemSize, numItems, usageopt) → {WebGLBufferExt}

Creates ARRAY buffer.

Parameters:
NameTypeAttributesDefaultDescription
arrayTypedArray

Input array.

itemSizenumber

Array item size.

numItemsnumber

Items quantity.

usagenumber<optional>
STATIC_DRAW

Parameter of the bufferData call can be one of STATIC_DRAW, DYNAMIC_DRAW, or STREAM_DRAW.

Returns:
Type: 
WebGLBufferExt

createArrayBufferLength(size, usageopt) → {WebGLBufferExt}

Creates ARRAY buffer specific length.

Parameters:
NameTypeAttributesDefaultDescription
sizenumber
usagenumber<optional>
STATIC_DRAW

Parameter of the bufferData call can be one of STATIC_DRAW, DYNAMIC_DRAW, or STREAM_DRAW.

Returns:
Type: 
WebGLBufferExt

createDefaultTexture(params, success)

Creates default texture object

Parameters:
NameTypeDescription
paramsIDefaultTextureParams | null

Texture parameters:

success

createElementArrayBuffer(array, itemSize, numItems, usageopt) → {Object}

Creates ELEMENT ARRAY buffer.

Parameters:
NameTypeAttributesDefaultDescription
arrayTypedArray

Input array.

itemSizenumber

Array item size.

numItemsnumber

Items quantity.

usagenumber<optional>
STATIC_DRAW

Parameter of the bufferData call can be one of STATIC_DRAW, DYNAMIC_DRAW, or STREAM_DRAW.

Returns:
Type: 
Object

createEmptyTexture2DExt(widthopt, heightopt, filteropt, internalFormatopt, formatopt, typeopt, levelopt) → {WebGLTexture|null}

Creates empty texture.

Parameters:
NameTypeAttributesDefaultDescription
widthnumber<optional>
1

Specifies the width of the texture image.

heightnumber<optional>
1

Specifies the width of the texture image.

filterstring<optional>
"NEAREST"

Specifies GL_TEXTURE_MIN(MAX)_FILTER texture value.

internalFormatstring<optional>
"RGBA"

Specifies the color components in the texture.

formatstring<optional>
"RGBA"

Specifies the format of the texel data.

typestring<optional>
"UNSIGNED_BYTE"

Specifies the data type of the texel data.

levelnumber<optional>
0

Specifies the level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.

Returns:
  • WebGL texture object.
Type: 
WebGLTexture | null

createEmptyTexture_l(width, height, internalFormatopt) → {WebGLTexture|null}

Creates empty LINEAR filtered texture.

Parameters:
NameTypeAttributesDescription
widthnumber

Empty texture width.

heightnumber

Empty texture height.

internalFormatnumber<optional>
Returns:
  • WebGL texture object.
Type: 
WebGLTexture | null

createEmptyTexture_n(width, height, internalFormatopt) → {WebGLTexture|null}

Creates Empty NEAREST filtered texture.

Parameters:
NameTypeAttributesDescription
widthnumber

Empty texture width.

heightnumber

Empty texture height.

internalFormatnumber<optional>
Returns:
  • WebGL texture object.
Type: 
WebGLTexture | null

createStreamArrayBuffer(itemSize, numItems, usageopt, bytesopt) → {WebGLBufferExt}

Creates STREAM_DRAW ARRAY buffer.

Parameters:
NameTypeAttributesDefaultDescription
itemSizenumber

Array item size.

numItemsnumber

Items quantity.

usagenumber<optional>
STATIC_DRAW

Parameter of the bufferData call can be one of STATIC_DRAW, DYNAMIC_DRAW, or STREAM_DRAW.

bytesnumber<optional>
4
Returns:
Type: 
WebGLBufferExt

createTexture_a_webgl1(image, internalFormatopt, textureopt) → {WebGLTexture|null}

Creates ANISOTROPY filter texture.

Parameters:
NameTypeAttributesDefaultDescription
imageImageSource

Image or Canvas object.

internalFormatnumber<optional>
textureWebGLTexture | null<optional>
null
Returns:
  • WebGL texture object.
Type: 
WebGLTexture | null

createTexture_a_webgl2(image, internalFormatopt, textureopt) → {WebGLTexture|null}

Creates ANISOTROPY filter texture.

Parameters:
NameTypeAttributesDefaultDescription
imageImageSource

Image or Canvas object.

internalFormatnumber<optional>
textureWebGLTexture | null<optional>
null
Returns:
  • WebGL texture object.
Type: 
WebGLTexture | null

createTexture_l_webgl1(image, internalFormatopt, textureopt) → {WebGLTexture|null}

Creates LINEAR filter texture.

Parameters:
NameTypeAttributesDefaultDescription
imageImageSource

Image or Canvas object.

internalFormatnumber<optional>
textureWebGLTexture | null<optional>
null
Returns:
  • WebGL texture object.
Type: 
WebGLTexture | null

createTexture_l_webgl2(image, internalFormatopt, textureopt) → {WebGLTexture|null}

Creates LINEAR filter texture.

Parameters:
NameTypeAttributesDefaultDescription
imageImageSource

Image or Canvas object.

internalFormatnumber<optional>
textureWebGLTexture | null<optional>
null
Returns:
  • WebGL texture object.
Type: 
WebGLTexture | null

createTexture_mm_webgl1(image, internalFormatopt, textureopt) → {WebGLTexture|null}

Creates MIPMAP filter texture.

Parameters:
NameTypeAttributesDefaultDescription
imageImageSource

Image or Canvas object.

internalFormatnumber<optional>
textureWebGLTexture | null<optional>
null
Returns:
  • WebGL texture object.
Type: 
WebGLTexture | null

createTexture_mm_webgl2(image, internalFormatopt, textureopt) → {WebGLTexture|null}

Creates MIPMAP filter texture.

Parameters:
NameTypeAttributesDefaultDescription
imageImageSource

Image or Canvas object.

internalFormatnumber<optional>
textureWebGLTexture | null<optional>
null
Returns:
  • WebGL texture object.
Type: 
WebGLTexture | null

createTexture_n_webgl1(image, internalFormatopt, textureopt) → {WebGLTexture|null}

Creates NEAREST filter texture.

Parameters:
NameTypeAttributesDefaultDescription
imageHTMLCanvasElement | Image

Image or Canvas object.

internalFormatnumber<optional>
textureWebGLTexture | null<optional>
null
Returns:
  • WebGL texture object.
Type: 
WebGLTexture | null

createTexture_n_webgl2(image, internalFormatopt, textureopt) → {WebGLTexture|null}

Creates NEAREST filter texture.

Parameters:
NameTypeAttributesDefaultDescription
imageImageSource

Image or Canvas object.

internalFormatnumber<optional>
textureWebGLTexture | null<optional>
null
Returns:
  • WebGL texture object.
Type: 
WebGLTexture | null

destroy()

getCenter() → {number}

Returns canvas center coordinates.

Returns:
Type: 
number

getClientAspect() → {number}

Returns canvas aspect ratio.

Returns:
Type: 
number

getHeight() → {number}

Returns context screen height.

Returns:
Type: 
number

getWidth() → {number}

Returns context screen width.

Returns:
Type: 
number

initialize()

Main function that initialize handler.

initializeExtension(extensionStr, showLog) → {any}

Initialize additional WebGL extensions.

Parameters:
NameTypeDefaultDescription
extensionStrstring

Extension name.

showLogbooleanfalse

Show logging.

Returns:
Type: 
any

isWebGl2()

Check is gl context type equals webgl2

loadCubeMapTexture(params) → {WebGLTexture|null}

Creates cube texture.

Parameters:
NameTypeDescription
paramsTexture3DParams

Face image urls:

Properties
NameTypeDescription
pxstring

Positive X or right image url.

nxstring

Negative X or left image url.

pystring

Positive Y or up image url.

nystring

Negative Y or bottom image url.

pzstring

Positive Z or face image url.

nzstring

Negative Z or back image url.

Returns:
  • WebGL texture object.
Type: 
WebGLTexture | null

removeProgram(name)

Removes shader program from handler.

Parameters:
NameTypeDescription
namestring

Shader program name.

setFrameCallback(callback)

Sets animation frame function.

Parameters:
NameTypeDescription
callbackfunction

Frame callback.

setSize(w, h)

Sets handler canvas size.

Parameters:
NameTypeDescription
wnumber

Canvas width.

hnumber

Canvas height.

setStreamArrayBuffer(buffer, array, offsetopt) → {WebGLBufferExt}

Sets stream buffer.

Parameters:
NameTypeAttributesDefaultDescription
bufferWebGLBufferExt
arrayTypedArray
offsetnumber<optional>
0
Returns:
Type: 
WebGLBufferExt

start()

Starts animation loop.

(static) getContext(canvas, contextAttributesopt) → {WebGLContextExt|null}

Returns a drawing context on the canvas, or null if the context identifier is not supported.

Parameters:
NameTypeAttributesDescription
canvasHTMLCanvasElement

HTML canvas object.

contextAttributesany<optional>

See canvas.getContext contextAttributes.

Returns:
Type: 
WebGLContextExt | null

(static) getExtension(gl, name) → {any}

The return value is null if the extension is not supported, or an extension object otherwise.

Parameters:
NameTypeDescription
glWebGLRenderingContext | WebGL2RenderingContext | null

WebGl context pointer.

namestring

Extension name.

Returns:
Type: 
any