for-loop in shader code working with hardcoded number but not with uniform variable

Basically GLSL specifies that implementations may restrict loops to have "constant" bounds on them. This is to make it simpler to optimize the code to run in parallel (different loop counts for different pixels would be complex). I believe on some implementations the constants even have to be small. Note that the spec just specifies the "minimum" behavior, so some devices might support more complex loop controls than the spec requires.

Here's a nice summary of the constraints: http://www.khronos.org/webgl/public-mailing-list/archives/1012/msg00063.html

Here's the GLSL spec (look at section 4 of Appendix A): http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf


http://www.opengl.org/discussion_boards/showthread.php/171437-can-for-loops-terminate-with-a-uniform

http://www.opengl.org/discussion_boards/showthread.php/177051-GLSL-loop-problem-on-Radeon-HD-cards

http://www.opengl.org/discussion_boards/showthread.php/162722-Problem-when-using-uniform-variable-as-a-loop-count-in-fragment-shader

https://www.opengl.org/discussion_boards/showthread.php/162535-variable-controlled-for-loops

If you have a static loop it can be unrolled and made into static constant lookups. If you absolutely need to make it dynamic, you'll need to store indexed data into a 1D texture and sample that instead.

I'm guessing that the hardware on the desktop is more advanced than on the tablet. Hope this helps!