This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Multiple textures with Mali-GPUs don't work properly

Note: This was originally posted on 6th February 2013 at http://forums.arm.com

Hi,

I have a problem with Mali-GPUs and multiple textures with OpenGL ES 2 (at least, I think it could be a problem with the Mali-GPU).

So, here my problem:
I just want to use multiple textures in my Android-App with OpenGL-ES 2.0, but the necessary code in the fragment shader doesn't work with most Samsung devices (tested Galaxy Nexus, galaxy S3, Galaxy Note 2, Galaxy S2). The texture wich is new calculated in the fragment shader (see code below), doesn't show up on this devices, but on the Nexus 4, it works fine. So, I conclude, that this problem could be caused by the Mali-GPU in the Samsung devices.

Here the fragment shader code I am using:
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);

}


The error seems to be in following line:
vec4 bumpTex = 2.0 * texture2D(refractTexture, vRefTexCoordinate) - 1.0;
If I delete this line (and the follwing line vec2 refCoords =...), the texture appears (it's just not calculated, but at least, it is visible). I have no idea, why this works on a Nexus 4, but not on a Mali-device.

Are there any known problems wiht the texture2d()-function on the Mali-GPUs or is it just my fault (but, how I said, on other non-mali devices it works properly)?

I would be glad about any tips and support relating to my problem.
  • Note: This was originally posted on 6th February 2013 at http://forums.arm.com

    Can you give us a little more detail about the texture you are trying to load?

    Resolution, color format, etc?
  • Note: This was originally posted on 6th February 2013 at http://forums.arm.com

    oh, i forgot :rolleyes:
    here the Texture Data: 512x512, .jpeg-File, 24 Bit

    I've tried some other textures (other format, resolution), but nothing changed. Also tried to put the textures in a 'drawable-nodpi'-folder (how i've read at stackoverflow, this could lead into same problems) but there was no change too.

    in addition the code to load the texture (maybe there went something wrong, but i can't figure out what):
    mTextureUniformHandle = GLES20.glGetUniformLocation(mProgram,
             "uTexture");

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle);

    GLES20.glUniform1i(mTextureUniformHandle, 0);

    if (refractNormal && 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);


    It's ridiculous, developed on a nexus 4, everything worked like a charm, then, installed it on a galaxy s3, no refracted texture was visible and it totally freezed the whole phone (had to do a complete restart). I've solved the crashing problem (there was missing 'precision mediump float' in the fragment shader), but the texture is still not visible. every texture, that is loaded with a 'normal' fragment-shader-code like the following one, is visible, so the error is probably in the calculation of the texture in the fragment-shader-code above.

    my 'standard'-fragment-shader-code (this code works on the Mali-Devices)
     
             precision mediump float;
       uniform vec4 vColor;  
       uniform sampler2D uTexture;  
       varying vec2 vTexCoordinate;
         
       void main() {  
        gl_FragColor = vColor * texture2D(uTexture, vTexCoordinate);
       }
  • Note: This was originally posted on 8th February 2013 at http://forums.arm.com

    Hi Rul3r,

    Sorry to hear you're having trouble. Do you happen to have a sample application which exhibits the problem? Also can you let me know the version of the OS on the device, and whether it is stock or custom ROM.

    Thanks,
    Chris
  • Note: This was originally posted on 8th February 2013 at http://forums.arm.com

    Hi,

    thanks for your answer.
    I have tested some devices. Here a list with the OS/rom:
    - Samsung galaxy S3, 4.1.2, samsung firmware (root)
    - Samsung galaxy Note 2, 4.1.2, samsung firmware (root)
    - Samsung Galaxy S2, 2.3, samsung firmware (no root)
    - Samsung Galaxy Nexus, 4.2, stock android (no root)

    on all this devices the texture, that was recalculated in the fragment shader with this two lines:
      vec4 bumpTex = 2.0 * texture2D(refractTexture, vRefTexCoordinate) - 1.0; 
            vec2 refCoords = vTexCoordinate.xy + bumpTex.xy * scaleVec; 


    was not visible. But on the LG Nexus 4 (Adreno 320 GPU), it works. If i delete the two lines from above in my shader code, the normal texture is visible on all devices....

    I will have a look, whether I could make a project where the error is repoducible (actual project is quite large)
  • Note: This was originally posted on 13th February 2013 at http://forums.arm.com

    Hi,

    the problem is now solved. I have no idea how, but it isn't there anymore.

    I have made a new project to demonstrate my problem, but I couldn't use it to demonstrate the problem, because in this App, the problem was not there any longer. So, I replaced different parts of the code in my larger project with the code of the demo-projet, but nothing changed. Lastly I copied the shader-code files (I am loading the code for the shaders from a text-file) into my main project and it worked.

    I don't know where the error was. The shadercodes in the text-files are the same, but with the one file it won't work.

    But anyways, thank you for your help