Search code examples
androidopengl-eslibgdxopengl-es-2.0

LibGDX returning black pixels ScreenUtils.getFrameBufferPixels


This is happening only on one device (so far reported) and can't be sure how isolated it is other than no other users have yelled at me over it.

Huawei P9 Lite (2017) is producing this issue (https://www.pdevice.com/product/huawei-p9-lite-2017-price-specs)

I'm simply retrieving the screen's pixels and putting them into a Pixmap. For this one device, however, the pixels (RGBA) are all [0,0,0,1] - so it's not even an alpha problem.

For all of my own test devices, and so far for all other users, this isn't happening.

screenPixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888);
ByteBuffer pixels = screenPixmap.getPixels();
Gdx.gl.glReadPixels(0, 0, width, height, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixels);

I feel like it has to be a GPU issue because it's kind of weird...


Solution

  • Well, it seems like it's just an OpenGL gotcha from what I can tell.

    You can't reliably glReadPixels from the screen/default framebuffer, some cases will throw GLError 1286 aka framebuffer is bad. Most cases seems it's fine.

    Luckily in my case, I'm already rendering my app to a secondary buffer before displaying that on the screen, so I'm just glReadPixels-ing that instead, seems to work now.