Hi,
I know the question is pretty generic, but hopefully there's some common
cause of this kind of error or something:
Basically the short version is, what can cause a GL stack UNDERflow error???
I have written a simple fragment shader in glsl for blending two texture
in different classic blending modes (add, multiply, difference...); I
have a few (16) instances of the same shader (an abstraction containing
a [glsl_fragment], a [glsl_vertex] and a [glsl_program], the abstraction
being repeated 16 times) rendering at the same time.
I am using uniform variables to tell each "instance" what texture to use
and I use the message [texunit ...( to [pix_texture] objects in order to
"name" the textures with some numbers.
Now, I am getting some unexpected results like: the texture being used
is not the one I expect, so I am trying to debug my own work since
there's certainly some stupid error, but
I have realized that the console shows this error message:
GL: subdesbordamiento de pila
which is in spanish and I guess it is a bad translation of "stack
underflow".
While I can easily think about errors I may make that may produce stack
OVERflows, I really can't figure out what the hell I may have done wrong
that may cause a stack UNDERflow. I don't know what kind of anomaly to
look for.
At the moment I can't attach the patch, however it wouldn't be of great
use: I would need to isolate the problem but I don't know where to start
from. I attach the fragment shader in case it is of any help though I
doubt it.
My hope is that there is something very "typical" to take care of which
"usually" cause stack underflows.
For example is it a problem that I sometimes "cut off" a piece of
rendering chain in order to not display some objects?? i.e.
[gemhead]
|
(....)
|
| |
[spigot]
|
(...)
I do this very often but this is the first time I use shaders. Is there
something I should do (e.g. some message to send to the [glsl_program])
when it starts/stops receiving the gemlist????
Any help will be greatly appreciated
Thanks in advance
m.
--
Matteo Sisti Sette
matteosistisette(a)gmail.com
http://www.matteosistisette.com
uniform sampler2D curtex;
uniform sampler2D bgndtex;
uniform int blendmode;
uniform float cropleft, cropright, croptop, cropbottom;
float computeGrey(vec4 srccolor);
void main (void)
{
vec2 xy=gl_TexCoord[0].st;
float x=gl_TexCoord[0].s;
float y=gl_TexCoord[0].t;
vec4 frontcolor = texture2D(curtex, xy);
float bx=x*cropright+(1.-x)*cropleft;
float by=y*croptop+(1.-y)*cropbottom;
vec4 bgndcolor = texture2D(bgndtex,vec2(bx,by));
if (blendmode==0) //normal
gl_FragColor = frontcolor;
else if (blendmode==1) //add
gl_FragColor = frontcolor + bgndcolor;
else if (blendmode==2) //multiply
gl_FragColor = frontcolor * bgndcolor;
else if (blendmode==3) { //difference
float frontgrey=computeGrey(frontcolor);
float bggrey=computeGrey(bgndcolor);
float resultgrey=abs(frontgrey-bggrey);
gl_FragColor=vec4(resultgrey, resultgrey, resultgrey, 1.);
}
else { //subtract
float frontgrey=computeGrey(frontcolor);
float bggrey=computeGrey(bgndcolor);
float resultgrey=max(0.,min(1.,bggrey-frontgrey));
gl_FragColor=vec4(resultgrey,resultgrey,resultgrey,1.);
}
gl_FragColor.a=1.;
}
float computeGrey(vec4 srccolor) {
return 0.3*srccolor.r+0.59*srccolor.g+0.11*srccolor.b;
}