Jump to content
  • Advertisement
Sign in to follow this  
coordz

OpenGL does GLSL support const arrays?

This topic is 4274 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've declared an array as const in my fragment shader and my nVidia drivers complain warning C7516: OpenGL does not allow constant arrays but then allows the shader to execute (correctly). Looking through the GLSL specs and through my orange book I can't find a mention of arrays not being allowed to be constant. Does GLSL allow const arrays or is this nVidia being weird? I can't think of a reason const arrays wouldn't be allowed........

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Beware NVidia GLSL compiler allows you to use cg constructs which are not allowed in pure OpenGL (... and you may face angry owners of ATI cards very soon :) To remedy this, I recomend you to download small NVidia utility(look on their dev page) where you can force strict OpenGL compiler.

MaR

Share this post


Link to post
Share on other sites
yeah :-D the thing is that I don't trust nVidia's compiler. In their last driver release (not the current dev drivers, the one before) the compiler claimed gl_MaxTextureCoords wasn't a const which it blatantly is. This has been fixed but leaves me doubtful as to whether GLSL really doesn't allow const arrays (can't find a mention in the spec) or if it's nVidia's driver playing games with me... again..... anyone tried const arrays with ATI drivers?

Share this post


Link to post
Share on other sites
As of GLSL v1.1 rev 60, this is allowed as arrays are first class objects, but before it was not, and I quote:

"There is no mechanism for initializing arrays at declaration time from within a shader." (GLSL v1.1 rev 59!, §4.1.9)

"It is an error to write to a const variable outside of its declaration, so they must be initialized when declared." (GLSL v1.1 rev 59, §4.3.2)

Combining these two leads to the conclusion that prior to v1.1 rev 60, constant arrays are not allowed. As of rev 60, you _can_ initialise an array using an array constructor.

And although nVidia has great drivers and an amazingly flexible GLSL compiler, be warned, ATI isn't as forgiving :-). I had written a blur shader that used a const kernel which compiled without a problem on my GF6800 GT, but failed to compile on an (albeit not so recent) ATI. This isn't surprising, knowing that nVidia adheres to the Cg standard. Perhaps newer ATIs do to, I wouldn't know.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!