src/asset-manager.js
/**
   * Returns a promise that resolves to a bound program.
   * @param  {String} name Program internal name (raw or loaded)
   * @return {Promise}     Resolves to the bound program.
   */
Returns a promise that resolves to a bound program.
@param  {String} name Program internal name (raw or loaded)
@return {Promise}     Resolves to the bound program.
Returns a promise that resolves to a bound program . @param { String } name Program internal name ( raw or loaded ) @return { Promise } Resolves to the bound program .
loadProgram(name) {
    if (!(name in this.manifest.program) && !(name in this.manifest.rawProgram)) {
      return Promise.reject(new Error('Unknown program ' + name));
    } else if (this.programs[name]) {
      this._recordUsage('program', name);
      return Promise.resolve(this.programs[name]);
    } else {
      if (name in this.manifest.rawProgram) {
        let asset = this.manifest.rawProgram[name];
        return new Promise((resolve) => {
          if (!this.programs[name]) {
            let Klass = _programs[asset.program] || Program;
            this.programs[name] = new Klass(this._gl, asset.vertex, asset.fragment);
          }
          this._recordUsage('program', name);
          resolve(this.programs[name]);
        });
      } else {
        let asset = this.manifest.program[name];
        return Promise.all([
            this.loader.loadAsset(this._getFullPath(asset.static, asset.vertex), 'text'),
            this.loader.loadAsset(this._getFullPath(asset.static, asset.fragment), 'text')
          ]).then((program) => {
            if (!this.programs[name]) {
              let Klass = _programs[asset.program] || Program;
              this.programs[name] = new Klass(this._gl, program[0], program[1]);
            }
            this._recordUsage('program', name);
            return this.programs[name];
          });
      }
    }
  }
loadProgram ( name ) { if ( ! ( name in this . manifest . program ) && ! ( name in this . manifest . rawProgram ) ) { return Promise . reject ( new Error ( 'Unknown program ' + name ) ) ; } else if ( this . programs [ name ] ) { this . _recordUsage ( 'program' , name ) ; return Promise . resolve ( this . programs [ name ] ) ; } else { if ( name in this . manifest . rawProgram ) { let asset = this . manifest . rawProgram [ name ] ; return new Promise ( ( resolve ) => { if ( ! this . programs [ name ] ) { let Klass = _programs [ asset . program ] || Program ; this . programs [ name ] = new Klass ( this . _gl , asset . vertex , asset . fragment ) ; } this . _recordUsage ( 'program' , name ) ; resolve ( this . programs [ name ] ) ; } ) ; } else { let asset = this . manifest . program [ name ] ; return Promise . all ( [ this . loader . loadAsset ( this . _getFullPath ( asset . static , asset . vertex ) , 'text' ) , this . loader . loadAsset ( this . _getFullPath ( asset . static , asset . fragment ) , 'text' ) ] ) . then ( ( program ) => { if ( ! this . programs [ name ] ) { let Klass = _programs [ asset . program ] || Program ; this . programs [ name ] = new Klass ( this . _gl , program [ 0 ] , program [ 1 ] ) ; } this . _recordUsage ( 'program' , name ) ; return this . programs [ name ] ; } ) ; } } }
Returns a promise that resolves to a bound program.
Returns a promise that resolves to a bound program .