title: Reading Pixels in WebGL 2 as Float values
body: <p>I need to read the pixels of my framebuffer as float values.
  My goal is to get a fast transfer of lots of particles between CPU and GPU and process them in realtime. For that I store the particle properties in a floating point texture.</p>
  
  <p>Whenever a new particle is added, I want to get the current particle array back from the texture, add the new particle properties and then fit it back into the texture (this is the only way I could think of to dynamically add particles and process them GPU-wise).</p>
  
  <p>I am using WebGL 2 since it supports reading back pixels to a <code>PIXEL_PACK_BUFFER</code> target. I test my code in Firefox Nightly. The code in question looks like this:</p>
  
  <pre><code>// Initialize the WebGLBuffer
  this.m_particlePosBuffer = gl.createBuffer();
  gl.bindBuffer(gl.PIXEL_PACK_BUFFER, this.m_particlePosBuffer);
  gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);
  ...
  // In the renderloop, bind the buffer and read back the pixels
  gl.bindBuffer(gl.PIXEL_PACK_BUFFER, this.m_particlePosBuffer);
  gl.readBuffer(gl.COLOR_ATTACHMENT0); // Framebuffer texture is bound to this attachment
  gl.readPixels(0, 0, _texSize, _texSize, gl.RGBA, gl.FLOAT, 0);
  </code></pre>
  
  <p>I get this error in my console:</p>
  
  <pre><code>TypeError: Argument 7 of WebGLRenderingContext.readPixels could not be converted to any of: ArrayBufferView, SharedArrayBufferView.
  </code></pre>
  
  <p>But looking at the current WebGL 2 Specification, this function call should be possible. Using the type <code>gl.UNSIGNED_BYTE</code> also returns this error.
  When I try to read the pixels in an ArrayBufferView (which I want to avoid since it seems to be way slower) it works with the format/type combination of <code>gl.RGBA</code> and <code>gl.UNSIGNED_BYTE</code> for a <code>Uint8Array()</code> but not with <code>gl.RGBA</code> and <code>gl.FLOAT</code> for a <code>Float32Array()</code> - this is as expected since it's documented in the WebGL Specification.</p>
  
  <p>I am thankful for any suggestions on how to get my float pixel values from my framebuffer or on how to otherwise get this particle pipeline going.</p>