WebGLContext Class
A thin wrapper around WebGLRenderingContext which handles context loss and restore with various rendering objects (textures, shaders and buffers). This also handles general viewport management.
If the view is not specified, a canvas will be created.
If the view
parameter is an instanceof WebGLRenderingContext,
we will use its canvas and context without fetching another through getContext
.
Passing a canvas that has already had getContext('webgl')
called will not cause
errors, but in certain debuggers (e.g. Chrome WebGL Inspector) only the latest
context will be traced.
Constructor
WebGLContext
-
width
-
height
-
view
-
contextAttribuets
Parameters:
-
width
Numberthe width of the GL canvas
-
height
Numberthe height of the GL canvas
-
view
HTMLCanvasElementthe optional DOM canvas element
-
contextAttribuets
Objectan object containing context attribs which will be used during GL initialization
Item Index
Properties
Properties
contextAttributes
Object
The context attributes for initializing the GL state. This might include anti-aliasing, alpha settings, verison, and so forth.
gl
WebGLRenderingContext
The actual GL context. You can use this for
raw GL calls or to access GLenum constants. This
will be updated on context restore. While the WebGLContext
is not valid
, you should not try to access GL state.
height
Number
The height of this canvas.
managedObjects
Array
The list of rendering objects (shaders, VBOs, textures, etc) which are currently being managed. Any object with a "create" method can be added to this list. Upon destroying the rendering object, it should be removed. See addManagedObject and removeManagedObject.
valid
Boolean
Whether this context is 'valid', i.e. renderable. A context that has been lost (and not yet restored) or destroyed is invalid.
view
Number
The canvas DOM element for this context.
width
Number
The width of this canvas.
Events
lost
Signal
A signal dispatched when GL context is lost.
The first argument passed to the listener is the WebGLContext managing the context loss.
restored
Signal
A signal dispatched when GL context is restored, after all the managed objects have been recreated.
The first argument passed to the listener is the WebGLContext which managed the restoration.
This does not gaurentee that all objects will be renderable. For example, a Texture with an ImageProvider may still be loading asynchronously.