Class: Handler

og/webgl/Handler~Handler

A WebGL handler for accessing low-level WebGL capabilities.

new Handler(id, params)

Name Type Description
id string Canvas element id that WebGL handler assing with. If it's null or undefined creates hidden canvas and handler bacomes hidden.
params Object optional Handler options:
Name Type Description
anisotropy number optional Anisotropy filter degree. 8 is default.
width number optional Hidden handler width. 256 is default.
height number optional Hidden handler height. 256 is default.
extensions Array.<string> optional Additional WebGL extension list. Available by default: EXT_texture_filter_anisotropic.

Members

protected_clocks

Custom timers.

activeProgramProgramController

Current active shader program controller.

canvasObject

WebGL rendering canvas element.

defaultClockClock

Application default timer.

readonlydeltaTimenumber

Draw frame time in milliseconds.

extensionsObject

Current WebGL extensions. Becomes here after context initialization.

glObject

WebGL context.

programsObject.<og.webgl.ProgramController>

Shader program controller list.

Methods

staticmodule:og/webgl/Handler~Handler.getContext(canvas, contextAttributes){Object}

Returns a drawing context on the canvas, or null if the context identifier is not supported.
Name Type Description
canvas Object HTML canvas object.
contextAttributes Object optional See canvas.getContext contextAttributes.
Returns:
Type Description
Object -

staticmodule:og/webgl/Handler~Handler.getExtension(gl, name){Object}

The return value is null if the extension is not supported, or an extension object otherwise.
Name Type Description
gl Object WebGl context pointer.
name String Extension name.
Returns:
Type Description
Object -

activateBlending()

Activate blending.

activateDepthTest()

Activate depth test.

activateFaceCulling()

Activate face culling.

addProgram(program, notActivate){Program}

Adds shader program to the handler.
Name Type Description
program Program Shader program.
notActivate boolean optional If it's true program will not compile.
Returns:
Type Description
Program -

addPrograms(programsArr)

Adds shader programs to the handler.
Name Type Description
programsArr Array.<Program> Shader program array.
Clearing gl frame.

createArrayBuffer(array, itemSize, numItems, usage){Object}

Creates ARRAY buffer.
Name Type Default Description
array Array.<number> Input array.
itemSize number Array item size.
numItems number Items quantity.
usage number STATIC_DRAW optional Parameter of the bufferData call can be one of STATIC_DRAW, DYNAMIC_DRAW, or STREAM_DRAW.
Returns:
Type Description
Object -

createArrayBufferLength(array, itemSize, numItems, usage){Object}

Creates ARRAY buffer specific length.
Name Type Default Description
array Array.<number> Input array.
itemSize number Array item size.
numItems number Items quantity.
usage number STATIC_DRAW optional Parameter of the bufferData call can be one of STATIC_DRAW, DYNAMIC_DRAW, or STREAM_DRAW.
Returns:
Type Description
Object -

createDefaultTexture(params, success)

Creates default texture object
Name Type Description
params Object optional Texture parameters:
success callback optional Creation callback

createElementArrayBuffer(array, itemSize, numItems, usage){Object}

Creates ELEMENT ARRAY buffer.
Name Type Default Description
array Array.<number> Input array.
itemSize number Array item size.
numItems number Items quantity.
usage number STATIC_DRAW optional Parameter of the bufferData call can be one of STATIC_DRAW, DYNAMIC_DRAW, or STREAM_DRAW.
Returns:
Type Description
Object -

createEmptyTexture2DExt(width, height, filter, internalFormat, format, type, levels){Object}

Creates empty texture.
Name Type Default Description
width Number 1 optional Specifies the width of the texture image..
height Number 1 optional Specifies the width of the texture image..
filter String "NEAREST" optional Specifies GL_TEXTURE_MIN(MAX)_FILTER texture value.
internalFormat String "RGBA" optional Specifies the color components in the texture.
format String "RGBA" optional Specifies the format of the texel data.
type String "UNSIGNED_BYTE" optional Specifies the data type of the texel data.
levels Number 0 optional Specifies the level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.
Returns:
Type Description
Object - WebGL texture object.

createEmptyTexture_l(width, height){Object}

