I'm using NDK on Android with OpenGL ES2.
- I create PBuffer surface using eglCreatePbufferSurface with resolution 1024x576. I use GL_RGBA format. 8 bits for each color component.
- Load texture from a bitmap and blit it onto the surface. Call glFlush().
- Than I create another texture and read the frame buffer into this texture with glCopyTexImage2D. Texture internal format is GL_RGBA.
- I blit the new texture onto the same frame buffer again. Call glFlush().
- Finally call glReadPixels to read the frame buffer and save it as Bitmap.
The result is pixelated:
All my textures have these parameters:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
Also if I use window surface instead of PBuffer and draw the result on the screen it is correct and not pixelated.
Another thing I tried is to render the original texture to the PBuffer and read pixels from buffer straight away. Without extra pass using glCopyTexImage2D. The result is also correct.
If I change glCopyTexImage2D internal format from GL_RGBA to GL_RGB everything works fine. My PBuffer color space format is RGBA.
Update: My code seems to work fine on the emulator but not on a Nexus 7 device.
So why is it pixelated when I use glCopyTexImage2D with GL_RGBA format?