which texture is loaded


i have a sampler in my shader called mytex

uniform sampler3D mytex;

iLocation is the location of mytex .


so a texture whose texture id is 0 is sampled using mytex in the shader.

my problem is that the code is fairly large and spread out in multiple files and i am having trouble locating which loaded texture is set to texture id 0. is there a way i can find this (in a reverse lookup sort of way at the point where i bind glUniform1i(iLocation,0))?


No, not “a texture whose texture id is 0”. The 3D texture object which is bound to texture unit 0. Texture ID and texture unit index are two different things.

Also, if you have such troubles you should revise the design of your application.

If what you want to know is the ID of the 3D texture that is bound to texture unit 0, you can query that using glGetIntegerv with a pname of GL_TEXTURE_BINDING_3D. However, using glGet* is a bad pattern and might hit your performance compared to if you would track it on your own.

Also, don’t forget that there could be more textures bound to the same texture unit, one per texture target. I.e. you can have a 2D and a 3D texture both bound to texture unit 0 (how useless is that btw) and practically the sampler uniform declaration in the GLSL code decides which one will be actually used (i.e. in your case obviously the 3D texture binding point).