glsl - How does a fragment shader work with sample1D and sample2D in a single texture unit? -
i working opengl client code uses default texture unit gl_texture0. never creates texture it's referring default texture name 0. drawing commands issued, if new texture needed, created on fly - either gl_texture_1d or gl_texture_2d.
my understanding both 1d , 2d textures refer same unit = 0. depending on texture being used - 1d or 2d - pass uniform flag shader knows how work on texture.
i define sampler1d , sampler2d in fragment shader. assign unit 0 both - @ least, that's understanding of should do.
in fragment shader use code
uniform sampler1d texture1; uniform sampler2d texture2; uniform int texflagf; void main() { if(texflagf == 1) { gl_fragcolor = texture1d(texture1, gl_texcoord[0].s); } else if(texflagf == 2) { gl_fragcolor = texture2d(texture2, gl_texcoord[0].st); } else { gl_fragcolor = gl_color; } }
where texflagf takes values 0, 1, , 2, depending on whether i'm drawing without textures, 1d texture, or 2d texture. note in both use gl_texcoord[0], 1 unit active. vertex shader passes these texcoords through:
gl_texcoord[0] = gl_multitexcoord0;
1) see if first draw 1d texture, 2d texture doesn't display; , vice-versa. why?
2) client code assigns unit via code
tex1dloc = glgetuniformlocation(prog,"texture1"); gluniform1i (tex1dloc,0); tex2dloc = glgetuniformlocation(prog,"texture2"); gluniform1i (tex2dloc,0);
this shows i'm setting unit both 1d , 2d texture 0.
if set tex2dloc unit 1 - though there no reference gl_texture1 in entire code! - seems work. never pass texture coordinates unit 1 in vertex shader , still access gl_texcoord[0] in both sampler1d , sampler2d.
i not understand why setting 1 of samplers different (non-existent!) unit works.
can explain me what's going on here?
thanks.
Comments
Post a Comment