title: GLES20 Texturing - do I glUniform1i(uniformLoc, txtUnit) before or after glActiveTexture() + glBindTexture()?
body: <p>Let's say I play a video on a <code>GLSurfaceView</code> with a custom renderer, and in said renderer I use a fragment shader that takes an extra texture for lookup filtering. Said fragment shader looks as follows:</p>
  
  <pre><code>#extension GL_OES_EGL_image_external : require
  precision mediump float;
  
  uniform samplerExternalOES u_Texture;
  uniform sampler2D inputImageTexture2;
  
  varying highp vec2 v_TexCoordinate;
  
  void main()
  {
      vec3 texel = texture2D(u_Texture, v_TexCoordinate).rgb;
      texel = vec3(
          texture2D(inputImageTexture2, vec2(texel.r, .16666)).r,
          texture2D(inputImageTexture2, vec2(texel.g, .5)).g,
          texture2D(inputImageTexture2, vec2(texel.b, .83333)).b
      );
  
      gl_FragColor = vec4(texel, 1.0);
  }
  </code></pre>
  
  <p>In the <code>onDrawFrame()</code> function, after the <code>glUseProgram()</code> call, I have the <code>onPreDrawFrame()</code> function that basically binds said texture into the shader's uniform. It currently looks like this:</p>
  
  <pre><code>public void onPreDrawFrame()
  {
      if (filterSourceTexture2 != -1 &amp;&amp; filterInputTextureUniform2 != -1) {
          GLES20.glActiveTexture(GLES20.GL_TEXTURE2);
          GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, filterSourceTexture2);
          GLES20.glUniform1i(filterInputTextureUniform2, 2);
      }
  }
  </code></pre>
  
  <p><code>filterSourceTexture2</code> is the texture unit corresponding to the extra texture.</p>
  
  <p>What I'm confused of is that if I put the <code>glUniform1i()</code> call before <code>glActiveTexture()</code>, it still works fine, but most of the tutorials I've seen put the <code>glUniform1i()</code> call like the above code.</p>
  
  <p>So which is recommended?</p>