title: iPhone iOS5 querying OpenGL ES 2.0 pipeline objects if they are hidden in the view or not..."Occlusion"
body: <p>EXT_occlusion_query_boolean is new with OS5.0,</p>
  
  <p>it looks to me like not a single person on the entire internet has posted about these new extensions nor used this code.... </p>
  
  <p>so here they are set up properly...which is not documented anywhere as far as i can tell... you can imagine how they would go in your code from this little sudo code here: </p>
  
  <pre><code>import UIKit/UIKit.h
  
  import GLKit/GLKit.h
  
  import "GLProgram.h"
  
  GLuint testBox,hasBeenTested,theParams;
  
  //...
  
  glGenQueriesEXT(1, &amp;testBox);
  
  glBeginQueryEXT(GL_ANY_SAMPLES_PASSED_EXT, testBox);
  
  
  //... draw an object .......
  
  glEndQueryEXT(GL_ANY_SAMPLES_PASSED_EXT);
  
  glGetQueryObjectuivEXT(testBox, GL_QUERY_RESULT_AVAILABLE_EXT, &amp;hasBeenTested);
  
  if (hasBeenTested) glGetQueryObjectuivEXT(testBox, GL_QUERY_RESULT_EXT, &amp;theParams);
  
  glDeleteQueriesEXT(1, &amp;testBox);
  
  if (!theParams)  object is hidden;  don't draw next time;
  </code></pre>
  
  <p>hopefully some here can use this code,  i've tested it and it works, 
  however, there appears to be a bug in GLKit, where if you use self.effect2 = [[GLKBaseEffect alloc] init]; type of GLKit code to render an object, rather than a normal GLES2.0 pipeline, the queries will fail to give you the correct answer... (never hidden) although i tested a pipeline object hiding a GLKBaseEffect object, (which fails) so it could be there is a bug just mixing the two types, if you go the other way,  have a GLKBaseEffect object hide a pipeline object,  it gives the correct answer,  i did not test further yet.</p>
  
  <p>so the question is,  I bet i can go further with this and create collision detection in the vertex/fragment shader somehow...   this code i found looks like a start...  given these two pieces of sudo code,  can someone get me closer to collision detection that just triggers when a "part" goes completely inside another part?  a quicker easier/firststep could be to have the entire object hidden inside another object before a positive is triggered,  this would be a great start,  any ideas?</p>
  
  <p><a href="http://ucv.academia.edu/Rhadam%C3%A9sCarmona/Papers/743483/Volume-Surface_Collision_Detection" rel="noreferrer">http://ucv.academia.edu/RhadamésCarmona/Papers/743483/Volume-Surface_Collision_Detection</a></p>
  
  <p><img src="https://i.stack.imgur.com/s5LjD.png" alt="http://ucv.academia.edu/RhadamésCarmona/Papers/743483/Volume-Surface_Collision_Detection"></p>