Help Setting up Multitexturing environment with glTexEnvf()

I have four textures and use four texture units,one as scale ,others as texture,like this:
(Let t0 , t1 ,t2 ,t3 hold rgb(note:[0,255]) , and td as result(display on screen))

float sum = t0.r + t0.g + t0.b ;
float scal_r = t0.r/sum ;
float scal_g = t0.g/sum ;
float scal_b = t0.b/sum ;

td.r = t1.rscal_r + t2.rscal_g + t3.rscal_b;
td.g = t1.g
scal_r + t2.gscal_g + t3.gscal_b;
td.b = t1.bscal_r + t2.bscal_g + t3.b*scal_b;

What can do with glTexEnvf() function ?

glBindTexture(GL_TEXTURE_2D, texid0);

glBindTexture(GL_TEXTURE_2D, texid1);


Thanks any way.

Sorry for my poor English.

Your math looks closer to several dot products, after swizzles :-(.

You can’t do what you want with combiners you might be able to get closer with DOT3 with more combiner units and maybe crossbar, you’d need r g b components for t1 t2 t3 in the same texture unit and you’d need to deal with the implicit signed scale and bias in the DOT3 but combining the multiple DOT3 results to an rgb triplet again takes a swizzle/mask that isn’t available.

I think you’ll have to go for a shader instead because your requirements are so specific.

A shader will easily let you do this with the needed swizzles into three DOT3 instructions and the copies to combine the results to output as an rgb triplet.

Alternatively preswizzle t1 t2 and t3 to have exclusive r g and b components and to a color masked dot3 multipass for simple combiner hardware.

I agree totally with dorbie. And I’d like to add one thing.
This code of yours:

float sum = t0.r + t0.g + t0.b ;
float scal_r = t0.r/sum ;
float scal_g = t0.g/sum ;
float scal_b = t0.b/sum ;

This should not be done in the combiner/shader in any case. This begs for preprocessing (i.e. the texture sample would directly yield scal_r;scal_g;scal_b).

Thank all,I have done uising a shader.