Accessing tex and texcoord after a texture2D operation.

Hi all,

When using this :

vec4 tmp = texture2D(tex, texcoord)

How can I get [b]tex/b and [b]texcoord/b from tmp ???

Thank you.

Short answer: you cannot.

Longer answer: you still cannot, because the vec4 tmp only stores the (RGBA) values sampled from the texture, but not any information about which texture or where on the texture these values are sampled from. If you really need these values you’ll have to store them somewhere where they are accessible when you need them again - or alternatively store enough information to recompute the values.

I’m curious as to why you would need to. tex is a sampler, which by its nature must be a global uniform (or you’re using bindless textures). So you almost certainly know where it is.

In fact I have fonc1() which deals with texture and modifies it, but in the main I have ““vec4 color = texture2D(tex, v_texcoord.st)””

The problem is that vec4 color will take the original texture without fonc1() modifications, and that’s not what I want.



vec4 fonc1()
{  
   do smth
   ....
   return tmp;
}

void main () 
{

vec4 color = texture2D(tex, v_texcoord.st)

}

Then you should call fonc1 and then don’t access the texture. Just use the function’s return value for the color.