draw()

in showcases/wind/src/layers/particle-layer/particle-layer.js [86:163]


  draw({uniforms}) {
    // Return early if elevationTexture is not loaded.
    if (!this.state.elevationTexture) {
      return;
    }
    const {gl} = this.context;

    const props = this.props;
    const {bbox, texData} = this.props;
    const {dataBounds} = texData;

    this.runTransformFeedback({gl});

    const {model, textureFrom, textureTo, delta} = this.state;
    const {textureArray} = texData;
    const {width, height, elevationTexture, bufferTo, bufferFrom, timeInterval} = this.state;

    const currentUniforms = {
      bbox: [bbox.minLng, bbox.maxLng, bbox.minLat, bbox.maxLat],
      bounds0: [dataBounds[0].min, dataBounds[0].max],
      bounds1: [dataBounds[1].min, dataBounds[1].max],
      bounds2: [dataBounds[2].min, dataBounds[2].max],
      color0: [83, 185, 148].map(d => d / 255),
      color1: [255, 255, 174].map(d => d / 255),
      color2: [241, 85, 46].map(d => d / 255),
      dataFrom: textureFrom,
      dataTo: textureTo,
      elevationTexture,
      elevationBounds: ELEVATION_DATA_BOUNDS,
      elevationRange: ELEVATION_RANGE,
      zScale: props.zScale,
      delta,
      pixelRatio: window.devicePixelRatio || 1
    };

    setParameters(gl, {
      blend: true,
      blendFunc: [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA],
      depthTest: true,
      depthFunc: gl.LEQUAL
    });
    const pixelStoreParameters = {
      [GL.UNPACK_FLIP_Y_WEBGL]: true
    };

    textureFrom.setImageData({
      pixels: textureArray[timeInterval],
      width,
      height,
      format: gl.RGBA32F,
      type: gl.FLOAT,
      dataFormat: gl.RGBA,
      parameters: pixelStoreParameters
    });

    textureTo.setImageData({
      pixels: textureArray[timeInterval + 1],
      width,
      height,
      format: gl.RGBA32F,
      type: gl.FLOAT,
      dataFormat: gl.RGBA,
      parameters: pixelStoreParameters
    });

    bufferTo.setAccessor(Object.assign({}, bufferTo.accessor, {divisor: 1}));
    model.setAttributes({
      posFrom: bufferTo
    });

    model.render(Object.assign({}, currentUniforms, uniforms));

    // Swap the buffers
    this.setState({
      bufferFrom: bufferTo,
      bufferTo: bufferFrom
    });
  }