ofShader::setUniformTexture .. location parameter

After using this function for a long time…I’m just not sure what the location parameter does exactly.

shader.setUniformTexture("tex0", vidGrabber.getTexture() ,0);

What does it do and how do I find out which texture location to use?

Hi,

You can make that whatever you want, though keep it under 16 to be on the safe side (less on an old card), though it can be queried. Unless told otherwise if you do an ofImage.draw this will be bound to slot 0.

I have to say I am a bit hazy on the particulars, I always saw it as “this is how many textures this card has silicon to do multitexturing with at the same time” back in the pre-shader days.

https://www.opengl.org/wiki/Texture#Texture_image_units

1 Like

that function binds that texture to the specified slot location, and calls set Unitform using the location

I Don’t know why openframeworks does this? normally in other apis you do this

tex1.bind(1) // bind to location 1
tex2.bind(2) // bind to location 2
shader.setUniform("tex1",1) // uses the texture bound to location 1
shader.setUniform("tex2",2) // uses the texture bound to location 2
 
1 Like