glReadPixels return 0 or wrong value with some Chipset

Hi, I use Cocos2dx-2.1.1

I have problem with glReadPixels and LG 936 (Qualcomm Snapdragon APQ8060, mounted also on some galaxy SII and other devices)

I read one pixel of sprite

@

char buffer;
CCRenderTexture * rt = CCRenderTexture::create(1, 1, kCCTexture2DPixelFormat_RGBA8888);
rt~~>retain;
// Draw into the RenderTexture
rt~~>beginWithClear(0, 0, 0, 0);

// move touch point to 0,0 so it goes to the right place on the rt
sprite~~>setAnchorPoint );
sprite~~>setPosition(ccp(—point.x * sprite~~>getScale, —point.y * sprite~~>getScale()));
sprite~~>visit;
float x = 0; y = 0;
float w = 1; h = 1;
glReadPixels;
rt~~>end();@

glReadPixels return buffer with strange value.
Sometimes 0 other time not 0 but not correct value.

I have also problem with

CCImage* CCRenderTexture::newCCImage(bool flipImage)

because this function use glReadPixels.
When I use newCCImage, the image is black (Only with LG 936)

Someone know this problem and resolved it?

More context (no solution or discussion): https://developer.qualcomm.com/forum/qdevnet-forums/mobile-gaming-graphics-optimization-adreno/26481

Also looks like we had the same issue on Samsung Galaxy S III with Qualcomm processor… Thread (no solution or discussion): http://www.cocos2d-x.org/boards/6/topics/30440

P.S. I plan to investigate this problem tomorrow and can send you patch to cocos2d-x develop branch, where TestCpp app shows issue. Unfortunately I have no access to buggy device (recently I bought Samsung S III with Mali GPU instead - that’s funny confusion).

Looks like glGetTexImage() can be used instead of glReadPixels inside cocos2d-x. I plan to play with it tomorrow and will publish patch to cocos2d-x develop branch in my clone on github. Are you ready to test it and help me too (since I have no access to buggy device)? :slight_smile:

Hi Sergey, thanks for answer.

I am ready, only for tomorrow I have a LG 936 that seems buggy.

Also, I am searching for another SII with this chipset.

Tell me how I have to use glGetTexImage and I try.

As you can see above, I use glReadPixels to read one pixel of a sprite.

Yet one report: https://developer.qualcomm.com/forum/qdevnet-forums/mobile-technologies/mobile-gaming-graphics-optimization-adreno/26799

glGetTexImage() is not available in GLES, I’m investigating EGL alternatives.

Unfortunately I see no solution
* glGetTexImage is not available in GLES
* EGLImage usage is very limited in NDK (despite that android internally have GraphicBuffer)

In [1] I’ve tried glReadPixel for RGBA4444 framebuffer instead of RGBA8888, perhaps it will help. To check it, build TestCpp from this branch and run it on buggy device, check RenderTextureTest: pictures should be black if bug is here. Play a bit with enabled/disabled alpha channel and hack. I hope that hack fixes bug and will be glad to see your reports :wink:

Maybe some workaround with EGLImage or rendering to custom EGLSurface is still possible, I’m not sure.

https://github.com/sergey-shambir/cocos2d-x/tree/adreno_fix_1 Updated: doesn’t work as expected.

hi, so, I first tried the patch only in RenderTexture (I use cocos2dx 2.1.1)

Black image again.

Now, I’m trying to run your TestCpp, but eclipse is made for hard person.

I imported project, many errors, I resolved Paths and Symbols -> Source Location.
I included in the project, cocos2dxlib, from platform/android/java, because I just have this project for 2.1.1

Remain one error, understandable for me:

make: * [obj/local/armeabi/objs/testcpp_shared/testcpp/main.o] Error 1

I have old ndk r8b, I’m updating it, but I don’t think that are the cause.

Console write build_native log and the path of NDK_ROOT, COCOS2DX_ROOT, APP_ROOT, APP_ANDROID_ROOT are correct

You can suggest me how I could build this project?

thanks
Don

some update, I’m able to run your TestCpp_fix on LG 936. I update NDK r8e from r8d.

I test RenderTextureCache

Works well with all 4 configuration.

But, also TestCpp 2.1.1, works well
Maybe LG 936 doesn’t mount buggy chipset?

My two different problems remain, cannot read pixel color and black sprite from CCRenderTexture, but now, for second problem, I try to implement mechanism of RenderTextureTest sample.

  • Save texture to file
  • Get texture2D with CCTextureCache::sharedTextureCache()~~>addUIImage;
    like this:
    @

char png;
sprintf;
// m_pTarget is a RenderTexture
m_pTarget~~>saveToFile(png, kCCImageFormatPNG);

CCImage pImage = m_pTarget->newCCImage;
CCTexture2D
tex = CCTextureCache::sharedTextureCache()->addUIImage(pImage, png);

CC_SAFE_DELETE(pImage);

CCSprite *sprite = CCSprite::createWithTexture(tex);

addChild(sprite);

@

I have to test on LG 936, so I don’t know if works ok.