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
- Supports shadertoy style post processing shaders
- Source
Members
(static) glAntialias :Boolean
Shoule webgl be setup with antialiasing, must be set before calling engineInit
Type:
- Boolean
- Source
(static) glCanvas :HTMLCanvasElement
The WebGL canvas which appears above the main canvas and below the overlay canvas
Type:
- HTMLCanvasElement
- Source
(static) glContext :WebGL2RenderingContext
2d context for glCanvas
Type:
- WebGL2RenderingContext
- Source
Methods
(static) glCompileShader(source, type) → {WebGLShader}
Compile WebGL shader of the given type, will throw errors if in debug mode
Parameters:
Name | Type | Description |
---|---|---|
source | String | |
type | Number |
- Source
Returns:
- Type:
- WebGLShader
(static) glCopyToContext(context, forceDrawopt)
Draw any sprites still in the buffer, copy to main canvas and clear
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
context | CanvasRenderingContext2D | | |||
forceDraw | Boolean | <optional> | false |
- Source
(static) glCreateProgram(vsSource, fsSource) → {WebGLProgram}
Create WebGL program with given shaders
Parameters:
Name | Type | Description |
---|---|---|
vsSource | String | |
fsSource | String |
- Source
Returns:
- Type:
- WebGLProgram
(static) glCreateTexture(image) → {WebGLTexture}
Create WebGL texture from an image and init the texture settings
Parameters:
Name | Type | Description |
---|---|---|
image | HTMLImageElement |
- Source
Returns:
- 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
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x | Number | |||
y | Number | |||
sizeX | Number | |||
sizeY | Number | |||
angle | Number | |||
uv0X | Number | |||
uv0Y | Number | |||
uv1X | Number | |||
uv1Y | Number | |||
rgba | Number | |||
rgbaAdditive | Number | <optional> | 0 |
- Source
(static) glFlush()
Draw all sprites and clear out the buffer, called automatically by the system whenever necessary
- Source
(static) glSetAntialias(antialiasopt)
Set antialiasing for webgl canvas
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
antialias | Boolean | <optional> | true |
- Source
(static) glSetTexture(texture)
Set the WebGl texture, called automatically if using multiple textures
- This may also flush the gl buffer resulting in more draw calls and worse performance
Parameters:
Name | Type | Description |
---|---|---|
texture | WebGLTexture |
- Source