Uniform behavior after glUseProgram () and speed

How fast does glUseProgram () work? Is there anything better (faster) ?:

Here are my thoughts:

  • Use 1 universal shader program, but with many input parameters and attributes (settings for each graphic class)
  • Use more than 1 shader for each graphics class.

What is the state of the uniform after changing the shader program? Do they store values ​​(e.g. matrix values)?

Here are some of the benefits of # 1:

  • Does not use glUseProgram ()

And advantages # 2:

  • No matrix changes (for example, if the Menu class and Scene3D class have different projection matrices)
+6
source share
1 answer

Which of the two options is better depends largely on what these shaders do, how different they are and how many attributes / uniforms you set and how often they change. There is not a single correct answer for all cases.

This says: keep in mind that not only the costs of changing the state, but also the cost of executing the shaders, and they are paid for each vertex and fragment. Therefore, maintaining the complexity of the shader minimum is always a good idea, and a universal shader is more complicated than specialized shaders.

Minimize state change. If you have objects A, C, E, using programs X and B, D, F, using program Y, then, ceteris paribus, render in ACEBDF, and not in ABCDEF.

Regarding the last question: programs maintain their state and, therefore, uniform values, throughout their lives, if you do not change them. But the uniform refers to the state of the program, which means that if you have two uniforms with the same name and type in different programs, the values ​​are not transferred from one program to another.

+6
source

Source: https://habr.com/ru/post/910586/


All Articles