title: How to save a variable inside a shader on WebGL, and how to read its value from the JavaScript program?
body: <p>I'm trying to use textures on WebGL to perform parallel array folding operations. The problem is I don't know how to save the result of a computation performed on the shader on the GPU itself. I also don't know how to read it back from JavaScript when the computation is done. See below for illustration:</p>
  
  <pre><code>precision mediump float;
  varying vec2 pix_pos; // the 2D coord of the texture
  uniform sampler2D texture; // this is the input array
      uniform sum_step(uniform* sampler2D){
         // this should perform a reduction step
         // for example, if texture = [1,2,3,4,5,6,7,8]
         // then, in the next step, it would be:
         // [3,7,11,15]
         // and so on, until we get the sum in O(log(n))
      };
  void main(void) {
      if (texture.length &gt; 1) // if not fully processed, computes a step
          texture = sum_step(texture); // don't work, texture is readonly!
  };
  </code></pre>