Jump to content
  • Advertisement
Sign in to follow this  
ishkabible

glShaderSource arguments

This topic is 3039 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

ok so i don't understand the arguments of glShaderSource, it uses a double pointer for the source code, but why. dose it expect me to tokenize it or something? second it uses an int* as a length argument, is it supposed to be passed by reference, cuz passing an int by pointer makes no sense? thirdly what is count? it says number of elements in int char** and int* that suggests to me that it wants me to tokenize it, and give it each individual length of each string in said array in the int array. but why on earth would they do that. also i have not seen any documentation that says that i cant just put the entire string in the first element of the char**, so if this is possible than why not just use a char* instead? this makes me think it wants me to do something else.

Share this post


Link to post
Share on other sites
Advertisement
First argument is the shader object. Second argument is the number of strings. Third argument is the array of strings. Fourth argument is an array of ints indicating the length of each string in argument three.
If the fourth is NULL, each string must be null terminated. If you have just one long string, pass it as

const char* code = "shader string";
int len = strlen(code);

glShaderSource(obj, 1, (const char**)&code, &len);

Share this post


Link to post
Share on other sites
Because you can pass array of strings (mostly good for lines) there. "length" argument would be the length of each passed string. "count" argument means how many strings are in the array. I personally use a whole string and pass it like:

glShaderSource(shader, 1, &shader_source, &length_of_source);

Share this post


Link to post
Share on other sites
so i can pass it as one big string, so what's the point of using the double pointer here? Kasya said for lines but is there a speed advantage? i don't think so as it would take more time to parse out the lines than it would be to just get each byte and store it in one big string but i could be wrong.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!