libgdx/libgdx — pull request #91 by xoppa (2012-10-28 14:57:23+00:00)
Title: Shaderprogram, replace string lookup by int lookup

I've been testing this change for over a month now and haven't found any problems with it. It shouldn't break backward compatibility with existing code (except for a deprecated warning perhaps). It doubled my fps when using large shaders (alot of uniforms and attributes).

The original implementation used a lot of string comparisons to find the location of the uniform/attribute. This change adds the ability to use an int for that. It maintains a global array of all uniform/attribute names and uses the index within that array to identify the attribute/uniform.

For now it uses a helper class (Parameter) to map the global id to the location and type within that shader. It can be futher optimized by using one, two or three int[] array instead. In my tests I found that shader locations could be just as well the index of that array. I'm currently experimenting with that, but i'm afraid that it might break in some rare situations. So the helper class is just to be safe.

I added "ByGUID" to the methods to identify the difference between location and guid (both int). I'm not sure about that naming, but haven't come up with something better. Any suggestions are welcome.