Friday 2 January 2009

Uniforms and Attributes

Volatile-Engine's old way of doing uniforms was rather complicated. You stuck an annotation on the field that is a uniform, registered the class that the field belonged to and you were done; however the background stuff that made all this possible was rather hideous. Lots of reflection, lots of workarounds around Array stuff and in the end I quoted Sherwin Nulland: "Ahhh fuck it".

So what do to? Well, I stole MatthiasM's idea (with his permission). Get the list of uniforms from the shader after linking -> create an array of Uniforms and access the uniforms through getUniform(String);

This allows a few things to happen:

1) You can only set Uniforms to what are declared in the shader. No more exceptions saying that uniform isn't there at runtime...

2) Allows a context specific state to be stored in java to compare uniform values before uploading to GL. Each Uniform has a Handle which has a reference to the cache.

3) It now plays rather nicely with Surface and its shizzlness. Hurrah for easy multi-target rendering!

Happy '09 by the way.

No comments: