Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Modern OpenGL (3+) and state sorting

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2010
    Location
    Hungary
    Posts
    28

    Question Modern OpenGL (3+) and state sorting

    Dear All,


    let me have a general question, and confirmation:


    In my game engine, I have a state graph to minimize the state changes.
    Each mesh knows what ShaderProgram, and what Texture it uses,
    and based on this info all of them are inserted into a simple graph, like below:
    (sorry for the ascii art)





    Code :
                   ....
                    /
          ShaderProgram1
             /           \
            /             \
         Texture1     Texture2
           /    \                  \
          /      \                  \
       Mesh1   Mesh2       Mesh3






    My questions is:
    This is my simple (and maybe bad) solution for state sorting, but in general,
    is the state sorting stuff is still relevant on today's GPU?

    Should I still sort my meshes according to their Shader/Texture/Material whatever properties?

    Or should I just simply draw the meshes, and let each mesh bind the ShaderProgram, and Texture it uses.
    In that case a mesh would bind (glBindTexture) a texture which might be already bound,
    or maybe it was already bound before by another similar mesh.





    Thank You for sharing Your thoughts about this!
    A
    There must be some way outta here ...

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    Yes, state sorting boosts performance. You can sort by shader, then texture (for example texture0).
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2010
    Location
    Hungary
    Posts
    28
    Quote Originally Posted by V-man View Post
    Yes, state sorting boosts performance. You can sort by shader, then texture (for example texture0).
    Thank You, V-man, yes I do that kind of sorting,
    I just wondered if this complication still needed,
    but it seems yes.

    Cheers
    A
    There must be some way outta here ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •