I am having issues reading back the alpha channel from my OpenGL texture on Android. I call glReadPixels
this way:
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
and just as a test, I made a fragment shader looking like this:
gl_FragColor = vec4(0.5, 0.5, 0.5, 0.5);
For each pixels, I get back { 64, 64, 64, -1 }.
I've tried all sorts of things to work out why the alpha is not returned the same way as the RGB values, including this before each render:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
//Tried various blend functions
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
But no matter what I do, it comes back -1.
Is this an Android limitation or what am I missing?
Just as a note, I am using an off-screen FBO if it makes any difference.
EDIT: If I do this:
int[] bits= new int[4];
glGetIntegerv(GL_RED_BITS, bits, 0);
glGetIntegerv(GL_GREEN_BITS, bits, 1);
glGetIntegerv(GL_BLUE_BITS, bits, 2);
glGetIntegerv(GL_ALPHA_BITS, bits, 3);
I get back { 8, 8, 8, 0 }.