title: OpenGL ES2: multiple textures with Mali GPU in fragment shader
body: <p>I am currently trying to get multiple textures working on android (with one fragment shader). It works fine on my Nexus 4 but on all Samsung devices I've tested it on, it just doesn't show the rectangle at all.
  The problem seems to be that texture2d is called twice within the fragment shader code:</p>
  
  <pre><code>precision mediump float;                
  uniform sampler2D uTexture;
  uniform sampler2D refractTexture;       
  varying vec2 vTexCoordinate;
  varying vec2 vRefTexCoordinate;
  
  void main() {
      vec2 scaleVec = vec2(0.05, 0.05);
      vec4 bumpTex = 2.0 * texture2D(refractTexture, vRefTexCoordinate) - 1.0;
      vec2 refCoords = vTexCoordinate.xy + bumpTex.xy * scaleVec;
  
      gl_FragColor = texture2D(uTexture, refCoords);
  }
  </code></pre>
  
  <p>In this shader I distort the texture (<code>uTexture</code>) with a normal map (<code>refractTexture</code>).
  I've tried out using the correct (not the calculated) coordinates for <code>gl_FragColor</code> and as soon as I delete <code>vec4 bumpTex = 2.0 * texture2D(refractTexture, vRefTexCoordinate) - 1.0;</code> it appears on the devices.</p>
  
  <p>Any hint will help.</p>
  
  <p>As requested here is the Java Code I use to set up the textures:</p>
  
  <pre><code>    mTextureUniformHandle = GLES20.glGetUniformLocation(mProgram,
              "uTexture");
  
      GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
  
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle);
  
      GLES20.glUniform1i(mTextureUniformHandle, 0);
  
      if (refractNormal &amp;&amp; textureRefBuffer != null) {
          mTextureRefUniHandle = GLES20.glGetUniformLocation(mProgram,
                  "refractTexture");
  
          GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
  
          GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureRefDataHandle);
  
          GLES20.glUniform1i(mTextureRefUniHandle, 1);
  
          mTextureRefCoordinateHandle = GLES20.glGetAttribLocation(mProgram,
                  "aRefTexCoordinate");
  
          GLES20.glVertexAttribPointer(mTextureRefCoordinateHandle,
                  mTextureCoordinateDataSize, GLES20.GL_FLOAT, false, 0,
                  textureRefBuffer);
          GLES20.glEnableVertexAttribArray(mTextureRefCoordinateHandle);
  
      }
  
      mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgram,
              "aTexCoordinate");
      GLES20.glVertexAttribPointer(mTextureCoordinateHandle,
              mTextureCoordinateDataSize, GLES20.GL_FLOAT, false, 0,
              textureBuffer);
      GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
  </code></pre>
  
  <p>And the C Code of the vertex shader:</p>
  
  <pre><code>        uniform mat4 uMVPMatrix;
          attribute vec4 vPosition;
          attribute vec2 aTexCoordinate;
          attribute vec2 aRefTexCoordinate;
          varying vec2 vTexCoordinate;
          varying vec2 vRefTexCoordinate;
  
          void main() {         
              vTexCoordinate = aTexCoordinate;
              vRefTexCoordinate = aRefTexCoordinate;
              gl_Position =   uMVPMatrix*vPosition;
          }
  </code></pre>