LittleJS WebGL Interface
- All webgl used by the engine is wrapped up here
- For normal stuff you won't need to see or call anything in this file
- For advanced stuff there are helper functions to create shaders, textures, etc
- Can be disabled with glEnable to revert to 2D canvas rendering
- Batches sprite rendering on GPU for incredibly fast performance
- Sprite transform math is done in the shader where possible
- Source
Members
(static) glCanvas :HTMLCanvasElement
The WebGL canvas which appears above the main canvas and below the overlay canvas
- HTMLCanvasElement
- Source
(static) glContext :WebGLRenderingContext
2d context for glCanvas
- WebGLRenderingContext
- Source
(static) glTileTexture :WebGLTexture
Main tile sheet texture automatically loaded by engine
- WebGLTexture
- Source
Methods
(static) glCompileShader(source, type) → {WebGLShader}
Compile WebGL shader of the given type, will throw errors if in debug mode
Name | Type | Description |
---|---|---|
source | String | |
type |
- Source
- Type:
- WebGLShader
(static) glCopyToContext(context, forceDrawopt)
Draw any sprites still in the buffer, copy to main canvas and clear
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
context | CanvasRenderingContext2D | |||
forceDraw | Boolean | <optional> | 0 |
- Source
(static) glCreateProgram(vsSource, fsSource) → {WebGLProgram}
Create WebGL program with given shaders
Name | Type | Description |
---|---|---|
vsSource | WebGLShader | |
fsSource | WebGLShader |
- Source
- Type:
- WebGLProgram
(static) glCreateTexture(image) → {WebGLTexture}
Create WebGL texture from an image and set the texture settings
Name | Type | Description |
---|---|---|
image | Image |
- Source
- Type:
- WebGLTexture
(static) glDraw(x, y, sizeX, sizeY, angle, uv0X, uv0Y, uv1X, uv1Y, rgba, rgbaAdditiveopt)
Add a sprite to the gl draw list, used by all gl draw functions
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x | ||||
y | ||||
sizeX | ||||
sizeY | ||||
angle | ||||
uv0X | ||||
uv0Y | ||||
uv1X | ||||
uv1Y | ||||
rgba | ||||
rgbaAdditive | <optional> | 0 |
- Source
(static) glFlush()
Draw all sprites and clear out the buffer, called automatically by the system whenever necessary
- Source
(static) glInitPostProcess(shaderCode, includeOverlay)
Set up a post processing shader
Name | Type | Description |
---|---|---|
shaderCode | String | |
includeOverlay | Boolean |
- Source
(static) glSetBlendMode(additiveopt)
Set the WebGl blend mode, normally you should call setBlendMode instead
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
additive | Boolean | <optional> | 0 |
- Source
(static) glSetTexture(textureopt)
Set the WebGl texture, not normally necessary unless multiple tile sheets are used
- This may also flush the gl buffer resulting in more draw calls and worse performance
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
texture | WebGLTexture | <optional> | glTileTexture |
- Source