View Full Version : fragment programs and tex units question.

02-10-2005, 10:23 AM

I'm having a weird problem with a fragment program that uses non-consecutive tex units.

My fragment program uses TEX with texture[0],2D and texture[2],2D (but does not touch texture[1]), and I am binding textures to these units with:

glActiveTexture GL_TEXTURE0+0
glBindTexture GL_TEXTURE_2D,texname0
glActiveTexture GL_TEXTURE0+2
glBindTexture GL_TEXTURE_2D,texname2

This works, until I also have something bound to GL_TEXTURE0+1, at which points it all goes pear shaped - the fragments all come out 'black'.

Attempting to somehow 'unbind' tex unit 1 (with glActiveTexture/glBindTexture target,0 ) doesn't help.

Is it legal to uses tex units like this? I can't find anything in the ARB spec about it not being legal so assumed it was.

The reason I am not just renaming the tex units to 0/1 is because I am writing a little preprocessor designed to 'strip' bits of fragment code out for lesser HW.

My hardware is a MacG5 running OSx10.3.8 with a GeForce6800 Ultra.

02-11-2005, 02:50 AM
The binding of texunit 1 should not make any difference, the problem must be somewhere else in your code.

Maybe with texunit 1 activated you're running in to the following problem:

Using more than 16 texunits in total?
Using automatic texcoord generation with more than 8 texunits?

check for gl errors when debugging.
Also try the following for a quick debug:

1. only output color of tex 0 in fragment program.
2. only output texcoord of tex 0 in fragment program.
3. only output color of tex 2 in fragment program.
4. only output texcoord of tex 2 in fragment program.

and compare the rgba values in framebuffer to the values of the working version.


02-11-2005, 04:27 PM
If I remember right, you can't/don't "unbind" textures, you just enable/disable GL_TEXTURE_2D for that unit:

glActiveTexture GL_TEXTURE0+unit
glDisable GL_TEXTURE_2D