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

a base GL Shader object

new GLShader(gl, vertex, fragment, precisionopt)

Parameters:
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').

See:
Example
// create a basic shader
var myShader = new me.GLShader(
   // WebGL rendering context
   gl,
   // vertex shader
   [
       "void main() {",
       "    gl_Position = doMathToMakeClipspaceCoordinates;",
       "}"
   ].join("\n"),
   // fragment shader
   [
       "void main() {",
       "    gl_FragColor = doMathToMakeAColor;",
       "}"
   ].join("\n")
 )
// use the shader
myShader.bind();

Members

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

Methods

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

Parameters:
Name Type Description
name String

the name of the attribute variable whose location to get.

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

Parameters:
Name Type Description
name String

the uniform name

value Object | Float32Array

the value to assign to that uniform

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