Hello there.
I’m trying to implement occlusion culling in my engine to improve performance of rendering of meshes.
But, I have one problem that I don’t understand ^_^.
I decompose my rendering in two parts.
The first part get occlusion queries from drawing cubes (Bounding boxes of meshes component all of my scene).
The second part print the number of sample passed (per query object). Normally, I have to see many differents numbers, but, I saw only the same number, it’s the last result in the query vector…
Otherwise, if I test to get all query in the first loop (where I render cube and not mesh), it works, so I don’t understand…
void Model::mRenderOcclusion(u32 bindingOcclusionUniform, std::shared_ptr<Shader> &occlusion)
{
mat4 *matAABB = (mat4*)mOcclusionBuffers.map(3);
mOcclusionBuffers.bind(2, BufferType::DRAW_INDIRECT);
mOcclusionBuffers.bindBase(3, BufferType::UNIFORM, bindingOcclusionUniform);
glMemoryBarrier(GL_COMMAND_BARRIER_BIT);
mOcclusionVao.bind(true);
occlusion->bind(true);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glDepthMask(GL_FALSE);
// Render all Bounding Boxes with queries
for(u32 i = 0; i < mNumMeshes; ++i)
{
*matAABB = mMatrixAABB[i];
glMemoryBarrier(GL_UNIFORM_BARRIER_BIT);
glBeginQuery(GL_SAMPLES_PASSED, mOcclusionQuery[i]);
glDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, (DrawElementCommand*)nullptr + i);
glEndQuery(GL_SAMPLES_PASSED);
// If I uncomment this part, it's working
/*s64 nQuery = 0;
while(nQuery == 0)
glGetQueryObjecti64v(mOcclusionQuery[i], GL_QUERY_RESULT_AVAILABLE, &nQuery);*/
}
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask(GL_TRUE);
}
void Model::render(u32 nInstance, u32 bindingMaterialOcclusionUniform, std::shared_ptr<Shader> &occlusion, std::shared_ptr<Shader> &render)
{
DrawElementCommand *command = (DrawElementCommand*)mBuffers.map(2);
DrawElementCommand *commandOcclusion = (DrawElementCommand*)mOcclusionBuffers.map(2);
for(u32 i = 0; i < mNumMeshes; ++i)
(command++)->primCount = (commandOcclusion++)->primCount = nInstance;
mRenderOcclusion(bindingMaterialOcclusionUniform, occlusion);
mBuffers.bind(2, BufferType::DRAW_INDIRECT);
glMemoryBarrier(GL_COMMAND_BARRIER_BIT);
render->bind(true);
mVao.bind(true);
glFlush();
int n = mNumMeshes * 3 / 4;
s64 available = 0;
while(available == 0)
glGetQueryObjecti64v(mOcclusionQuery[n], GL_QUERY_RESULT_AVAILABLE, &available);
for(u32 i = 0; i < mNumMeshes; ++i)
{
s64 nQuery = 0;
glGetQueryObjecti64v(mOcclusionQuery[i], GL_QUERY_RESULT, &nQuery);
std::cout << nQuery << std::endl;
}
}
Thanks :). And sorry for my english…