Forums - Cocos2dx on Adreno 225: black picture returned by glReadPixels() from FBO

1 post / 0 new
Cocos2dx on Adreno 225: black picture returned by glReadPixels() from FBO
Sergey Shambir
Join Date: 15 Jul 13
Posts: 1
Posted: Mon, 2013-07-15 05:14

Hi,

We (development & QA teams) got black pictures with glReadPixels() function on various Samsung S3 variants with Adreno 225 GPU inside. Since I partially fixed this trouble, I gonna provide more information about this bug. Can you please point me to directions for further research? I have no access to any buggy device and should fix it being absolutely blind, so any help is welcome.

Problem appears on all Samsung S3 models with Qualcomm processor and Adreno 225 GPU. There are 13 models in total, and 6 have such GPU, see [1]. We are using cocos2dx game engine, and it have CCRenderTexture class [2] that actually uses FBO, attaches texture to it and reads pixels via glReadPixels() before saving to file. When CCRenderTexture used without reading pixels, it works OK on all tested Samsung S3 models. However, saving rendered image to file causes calling glReadPixels() which returns black picture. Texture is NPOT (we specify size 114x53 and NPOT extension used by cocos2dx automatically). We also using cocos2dx design size feature, so our viewport size differs from real screen size, there also was report about such case [3].

Other people also got such troubles with Adreno 200 and Adreno 225, see [4] and [5].

To workaround trouble, I've tried different ways to get rendered content pixels. Again: we have FBO and texture, and should read their content. Function glGetTexImage() is not available in GLES, so the only way I see is to use EGL.

There are EGLImage object and extension to create it from existing texture [6], unfortunately I have no idea how to read EGLImage pixels, can you point me to possible solution?

Another way is direct textures, widely used internally in android sources. I got common idea from Firefox developer blog [7], used AndroidGraphicsBuffer class from Firefox [8] and this thread [9]. Now it enabled on 2/6 devices (I've forgot to add yet 4 devices to whitelist), fixes trouble on one device and causes another issue on other device. In [11] you can see image which is mostly black and have transparent strips (these strips look white or gray because there also is backround scene).

Seems that transparent strips appear because we have 114x53 image and NPOT textures actually implemented as square POT textures with unused areas, it handled automatically by OpenGL driver but we should handle it manually when reading GrapghicBuffer content directly. Should I use POT textures and finally truncate pixels manually? Affected device description from QA team: "Samsung Galaxy S3 Sprint, SPH-L710, 720 x 1280, Snapdragon S4 Plus MSM8960 Dual core, 1500 MHz, Krait, 2 GB, 4.1.1, 4.1.2".

I'm ready to give more information and code samples. First, see SimpleGame example in branch "adreno_pixels" at this git repo: https://github.com/sergey-shambir/cocos2d-x

To setup SimpleGame sample, see [10] or just import android projects "java" and "SimpleGame" to Eclipse, make project reference from "SimpleGame" to "java", add java.jar to SimpleGame dependencies, build and run. Tweak used only on some devices, it prints "Samsung S3 tweak: gralloc available for this device (model '%s', GLES vendor '%s')." when tweak enabled and "Samsung S3 tweak: should not use gralloc for this device (model '%s', GLES vendor '%s'), fallback to glReadPixels." when disabled.

References:
[1] https://en.wikipedia.org/wiki/Samsung_Galaxy_S_III#Model_variants
[2] https://github.com/cocos2d/cocos2d-x/blob/develop/cocos2dx/misc_nodes/CC...
[3] http://www.cocos2d-x.org/boards/6/topics/9237
[4] https://developer.qualcomm.com/forum/qdevnet-forums/mobile-technologies/...
[5] https://developer.qualcomm.com/forum/qdevnet-forums/mobile-gaming-graphi...
[6] https://developer.qualcomm.com/forum/qdevnet-forums/mobile-technologies/...
[7] http://snorp.net/2011/12/16/android-direct-texture.html
[8] http://dxr.mozilla.org/mozilla-central/source/widget/android/AndroidGrap...
[9] http://forums.arm.com/index.php?/topic/15782-glreadpixels/
[10] http://cocos2d-x.org/projects/cocos2d-x/wiki/Android_Environment_Setup
[11] https://dl.dropboxusercontent.com/u/86213541/bugrepro_s3_sprint.png

  • Up0
  • Down0

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.