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.