PingPong

PingPong

This is a class defined in the WebGl Util module.

var PingPong = require('paraviewweb/src/Common/Misc/PingPong'),
instance = new PingPong(gl, [fbo_1, fbo_2], [texture_1, texture_2]);

constructor(glContext, [fbo1, fbo2], [texture1, texture2])

This will bind the framebuffers with the textures.

swap()

Swap active texture and framebuffer.

clearFbo()

Clear framebuffers content.

getFramebuffer() : framebuffer

Return the current active framebuffer.

getRenderingTexture() : texture

Return the current active texture.

Source

index.js
import WebGl from 'paraviewweb/src/Common/Misc/WebGl';

export default class PingPong {
constructor(gl, fbos, textures) {
this.gl = gl;
this.idx = 0;
this.fbos = fbos;
this.textures = textures;

WebGl.bindTextureToFramebuffer(this.gl, this.fbos[0], this.textures[1]);
WebGl.bindTextureToFramebuffer(this.gl, this.fbos[1], this.textures[0]);
}

swap() {
this.idx += 1;
this.idx %= 2;
}

clearFbo() {
this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.fbos[0]);
this.gl.clear(this.gl.COLOR_BUFFER_BIT);

this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.fbos[1]);
this.gl.clear(this.gl.COLOR_BUFFER_BIT);

this.idx = 0;
}

getFramebuffer() {
return this.fbos[this.idx];
}

getRenderingTexture() {
return this.textures[this.idx];
}
}