me.GLShader(gl, vertex, fragment, precisionopt)

a base GL Shader object

new GLShader(gl, vertex, fragment, precisionopt)

Name Type Attributes Default Description
gl WebGLRenderingContext

the current WebGL rendering context

vertex String

a string containing the GLSL source code to set

fragment String

a string containing the GLSL source code to set

precision String <optional>
auto detected

float precision ('lowp', 'mediump' or 'highp').

// create a basic shader
var myShader = new me.GLShader(
   // WebGL rendering context
   // vertex shader
       "void main() {",
       "    gl_Position = doMathToMakeClipspaceCoordinates;",
   // fragment shader
       "void main() {",
       "    gl_FragColor = doMathToMakeAColor;",
// use the shader


static attributes :Array.<GLint>

the location attributes of the shader

static gl :WebGLRenderingContext

the active gl rendering context

static program :WebGLProgram

a reference to the shader program (once compiled)

static uniforms :Object

the uniforms of the shader

static vertex :String

the vertex shader source code

static vertex :String

the fragment shader source code


static bind()

Installs this shader program as part of current rendering state

static destroy()

destroy this shader objects resources (program, attributes, uniforms)

static getAttribLocation(name) → {GLint}

returns the location of an attribute variable in this shader program

Name Type Description
name String

the name of the attribute variable whose location to get.

GLint -

number indicating the location of the variable name if found. Returns -1 otherwise

static setUniform(name, value)

Set the uniform to the given value

Name Type Description
name String

the uniform name

value Object | Float32Array

the value to assign to that uniform

myShader.setUniform("uProjectionMatrix", this.projectionMatrix);