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
- 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
Type:
- HTMLCanvasElement
- Source:
# (static) glContext :WebGLRenderingContext
2d context for glCanvas
Type:
- WebGLRenderingContext
- Source:
# (static) glTileTexture :WebGLTexture
Main tile sheet texture automatically loaded by engine
Type:
- WebGLTexture
- 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 |
- 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> |
0 |
- Source:
# (static) glCreateBuffer(bufferType, size, usage) → {WebGLBuffer}
Create WebGL buffer
Parameters:
Name | Type | Description |
---|---|---|
bufferType |
||
size |
||
usage |
- Source:
Returns:
- Type
- WebGLBuffer
# (static) glCreateProgram(vsSource, fsSource) → {WebGLProgram}
Create WebGL program with given shaders
Parameters:
Name | Type | Description |
---|---|---|
vsSource |
WebGLShader | |
fsSource |
WebGLShader |
- Source:
Returns:
- Type
- WebGLProgram
# (static) glCreateTexture(image) → {WebGLTexture}
Create WebGL texture from an image and set the texture settings
Parameters:
Name | Type | Description |
---|---|---|
image |
Image |
- Source:
Returns:
- Type
- WebGLTexture
# (static) glDraw(x, y, sizeX, sizeY, angle, uv0X, uv0Y, uv1X, uv1Y, rgbaopt, rgbaAdditiveopt)
Add a sprite to the gl draw list, used by all gl draw functions
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x |
||||
y |
||||
sizeX |
||||
sizeY |
||||
angle |
||||
uv0X |
||||
uv0Y |
||||
uv1X |
||||
uv1Y |
||||
rgba |
<optional> |
0xffffffff | ||
rgbaAdditive |
<optional> |
0 |
- Source:
# (static) glFlush()
Draw all sprites and clear out the buffer, called automatically by the system whenever necessary
- Source:
# (static) glSetBlendMode(additiveopt)
Set the WebGl blend mode, normally you should call setBlendMode instead
Parameters:
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
- This may also flush the gl buffer resulting in more draw calls and worse performance
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
texture |
WebGLTexture |
<optional> |
glTileTexture |
- Source: