in showcases/wind/src/layers/particle-layer/particle-layer.js [198:269]
runTransformFeedback({gl}) {
// Run transform feedback
const {textureFrom, textureTo, delta, timeInterval, transform} = this.state;
const {bbox} = this.props;
const {dataBounds, textureArray, textureSize} = this.props.texData;
const {width, height} = textureSize;
const {bufferFrom, bufferTo, now} = this.state;
let {counter} = this.state;
// onBeforeRender
const time = Date.now() - now;
let flip = time > 500 ? 1 : -1;
if (flip > 0) {
counter = (counter + 1) % 10;
flip = counter;
}
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
});
const uniforms = {
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],
dataFrom: textureFrom,
dataTo: textureTo,
time,
flip,
delta // TODO: looks to be 0 always , verify.
};
bufferFrom.setAccessor(Object.assign({}, bufferFrom.accessor, {divisor: 0}));
bufferTo.setAccessor(Object.assign({}, bufferTo.accessor, {divisor: 0}));
transform.run({uniforms});
transform.swapBuffers();
if (flip > 0) {
flip = -1;
this.setState({
now: Date.now()
});
}
this.setState({
counter
});
}