index.js
function update (opt) {
    // remove old shaders
    disposeShaders()

    var quiet = opt.quiet
    var attributeBindings = opt.attributes

    var vertSrc = opt.vertex || defaultVertex
    var fragSrc = opt.fragment || defaultFragment

    // re-compile source
    vertexShader = compileShader(gl, gl.VERTEX_SHADER, vertSrc, quiet, name)
    fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragSrc, quiet, name)

    // re-link
    var shaders = [ vertexShader, fragmentShader ]
    linkShaders(gl, program, shaders, attributeBindings, quiet, name)

    // extract uniforms and attributes
    types = extract(gl, program)

    // allow user to inject some dummy uniforms
    if (opt.uniforms) {
      var inactiveUniforms = []
      opt.uniforms.forEach(function (uniform) {
        if (indexOfName(types.uniforms, uniform.name) === -1) {
          inactiveUniforms.push(uniform)
          types.uniforms.push({ name: uniform.name, type: uniform.type })
        }
      })

      // provide UX for inactive uniforms...? TBD
      if (!quiet && inactiveUniforms.length > 0) {
        var shaderName = name ? (' (' + name + ')') : ''
        console.warn('Inactive uniforms in shader' + shaderName + ': '
          + inactiveUniforms
            .map(function (x) { return x.name })
            .join(', '))
      }
    }

    // normalize sort order by name across Chrome / FF
    types.uniforms.sort(compareString)
    types.attributes.sort(compareString)

    // provide optimized getters/setters
    uniforms = reflect(types.uniforms, function (uniform, index) {
      return makeUniformProp(uniform, index)
    })

    // provide attribute locations and type
    // (GLSL ES does not support array/struct attributes)
    attributes = types.attributes.reduce(function (struct, attrib) {
      var name = attrib.name
      struct[name] = {
        size: dimension(attrib.type),
        type: attrib.type,
        location: gl.getAttribLocation(program, name)
      }
      return struct
    }, {})
  }
function update (opt) {
    // remove old shaders
    disposeShaders()

    var quiet = opt.quiet
    var attributeBindings = opt.attributes

    var vertSrc = opt.vertex || defaultVertex
    var fragSrc = opt.fragment || defaultFragment

    // re-compile source
    vertexShader = compileShader(gl, gl.VERTEX_SHADER, vertSrc, quiet, name)
    fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragSrc, quiet, name)

    // re-link
    var shaders = [ vertexShader, fragmentShader ]
    linkShaders(gl, program, shaders, attributeBindings, quiet, name)

    // extract uniforms and attributes
    types = extract(gl, program)

    // allow user to inject some dummy uniforms
    if (opt.uniforms) {
      var inactiveUniforms = []
      opt.uniforms.forEach(function (uniform) {
        if (indexOfName(types.uniforms, uniform.name) === -1) {
          inactiveUniforms.push(uniform)
          types.uniforms.push({ name: uniform.name, type: uniform.type })
        }
      })

      // provide UX for inactive uniforms...? TBD
      if (!quiet && inactiveUniforms.length > 0) {
        var shaderName = name ? (' (' + name + ')') : ''
        console.warn('Inactive uniforms in shader' + shaderName + ': '
          + inactiveUniforms
            .map(function (x) { return x.name })
            .join(', '))
      }
    }

    // normalize sort order by name across Chrome / FF
    types.uniforms.sort(compareString)
    types.attributes.sort(compareString)

    // provide optimized getters/setters
    uniforms = reflect(types.uniforms, function (uniform, index) {
      return makeUniformProp(uniform, index)
    })

    // provide attribute locations and type
    // (GLSL ES does not support array/struct attributes)
    attributes = types.attributes.reduce(function (struct, attrib) {
      var name = attrib.name
      struct[name] = {
        size: dimension(attrib.type),
        type: attrib.type,
        location: gl.getAttribLocation(program, name)
      }
      return struct
    }, {})
  }
function update ( opt ) { // remove old shaders disposeShaders ( ) var quiet = opt . quiet var attributeBindings = opt . attributes var vertSrc = opt . vertex || defaultVertex var fragSrc = opt . fragment || defaultFragment // re-compile source vertexShader = compileShader ( gl , gl . VERTEX_SHADER , vertSrc , quiet , name ) fragmentShader = compileShader ( gl , gl . FRAGMENT_SHADER , fragSrc , quiet , name ) // re-link var shaders = [ vertexShader , fragmentShader ] linkShaders ( gl , program , shaders , attributeBindings , quiet , name ) // extract uniforms and attributes types = extract ( gl , program ) // allow user to inject some dummy uniforms if ( opt . uniforms ) { var inactiveUniforms = [ ] opt . uniforms . forEach ( function ( uniform ) { if ( indexOfName ( types . uniforms , uniform . name ) === - 1 ) { inactiveUniforms . push ( uniform ) types . uniforms . push ( { name : uniform . name , type : uniform . type } ) } } ) // provide UX for inactive uniforms...? TBD if ( ! quiet && inactiveUniforms . length > 0 ) { var shaderName = name ? ( ' (' + name + ')' ) : '' console . warn ( 'Inactive uniforms in shader' + shaderName + ': ' + inactiveUniforms . map ( function ( x ) { return x . name } ) . join ( ', ' ) ) } } // normalize sort order by name across Chrome / FF types . uniforms . sort ( compareString ) types . attributes . sort ( compareString ) // provide optimized getters/setters uniforms = reflect ( types . uniforms , function ( uniform , index ) { return makeUniformProp ( uniform , index ) } ) // provide attribute locations and type // (GLSL ES does not support array/struct attributes) attributes = types . attributes . reduce ( function ( struct , attrib ) { var name = attrib . name struct [ name ] = { size : dimension ( attrib . type ) , type : attrib . type , location : gl . getAttribLocation ( program , name ) } return struct } , { } ) }
reload shader with new source code
reload shader with new source code