Constructor
new Program(gl, vertopt, fragopt, defsopt)
Program constructor. Create gl program and shaders. You can pass optional shader code to immediatly compile shaders
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
gl |
WebGLRenderingContext | webgl context this program belongs to | |
vert |
String |
<optional> |
an optional vertex shader code. See Program#compile |
frag |
String |
<optional> |
an optional fragment shader code See Program#compile |
defs |
String |
<optional> |
an optional string prepend to both fragment and vertex shader code. See Program#compile. |
- Source:
- See:
Examples
For the given vertex shader
attribute vec3 aPosition;
uniform mat4 uMVP;
uniform vec3 uCameraPosition;
access to uniforms and attributes
var prg = new Program( gl, vert, frag );
prg.use()
var mvp = glmatrix.mat4.create()
prg.uMVP( mvp )
prg.uCameraPosition( 0, 0, 0 )
// or
var campos = glmatrix.vec3.create()
prg.uCameraPosition( campos )
// or
prg.uCameraPosition( [0, 1, 2] )
// get the uniform location
var matLocation = prg.uMVP()
// or attribute location
var aPosition = prg.aPosition()
Members
(static) verbose
Program.verbose
can be set to false to prevent shader code logs on glsl errors (default to true)
- Source:
bind
alias to Program.use()
- Source:
Methods
compile(vert, frag, prefixopt)
Compile vertex and fragment shader then link gl program
This method can be safely called several times.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
vert |
String | vertex shader code | ||
frag |
String | fragment shader code | ||
prefix |
String |
<optional> |
'' | an optional string append to both fragment and vertex code |
- Source:
dispose()
Delete program and shaders
- Source:
use()
Shortcut for gl.useProgram()
alias program.bind()
- Source: