GLShader

A GLShader is a WebGL program with a bound vertex and fragment shader.

Constructor

new L3D.GLShader()

Properties

static precision String

The default precision to use for shaders that don't explicitely define it.

isBound bool

Is the shader currently the active bound shader?

Methods

static injectCode(injectCode, code) → String

Injects macro code into the shader, but only after the #version line, which must be first.

Parameters
injectCode String

The code to inject.

code String

The code to inject into.

Returns
String

The resulting code.

attributeLocation(name) → number

Get the location of an attribute with the given name.

Parameters
name String

The name of the attribute.

Returns
number

An int number indicating the location of the attribute name if found. Returns -1 if the attribute wasn't found.

bind()

Bind the shader as active for the context.

drawBuffers(vertexBuffers, indexBuffer, mode, rangeStart, rangeLength)GLShader

Draw the geometry defined by the given buffers using this shader.

Parameters
vertexBuffers Object

The vertex buffers to draw.

indexBuffer GLBuffer

Optional index buffer to draw with

mode number

The GL element mode to draw with

rangeStart number
rangeLength number
Returns
GLShader

Returns self.

drawMesh(mesh, mode, indexBufferName)GLShader

Renders a mesh using this shader.

Parameters
mesh GLMesh

The mesh to draw

mode number

The GL draw mode, could be gl.LINES, gl.POINTS, gl.TRIANGLES, gl.TRIANGLE_STRIP, gl.TRIANGLE_FAN

indexBufferName String

The name of the index buffer, if not provided "lines" will be assumed if mode is gl.LINES, otherwise "triangles".

Returns
GLShader

Returns self.

drawRange(mesh, mode, start, length, indexBufferName)GLShader

Draw a given sub-range from the given mesh.

Parameters
mesh GLMesh

The mesh to draw.

mode number
start number
length number
indexBufferName String
Returns
GLShader

Returns self.

setUniform(name, value)GLShader

Set a uniform value given it's name.

The uniform locations will already have been cached when the shader was loaded. Attempting to set a uniform value that doesn't exist in the shader will return without doing anything.

Parameters
name String

The name of the uniform.

value *

The value to set it as.

Returns
GLShader

Returns self.

setUniforms(uniformValues)GLShader

Set multiple uniform values.

setUniforms({ color: [1,1,1,1] });
setUniforms([{ color: [1,1,1,1] }, { worldToCamera: new Matrix4() }]);
Parameters
uniformValues *

Can be a map, or an array of maps.

Returns
GLShader

Returns self.

unbind()

Unbind the shader from the context.

uniformLocation(name) → WebGLUniformLocation

Get the location of a uniform with the given name.

Parameters
name String

The name of the uniform.

Returns
WebGLUniformLocation

The location of the uniform.