Constructor
new L3D.GLContext(options)
options |
Object | supported options: Properties
|
Properties
currently bound shader.
Stores common used extensions so they can be checked if they are supported.
The canvas height, in pixels.
Unique ID for this GLContext.
Emitted when the context is destroyed so objects can free their resources.
Emitted so objects can draw into the current frame.
Emitted when the context has been lost so objects can free their resources and prepare for a new context being created.
Emitted before rendering so listeners can do any updating for the next frame.
Manages a cache of GL objects.
The GLState object managing pushing and popping of state values.
The current viewport dimensions
True if this context is WebGL 2.
The version of WebGL used by this context, either 2 or 1.
The canvas width, in pixels.
Methods
static cloneCanvas(canvas) → Canvas
Clone a canvas element.
canvas |
Canvas | The canvas to clone. |
- Canvas
The created canvas.
static createCanvas(width, height) → Canvas
Create a canvas element.
width |
number | The width of the created canvas. |
height |
number | The height of the created canvas. |
- Canvas
The created canvas.
animate()
Launch animation loop (calls gl.onUpdate and gl.onDrawFrame every frame) example: gl.onDrawFrame.addListener(function(){ ... }) or gl.onUpdate.addListener(function(dt) { ... })
destroy()
Destroy this WebGL context and removes the Canvas from the DOM.
drawFrame()
Request all objects listening to onDrawFrame to draw.
exitPointerLock()
Release the pointer lock from the canvas.
fullscreen()
Launches the canvas in fullscreen mode
getAspectRatio() → number
Get the aspect ratio of the canvas.
- number
The aspect ratio, width / height.
getUniformFunction(data) → function
Get the setter function to use for a uniform given a WebGLActiveInfo.
data |
WebGLActiveInfo | Info about the active uniform. |
- function
The uniform setter function, bound to the GL context, such as uniform1f.
getViewport(v)
Get the dimensions of the viewport
v |
Array.<number> | Optional storage for the results. |
requestFrame()
Request a frame to be drawn. This is done asynchrounously, and multiple calls to requestFrame called before the frame is drawn will be consolidated.
requestPointerLock()
Request pointer lock for the canvas. This needs to be done from a user event, such as mousedown or touchdown.
reset()
Reset the the initial gl state
setViewport(v, flipY)
Set the dimensions of the viewport.
v |
array.<number> | Dimensions of the viewport |
flipY |
bool | If true, flip the y coordinate of the viewport so the origin is the bottom-left corner of the viewport. |
snapshot(startx, starty, areax, areay, skipReverse) → Canvas
Returns a canvas with a snapshot of an area. This is safer than using the canvas itself due to internals of WebGL.
startx |
number | Viewport x coordinate |
starty |
number | Viewport y coordinate, from bottom of the canvas. |
areax |
number | Viewport area width. |
areay |
number | Viewport area height. |
skipReverse |
bool | If false, the canvas image will be flipped vertically. |
- Canvas
canvas
updateResolution()
Call this when the size of the canvas has changed to update the resolution of the canvas to match.
viewport(a, b, c, d)
Set the dimensions of the viewport.
a |
number | |
b |
number | |
c |
number | |
d |
number |