title: Stencil buffer clear values not 0?
body: <p>Ive been trying to understand / debug a problem to do with the stencil buffer. I probably dont understand how it works versus how I think it works. Essentially I have a scene where I render all my solid objects and assign them a stencil value of 1. I then go through the same scene again, but the second time I render only the transparent objects and give them a stencil value of 2. In the final step I have a screen quad that draws the scene to a texture. I want to use the stencil buffer to only draw the final quad where the stencil bits were set to 1 or 2. So in code:</p>
  
  <pre><code>// First enable the stencil buffer
  gl.enable( gl.STENCIL_TEST );
  gl.clearStencil( 0 );
  gl.clear(gl.STENCIL_BUFFER_BIT); // presumably this clears the buffer to 0?
  
  // ...for the solid meshes
  gl.stencilFunc( gl.ALWAYS, 1, 0xffffffff ); // Always pass the stencil
  gl.stencilOp( gl.REPLACE, gl.REPLACE, gl.REPLACE ); // Replace the stencil value with ref=1
  
  
  // ...for the transparent meshes
  gl.stencilFunc( gl.ALWAYS, 2, 0xffffffff ); // Always pass the stencil
  gl.stencilOp( gl.REPLACE, gl.REPLACE, gl.REPLACE ); // Replace the stencil value with ref=2
  
  // ...for the final screen quad
  gl.stencilFunc( gl.GEQUAL, 1, 0xffffffff ); // Only draw the bits higher than 1 (so 1 and 2 should be included)
  gl.stencilOp( gl.KEEP, gl.KEEP, gl.KEEP); //  Dont touch the stencil values in the buffer
  </code></pre>
  
  <p>However this never seems to work. From my tests it seems as though the stencil values are set to 0xffffffff before I assign them values. This makes the GEQUAL test pointless as the buffer values are greater than 0. </p>
  
  <p>I created a JS fiddle to demo what I mean. I draw a small square and assign its values to 4. Then draw a bigger square and test for gequal to 5. I would have thought that the bigger square would always fail. However it always passes. When I test using gl.stencilFunc( gl.GEQUAL, 4, 0xffffffff ); I see the correct small square only. But when I test  gl.stencilFunc( gl.GEQUAL, 0xffffff, 0xffffffff ); then it also looks correct. This to me says that the stencil buffer is not set to 0? </p>
  
  <p><a href="http://jsfiddle.net/90af0rov/" rel="nofollow">http://jsfiddle.net/90af0rov/</a></p>
  
  <p>Im really confused and would appreciate any pointers on this &lt;:(</p>