WebGL

WebGL

LittleJS WebGL Interface
- All webgl used by the engine is wrapped up here
- 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
- For normal stuff you won't need to call any functions in this file
- For advanced stuff there are helper functions to create shaders, textures, etc

Members

# (static) glCanvas :HTMLCanvasElement

The WebGL canvas which appears above the main canvas and below the overlay canvas
Type:
  • HTMLCanvasElement

# (static) glContext :WebGLRenderingContext

2d context for glCanvas
Type:
  • WebGLRenderingContext

# (static) glTileTexture :WebGLTexture

Main tile sheet texture automatically loaded by engine
Type:
  • WebGLTexture

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
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

# (static) glCreateBuffer(bufferType, size, usage) → {WebGLBuffer}

Create WebGL buffer
Parameters:
Name Type Description
bufferType
size
usage
Returns:
Type
WebGLBuffer

# (static) glCreateProgram(vsSource, fsSource) → {WebGLProgram}

Create WebGL program with given shaders
Parameters:
Name Type Description
vsSource WebGLShader
fsSource WebGLShader
Returns:
Type
WebGLProgram

# (static) glCreateTexture(image) → {WebGLTexture}

Create WebGL texture from an image and set the texture settings
Parameters:
Name Type Description
image Image
Returns:
Type
WebGLTexture

# (static) glDraw(x, y, sizeX, sizeY, angleopt, uv0Xopt, uv0Yopt, uv1Xopt, uv1Yopt, 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 <optional>
0
uv0X <optional>
0
uv0Y <optional>
0
uv1X <optional>
1
uv1Y <optional>
1
rgba <optional>
0xffffffff
rgbaAdditive <optional>
0

# (static) glFlush()

Draw all sprites and clear out the buffer, called automatically by the system whenever necessary

# (static) glSetBlendMode(additiveopt)

Set the WebGl blend mode, normally you should call setBlendMode instead
Parameters:
Name Type Attributes Default Description
additive Boolean <optional>
0

# (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
Parameters:
Name Type Attributes Default Description
texture WebGLTexture <optional>
glTileTexture