Creates empty LINEAR filtered texture.
Name Type Description
width number Empty texture width.
height number Empty texture height.
Returns:
Type Description
Object - WebGL texture object.

createEmptyTexture_n(width, height){Object}

Creates Empty NEAREST filtered texture.
Name Type Description
width number Empty texture width.
height number Empty texture height.
Returns:
Type Description
Object - WebGL texture object.

createStreamArrayBuffer(array, itemSize, numItems, usage){Object}

Creates STREAM_DRAW ARRAY buffer.
Name Type Default Description
array Array.<number> Input array.
itemSize number Array item size.
numItems number Items quantity.
usage number STATIC_DRAW optional Parameter of the bufferData call can be one of STATIC_DRAW, DYNAMIC_DRAW, or STREAM_DRAW.
Returns:
Type Description
Object -

createTexture_a_webgl1(image){Object}

Creates ANISOTROPY filter texture.
Name Type Description
image Object Image or Canvas object.
Returns:
Type Description
Object - WebGL texture object.

createTexture_a_webgl2(image){Object}

Creates ANISOTROPY filter texture.
Name Type Description
image Object Image or Canvas object.
Returns:
Type Description
Object - WebGL texture object.

createTexture_l_webgl1(image){Object}

Creates LINEAR filter texture.
Name Type Description
image Object Image or Canvas object.
Returns:
Type Description
Object - WebGL texture object.

createTexture_l_webgl2(image){Object}

Creates LINEAR filter texture.
Name Type Description
image Object Image or Canvas object.
Returns:
Type Description
Object - WebGL texture object.

createTexture_mm_webgl1(image){Object}

Creates MIPMAP filter texture.
Name Type Description
image Object Image or Canvas object.
Returns:
Type Description
Object - WebGL texture object.

createTexture_mm_webgl2(image){Object}

Creates MIPMAP filter texture.
Name Type Description
image Object Image or Canvas object.
Returns:
Type Description
Object - WebGL texture object.

createTexture_n_webgl1(image){Object}

Creates NEAREST filter texture.
Name Type Description
image Object Image or Canvas object.
Returns:
Type Description
Object - WebGL texture object.

createTexture_n_webgl2(image){Object}

Creates NEAREST filter texture.
Name Type Description
image Object Image or Canvas object.
Returns:
Type Description
Object - WebGL texture object.

deactivateBlending()

Deactivate blending.

deactivateDepthTest()

Deactivate depth test.

deactivateFaceCulling()

Deactivate face cullting.

drawFrame(now)

Draw single frame.
Name Type Description
now number Frame current time milliseconds.

getCenter(){number}

Returns screen center coordinates.
Returns:
Type Description
number -

getClientAspect(){number}

Returns canvas aspect ratio.
Returns:
Type Description
number -

getHeight(){number}

Returns context screen height.
Returns:
Type Description
number -

getWidth(){number}

Returns context screen width.
Returns:
Type Description
number -
Main function that initialize handler.

initializeExtension(extensionStr, showLog){Object}

Initialize additional WebGL extensions.
Name Type Description
extensionStr string Extension name.
showLog boolean Show logging.
Returns:
Type Description
Object -

loadCubeMapTexture(params){Object}

Creates cube texture.
Name Type Description
params Object.<string> Face image urls:
Name Type Description
px string Positive X or right image url.
nx string Negative X or left image url.
py string Positive Y or up image url.
ny string Negative Y or bottom image url.
pz string Positive Z or face image url.
nz string Negative Z or back image url.
Returns:
Type Description
Object - WebGL texture object.

removeProgram(name)

Removes shader program from handler.
Name Type Description
name String Shader program name.

setFrameCallback(callback)

Sets animation frame function.
Name Type Description
callback callback Frame callback.

setSize(w, h)

Sets handler canvas size.
Name Type Description
w number Canvas width.
h number Canvas height.

setStreamArrayBuffer(array, itemSize, numItems, usage){Object}

Load stream ARRAY buffer.
Name Type Default Description
array Array.<number> Input array.
itemSize number Array item size.
numItems number Items quantity.
usage number STATIC_DRAW optional Parameter of the bufferData call can be one of STATIC_DRAW, DYNAMIC_DRAW, or STREAM_DRAW.
Returns:
Type Description
Object -
Starts animation loop.