Zero sized arrays?!

I posted this at but didnt all the answers I wanted:

I’m trying to make a ‘master’ shader that does basically everything my engine needs and have it’s functionality controlled by compile time constants for things like number of textures, number of spotlights, point lights etc

The problem with this method is that if I declare an array like so:

 uniform sampler2DShadow g_spot_shadowmaps[g_num_spot_lights]; 

then when I have no spot lights g_num_spot_lights will be zero and the spec doesn’t let you do that.

the person who replied on gamedev said that I should try leaving the arrays unsized and that the compiler would figure out how big they needed to be based on my static loops. So I did that change and my shaders compile with nvidia but the 3dlabs glsl validator complains:

“array must be redeclared with a size before being indexed with a variable”

am I doing something that is not compatible with the spec? what is the best way to do what I’m trying to do. I guess I could use lots of ifdefs but that seems a bit more hacky

If g_num_spot_lights is a #define constant you can do this:

#if g_num_spot_lights != 0
uniform sampler2DShadow g_spot_shadowmaps[g_num_spot_lights];

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.