Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between uniform location and uniform index?

Tags:

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?

like image 315
Dan Webster Avatar asked Apr 30 '13 14:04

Dan Webster


People also ask

What is uniform index?

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.

What does uniform mean in GLSL?

A uniform is a global Shader variable declared with the "uniform" storage qualifier. These act as parameters that the user of a shader program can pass to that program. Their values are stored in a program object.


1 Answers

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?

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.

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.

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.

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.

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.

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.

like image 188
Nicol Bolas Avatar answered Sep 24 '22 19:09

Nicol Bolas