PDA

View Full Version : Collision detection: Need to port occlusion query!



Andreas K
07-16-2010, 10:44 PM
Hello, my following algorithm works perfect with opengl. Now
it has to work on opengl AND opengles. But opengles does not support queries: glBeginQuery() e.g. is not available. Any idea what to code instead?

glGenQueries(1, &queries);
occquery=queries;
samples=0;
int x,y,w,h;
w=isect.Width();
h=isect.Height();
x=isect.xmin;
y=engine->Surface()->h -isect.ymin-h;
err=glGetError();
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GEQUAL, 0.5f);
glEnable(GL_SCISSOR_TEST);
glScissor(x, y, w, h);
glEnable(GL_STENCIL_TEST);
glColorMask(false, false, false, false);

glClear(GL_STENCIL_BUFFER_BIT);
glStencilFunc(GL_ALWAYS,1,1);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
// Returns NULL but forces objects to be drawn
left->Resource()->Draw( left/*, window*/ );

glStencilFunc(GL_EQUAL, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

glBeginQuery(GL_SAMPLES_PASSED, occquery);

// Returns NULL but forces objects to be drawn
right->Resource()->Draw( right/*, window*/ );

glEndQuery(GL_SAMPLES_PASSED);

do {
glGetQueryObjectiv(occquery, GL_QUERY_RESULT_AVAILABLE, &samples);
} while (samples != GL_TRUE);



glGetQueryObjectiv(occquery, GL_QUERY_RESULT, &samples);
glColorMask(true, true, true, true);
glDisable(GL_STENCIL_TEST);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_ALPHA_TEST);
glDeleteQueries(1, &queries);
err=glGetError();
GLASSERT(err == GL_NO_ERROR);
return samples;

andreas