glUseProgram()和速度后制服的行为 [英] Behavior of uniforms after glUseProgram() and speed

查看:199
本文介绍了glUseProgram()和速度后制服的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

glUseProgram()有多快?是否有更好的(更快)?:

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

这是我的想法:



  1. 为每个图形类使用多于1个着色器

更改着色器程序后的统一状态是什么?他们保存的值(例如,矩阵的值)?

What state are uniforms in after changing the shader program? Do they save values (for example, values of matrices)?

这里是我认为#1的好处是:

Here are what I consider the benefits of #1 to be:


  • 不使用glUseProgram()


  • 没有矩阵变化(例如,如果菜单和类 Scene3D 有不同的投影矩阵)

  • No matrix changes (for example, if class Menu and class Scene3D have different Projection matrices)

推荐答案

的两个选项更好地在很大程度上取决于那些着色器做什么,它们是多么不同,你设置了多少属性/制服,以及它们被改变的频率。对于所有情况没有一个正确的答案。

What of the two options is better largely depends on what those shaders do, how different they are and how many attributes/uniforms you set and how often they are changed. There is no one right answer for all cases.

这就是说:请记住,不仅有状态更改的成本,还有着色器运行时成本是每个顶点和每个片段支付的。因此保持着色器的复杂性低是一个好主意,通用着色器比专用的着色器更复杂。

That said: Keep in mind, there is not only the cost for state changes, but also a shader runtime cost and it is payed per vertex and per fragment. So keeping the complexity of the shader low is always a good idea and a universal shader is more complex than specialised ones.

最小化状态更改。如果你有对象A,C,E使用程序X和B,D,F使用程序Y,然后,所有其他是相等的,顺序ACEBDF,而不是ABCDEF。

Minimize state change. If you have objects A, C, E using Program X and B, D, F using Program Y then, all else being equal, render in order ACEBDF, not ABCDEF.

关于最后一个问题:程序保留他们的状态,并因此保持制服的价值,在他们的一生,除非你重新链接他们。但统一是每个程序状态,这意味着如果你有两个统一在不同的程序中具有相同的名称和类型,值不会从一个程序继承到另一个程序。

Regarding the last question: Programs retain their state, and thus the values of uniforms, over their lifetime, unless you relink them. But uniforms are per program state, which means that if you have two uniforms with the same name and type in different programs, values won't carry over from one program to another.

这篇关于glUseProgram()和速度后制服的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