0

i'm trying to compare 2 textures using opengles 2.0 [hoping they would be strictly identical]. This is to analyse the results of my post processing.

So, basically, i'm using twice the below fragment shader (once bound to a framebuffer, and then again to render to the screen).

precision lowp float;

uniform sampler2D u_Texture0;
uniform vec2 u_sizeVideo;

varying vec3 v_texCoord;

void main()
{
    vec2 vCoord = gl_FragCoord.st/ u_sizeVideo.st;

    gl_FragColor = texture2D(u_Texture0,vCoord);
}

The picture i'm rendering is on purpose of the same size as my GLSurfaceView (ie: 1280*720). I then read the results using glReadPixels and create the corresponding bitmap. Then i create the bitmap again but this time using the original picture

        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inDensity=320; //i have double checked that this is the same density as from the bmpGPU
        options.inMutable=true; //same here, trying to manually set all options so the 2 bmp are identical
        final int resourceId=R.drawable.mypic;

        final Bitmap bmpCPU = BitmapFactory.decodeResource(mActivityContext.getResources(), resourceId, options);
        ByteBuffer buff1=ByteBuffer.allocateDirect(imgWidth * imgHeight * 4).order(ByteOrder.LITTLE_ENDIAN);;
        bmpCPU.copyPixelsToBuffer(buff1);
        buff1.rewind();

        final Bitmap bmpGPU = Bitmap.createBitmap(imgWidth, imgHeight,Config.ARGB_8888); 
        ByteBuffer buff2=ByteBuffer.allocateDirect(imgWidth * imgHeight * 4).order(ByteOrder.LITTLE_ENDIAN);
        GLES20.glReadPixels(0, 0, imgWidth, imgHeight, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE,buff2);
        buff2.rewind();
        bmpGPU.copyPixelsFromBuffer(flipByteBuffer(buff2));// the flip function works as expected

        storeImage(bmpGPU,"gpu");
        storeImage(bmpCPU,"cpu");

So what is interesting to note is that, despite the fact that the 2 bitmaps look identical, they aren't of the same size. The original one is 40Kb whereas the GPU one is 45Kb.

Btw, i have also set the filtering to what i suspect is the most appropriate:

GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);

Any suggestion would be most welcome.

  • What is your drawing routine with vertices attributes. Using gl_FragCoord for uv calculation and specifying repeat parameter seems strange to me also... – j-p Jan 13 '15 at 12:07
  • Thanks for your reply j-p. My varying vec3 v_texCoord was just a left over but I don't want to use it as I need to perform some per pixel operation. Perhaps I'm wrong but if I understand properly how opengles works I should use gl_FragCoord to avoid any interpolation. When it comes to the use of GL_REPEAT, and since the dimension of my glsurfaceview is the same as my picture, I'm not expecting this to have any impact. is that correct? – RogerLePatissier Jan 13 '15 at 14:45
  • Right, gl_FragCoord is in texture space and the unit is the pixel. So your WRAP_ST param is irrelevant, ensure it's not causing some unwanted behaviour. – j-p Jan 13 '15 at 14:50
  • i have just double checked and unfortunately the problem remains the same. Having said that i made a bit of progress as i realised that imgCPU had no Alpha and so by adding imgCPU.setHasAlpha(true) i end up with 2 images of the same size!!! a problem still persists though as imgCPU.equals(imgGPU) returns false, despite the fact that imgCPU.sameAs(imgGPU) returns true??? looping through the ByteBuffers i can indeed see some differences in there. Any idea any one? – RogerLePatissier Jan 13 '15 at 23:34

0 Answers0