Results 1 to 3 of 3

Thread: About batching and GL states.

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2014
    Posts
    17

    About batching and GL states.

    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:

    Code :
    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.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,660
    Quote Originally Posted by Alberto García View Post
    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 (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.

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2014
    Posts
    17
    Thanks for your response Dark Photon.

    I will read the presentation.

Similar Threads

  1. Batching
    By SubZero00 in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 04-16-2014, 12:39 AM
  2. batching befuzzlement
    By ugluk in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 10-11-2010, 04:55 PM
  3. Batching and VBO's
    By Zulfiqar Malik in forum OpenGL: Advanced Coding
    Replies: 38
    Last Post: 08-03-2005, 01:02 AM
  4. Yet another batching thread
    By SeskaPeel in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 11-09-2004, 07:38 AM
  5. Regarding VAR and buffer batching
    By Cirrus in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 11-12-2002, 12:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean