GLShader

class GLShader

a base GL Shader object

Constructor


new GLShader(gl: WebGLRenderingContext, vertex: string, fragment: string, precision: string) → {}
// create a basic shader
let 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();
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: https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders

Summary


Properties from GLShader

Array<GLint>
attributes
string
fragment
WebGLRenderingContext
gl
WebGLProgram
program
object
uniforms
string
vertex

Methods from GLShader

bind()

Installs this shader program as part of current rendering state

destroy()

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

GLint
getAttribLocation(name: string)
setUniform(name: string, value: object | Float32Array)
setVertexAttributes(gl: WebGLRenderingContext, attributes: Array<object>, vertexByteSize: number)

Public Properties


attributes glshader.js:60
attributes: Array<GLint>

Array<GLint>

the location attributes of the shader

fragment glshader.js:54
fragment: string

string

the fragment shader source code

gl glshader.js:42
gl: WebGLRenderingContext

WebGLRenderingContext

the active gl rendering context

program glshader.js:67
program: WebGLProgram

WebGLProgram

a reference to the shader program (once compiled)

uniforms glshader.js:73
uniforms: object

object

the uniforms of the shader

vertex glshader.js:48
vertex: string

string

the vertex shader source code

Public Methods


bind glshader.js:83
bind() → {}

Installs this shader program as part of current rendering state

destroy glshader.js:145
destroy() → {}

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

getAttribLocation glshader.js:90
getAttribLocation(name: string) → {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:
Type Description
GLint

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

setUniform glshader.js:104
setUniform(name: string, value: object | Float32Array) → {}

Set the uniform to the given value

myShader.setUniform("uProjectionMatrix", this.projectionMatrix);
Parameters:
Name Type Description
name string

the uniform name

value object | Float32Array

the value to assign to that uniform

setVertexAttributes glshader.js:124
setVertexAttributes(gl: WebGLRenderingContext, attributes: Array<object>, vertexByteSize: number) → {}

activate the given vertex attribute for this shader

Parameters:
Name Type Description
gl WebGLRenderingContext

the current WebGL rendering context

attributes Array<object>

an array of vertex attributes

vertexByteSize number

the size of a single vertex in bytes


Powered by webdoc!