View Full Version : cost of glGetUniformLocation
Does anyone know what is the cost of failed uniform query?
I have 10-15 uniforms which I would like to set depending on whether that uniform is defined in the attached shader.
I understand that failed GL query is costly but I do not see any difference between 1) while checking for uniform and setting when valid location found or 2) checking only for valid uniforms and setting.
Does anyone have some more information or data regarding what is the cost of failed glGetUniformLocation call?
11-30-2006, 07:29 AM
To find a uniform which is not active will have to run through the whole search algorithm, so it's expected to take greater or equal the time to find an active uniform (=> slowest option).
Since uniform locations don't change if you don't call LinkProgram you can gather the valid locations per program once, and either simply check the location for -1 (inactive) and not sent the value (=> fastest option), or just send the values anyway and if the location is -1, the OpenGL implementation will ignore it (=> medium fast).
Calling an OpenGL entry function is slower than the if-statement you need to check if the uniform location is > -1, which makes the fastest option the smartest choice. ;)
For me since I have distinction between global (for all shaders) and local uniforms, access and search is not a low cost.
Before switching the shaders; I disable and set it to fixed function pipeline (glUseProgram(0)) - does that invalidate a uniform location?
I will also check your fastest suggestion :)
11-30-2006, 08:14 AM
Uniform locations are only invalidated when you call glLinkProgram, so the fastest option is that you just determine all uniform locations when linking the program and store it somewhere.
The uniform location query is expensive because it has to deal with strings. It has to do at least a few string compares, opposed to a simple table lookup when using the uniform index.
I don't think there is any relevant performance difference between a successful and a failed query.
12-01-2006, 01:08 AM
What overmind said ^^^
Before switching the shaders; I disable and set it to fixed function pipeline (glUseProgram(0))You mean you use
// Nothing in between
That's not necessary, just switch from A to B.
Yay, celebrating my 2222's post. Cheers. :D
Yes, I had done that and could scrap few miliSecs.
thanks to all of you, I think I have found my optimal flow.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.