Threaded View

Quality of Implementation: Debug shader variable locations

Now that OpenGL's debug context concept is a bit more well-defined (thanks to language in KHR_debug and the like), let's expand on this. NVIDIA already starts spamming stdout when you're in debug, so let's close another source of errors:

Accidentally using the correct variable locations.

Unless you explicit assign a variable location in OpenGL, you must query its location to know where it is. However, most implementations will assign locations sequentially, starting from 0. Which means that code can be written which accidentally does the right thing.

I would suggest that, upon every shader compilation (in debug only), generating a random number and starting the location assignments from there. This will help show where a program is accidentally forgetting an explicit assignment or a query.