统一位置和统一索引之间的区别? [英] Difference between uniform location and uniform index?
问题描述
OpenGL中统一位置和统一索引之间有什么区别?似乎您需要一个位置来为制服分配一个值,并且您需要索引来查询有关制服的信息.
What is the difference between uniform location and uniform index in OpenGL? It seems like you need the location to assign a value to the uniform, and you need the index to query information about the uniform.
为什么需要两个值?为什么其中一个不能同时实现这两个目的?
Why is there a need of two values? Why can't one of them fulfill both purposes?
推荐答案
似乎您需要位置来为制服分配一个值,并且您需要索引来查询有关制服的信息.
It seems like you need the location to assign a value to the uniform, and you need the index to query information about the uniform.
是的,这就是两者之间的区别.
Yes, that's the difference between the two.
为什么需要两个值?
Why is there a need of two values?
不要假设OpenGL API所做的任何事情纯粹基于需要".有时只是我们很愚蠢"或这在某种程度上是个好主意,但现在不再有意义了."
Don't assume anything that the OpenGL API does is based purely on "need". Sometimes it's just "we were stupid" or "this was kinda a good idea at one point, but now it doesn't make sense anymore."
统一的位置通常落在后面.
Uniform locations generally fall into the later.
最初的想法可以追溯到3D Labs最初的GLSL提议,那就是统一的位置可以表示某种字节偏移.该位置是一个有意义的数字,表示制服的记忆所在的实际位置.因此,该实现无需使用查找表即可将任意数字转换为实际内存所在的字节偏移量.该位置将是字节偏移量或任何其他需要的数据.
The original idea, going back to 3D Labs's original GLSL proposal, was that uniform locations could represent some kind of byte offset. That the location was a meaningful number that represented an actual location for where the uniform's memory is. Therefore, the implementation wouldn't have to use a lookup table to convert an arbitrary number into a byte offset where the actual memory is. The location would be the byte offset or whatever other data was needed.
但是,除了3D Labs自己的GLSL实现之外,实现从未真正使用过.统一位置几乎总是索引的第二种形式,并且glUniform
调用会在表中查找它们.
However, with the exception of possibly 3D Labs's own GLSL implementation, this was never actually used by implementations. Uniform locations were almost always just a second form of index, and glUniform
calls would look them up in a table.
这就是为什么我们现在能够明确指定统一位置的原因.基本上,ARB就是这样说的:我们放弃;它们现在是索引".但是他们不能只更改具有区别的旧API,因此必须保留两种单独的方式来讨论制服.
This is why we now have the ability to explicitly specify uniform locations. That's basically the ARB saying, "we give up; they're indices now". But they couldn't just change the old APIs that have the distinction, so they have to remain two separate ways to talk about uniforms.
他们并不是真的想要.在某些方面,保持区别使查询API 易于使用.可用的统一索引是从0到某个可查询计数(GL_ACTIVE_UNIFORMS
)的所有索引.一旦您可以明确指定统一的位置,二分法就变得有用,因为索引仅是可查询的数字计数,与位置无关.
And they didn't really want to. Keeping the distinction makes the query APIs a bit easier to use, in some respects. The available uniform indices are all indices from 0 to some queriable count (GL_ACTIVE_UNIFORMS
). Once you can specify uniform locations explicitly, the dichotomy becomes useful because the indices remain just a queriable count of numbers which are independent of the location.
这样,API不必具有获取所有可用的统一位置"查询.您只需查询计数,然后在0到该计数之间循环即可查询信息.对用户来说更容易,对实施也更容易.
That way, the API doesn't have to have a "get all available uniform locations" query. You just query the count, and then make a loop from 0 to that count to query information. It's easier for the user and it's easier for the implementation.
这篇关于统一位置和统一索引之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!