PDA

View Full Version : About batching and GL states.



Alberto García
04-04-2017, 12:19 PM
Hi all, I have implemented a simple batching code. The goal of my batching is to group each VAO by material pass, where each material pass is related with a unique shader program, then I minimized the calls to glUseProgram, doing only one per registered pass type.

In each pass ( one per batch entry ) I have custom variables which are linked as uniforms to the shader, apart of this I have custom GL states, like "GL_DEPTH_TEST" or "glPolygonOffSet" among others.

Here a pseudo code of how it works:



for( BatchGroup *group : this->groups )
{
glUseProgram( group->GetShader()->GetId( ) );

for( BatchEntry *entry : group->entries )
{
// get the material pass, which have custom shader values and GL states
Pass *pass = entry->GetPass( );

// set custom GL states ( glCullMode, glEnable, glDisable ... )
pass->SetGLStates( )
// bind custom variables to shader program
pass->BindUniforms( group->GetShader( ) )
// call glDrawElements ...
entry->Draw( )
}
}


My question is about the line "pass->SetGLStates( )", is it correct to have differents GL states in the same batch group? or all entries which are drawn in the same group, that is, are using the same shader program, should have the same GL state.

Thanks in advance.

Dark Photon
04-04-2017, 06:47 PM
Hi all, I have implemented a simple batching code. ...
My question is about the line "pass->SetGLStates( )", is it correct to have differents GL states in the same batch group? or all entries wich are drawn in the same group, that is, are using the same shader program, should have the same GL state.

What you're doing seems pretty reasonable, depending on what GL states "SetGLStates" encompasses.

Check out pg. 48 in this presentation (video and presentation PDF link):

* Beyond Porting: How Modern OpenGL Can Radically Reduce Driver Overhead (https://developer.nvidia.com/content/how-modern-opengl-can-radically-reduce-driver-overhead-0) (NVidia)

This seems to mesh preetty well with what you're doing, and gives you suggestions for how you can layer your GL state settings by cost.

Alberto García
04-05-2017, 04:50 AM
Thanks for your response Dark Photon.

I will read the presentation.