Jump to content
  • Advertisement
Sign in to follow this  
ghempton

GLSL Sampler Array Problems

This topic is 4324 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 am trying to use an array of samplers in a fragment shader that I am writing, However I cannot seem to assign multiple textures to the array. In my shader I have: uniform sampler2D inputFrames[4]; Then to assign the array I have the following in my main program: GLuint samplersLoc = glGetUniformLocation(p, "inputFrames"); glUniform1iv(samplersLoc, 4, texture_units); // crashes here Where texture_units contains an array of all the texture units I want in the array of samplers. It just crashed on the line where I set the uniform variable. I have also tried to assign each array element independently but that crashes as well. If I just assign a single texture unit to the first element in the array it works: glUniform1i(samplersLoc, 0); // this works Also, if I use two different samplers (not in an array) it doesn't crash if I assign each to a different texture unit. I think this might have something to do with my particular graphics card's implementation of glsl since I have been noticing a lot of other quirky things like it doesn't like it if I return from the main function in a shader. I am using a Nvidia go 7400 with the optimal drivers (as of a couple weeks ago). I think I might also just be having problems with arrays in general. Also, I noticed that sometimes when I change a shader it seems to revert back to what it did a couple of edits ago, like it was cached on the graphics card or something. Anyone experienced that before? Thanks, Gordon

Share this post


Link to post
Share on other sites
Advertisement
If you do something like


char temp[200];

for(int i=0; i<4; i++){
sprintf(temp, "inputFrames[%d]", i);
uni = glGetUniformLocation(p, temp);
glUniform1i(uni, texture_units);
}



(which works for me) when does it crash? How many texture units can you assign? Does 'uni' get set to a proper value each time?

Share this post


Link to post
Share on other sites
It crashes on the second one. Its kind of weird though, the shader can actually access the sampler even if I dont even assign the sample a value. There are some weird things going on.

Share this post


Link to post
Share on other sites
Ok, so I think that it wasn't working because I wasn't ever using the other element in the array in the shader so the gpu compiler was removing them when it compiled the shader at runtime.

Now I have a different problem. I never assign the sampler uniform variable and it still works! When I do assign the sampler uniform variable it doesn't work (but at least not it doesn't crash). Any Ideas?

Share this post


Link to post
Share on other sites
Usually all uniform variables start off with a value of zero. This means all your textures will be bound to TEXTURE0.

Quote:
When I do assign the sampler uniform variable it doesn't work (but at least not it doesn't crash).


So you can run through my little code snippet, uni is always a proper value and your prog doesn;t crash? And then your shader doesn't work?

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!