Take the 2-minute tour ×

Shaders can have lots of different uniform names + attributes. How can I make a system which works in general case so that I do not have to know each shader uniform's name beforehand and hardcode it to code to get its location. I use OpenGL.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Unfortunately, at some point, you'll need to know what the uniform names in the shader are, and what they refer to... there's just no way around that.

Most graphics/game engines work by convention - certain uniforms are set by the engine, and shaders use them as needed. Some will add configuration, so each shader can specify what uniforms it requires, but typically, the names are still done by convention.

share|improve this answer

Use a naming convention, or parse the shader string yourself to get the type, symbol and optional storage specifier. The former option puts a responsibility on the shader programmer, while the latter solution puts the burden on the application programmer. Such code can be made a lot more elegant and efficient by using the extension GL _ ARB _ uniform _ buffer _ object, which was promoted to core in OpenGL 3.1

share|improve this answer

Your Answer


