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();
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'). |
Summary
Properties from GLShader
Methods from GLShader
Installs this shader program as part of current rendering state |
|
destroy this shader objects resources (program, attributes, uniforms) |
|
GLint |
|
|
|
|
Public Properties
attributes: Array<GLint>
Array<GLint>
the location attributes of the shader
program: WebGLProgram
WebGLProgram
a reference to the shader program (once compiled)
Public Methods
destroy() → {}
destroy this shader objects resources (program, attributes, uniforms)
getAttribLocation(name: string) → {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. |
Type | Description |
---|---|
GLint |
number indicating the location of the variable name if found. Returns -1 otherwise |
setUniform(name: string, value: object | Float32Array) → {}
Set the uniform to the given value
myShader.setUniform("uProjectionMatrix", this.projectionMatrix);
Name | Type | Description |
---|---|---|
name | string |
the uniform name |
value | object | Float32Array |
the value to assign to that uniform |
setVertexAttributes(gl: WebGLRenderingContext, attributes: Array<object>, vertexByteSize: number) → {}
activate the given vertex attribute for this shader
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 |