GLSL Sampler Array Problems
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
If you do something like
(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?
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?
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.
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?
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?
Usually all uniform variables start off with a value of zero. This means all your textures will be bound to TEXTURE0.
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?
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?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement