Sign in to follow this  

how to store shader source in const GLchar?

This topic is 3586 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 don't understand why this string must be a constant if it is just going to be copied when I call glShaderSource. But given that this is how it works, how do I create a const string from a file I've just read in at runtime?

Share this post


Link to post
Share on other sites
Oh thanks.

I forgot glTexImage has the same requirement of const array pointers. I thought copying the array to the GPU would have to be complete before the CPU processes the next instruction but maybe I'm assuming too much?

Share this post


Link to post
Share on other sites
Well, if it wasn`t const then it would mean that the GL library can take your shader and modify it and return you a modified shader. That would be uncool.

Share this post


Link to post
Share on other sites
Quote:
Well, if it wasn`t const then it would mean that the GL library can take your shader and modify it and return you a modified shader. That would be uncool.

Well, drivers have been doing that since the R300 / Geforce FX era ;)

I'm not sure if this is still the case, but it used to be a very common optimization:, for example changing TEX lookups with ALU instructions (significant boost on Ati hardware for Doom3 - Id actually went in and patched the shader with this change), or dropping to precision to 16bit half-floats when you requested 32bits (Nvidia was widely criticized for doing that on 3d Mark 2003). Fun stuff! :)

Actually, the "const" part in "const char**" only indicates the intended usage (as in, you give me the data, and you can assume I won't change it). If the callee wants to change the data behind your back, he just needs to cast it to the non-const version (char**).

Share this post


Link to post
Share on other sites
Quote:
Actually, the "const" part in "const char**" only indicates the intended usage (as in, you give me the data, and you can assume I won't change it). If the callee wants to change the data behind your back, he just needs to cast it to the non-const version (char**).


Of course but that's considered abuse or a bug.

Driver side optimization is a whole other thing.

Share this post


Link to post
Share on other sites

This topic is 3586 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this