I want to render a big scene(a modeled city) using WebGL, and I think occlusion culling is a good way to optimize the performance.
And I know WebGL 2.0 has a new feature called 'Query Objects' to get the occlusion information. But every time I use gl.getQueryParameter(query, gl.QUERY_RESULT), I got the same result 1.
And I wrote a demo here to explain the problem:
var query = gl.createQuery();
gl.beginQuery(gl.ANY_SAMPLES_PASSED, query);
gl.drawArrays(gl.TRIANGLES,0,n);
gl.endQuery(gl.ANY_SAMPLES_PASSED);
var tick = function(){
if(!gl.getQueryParameter(query,gl.QUERY_RESULT_AVAILABLE)){
requestAnimationFrame(tick);
return;
}
var result = gl.getQueryParameter(query,gl.QUERY_RESULT);
console.log(Number(result));
gl.deleteQuery(query);
};
tick();
and here are my vertex information that the sceond triangle is obscured by the first triangle.
var vertexData = new Float32Array([
0.0,0.5,0.0, //first triangle
-0.5,-0.5,0.0,
0.5,-0.5,0.0,
0.0,0.5,-0.5, //second triangle
-0.5,-0.5,-0.5,
0.5,-0.5,-0.5
]);
and the result is always 1.
What's the result '1' stands for?
In addition, how could I do occlusion culling using WebGL 2.0? Is there any helpful samples?