# Is FBO with EGLImage Working on SGX540 ?

**URL:** <https://forums.imgtec.com/t/is-fbo-with-eglimage-working-on-sgx540/1336>\
**Category:** PowerVR Insider\
**Created:** [March 16, 2012, 2:22pm UTC](https://forums.imgtec.com/t/is-fbo-with-eglimage-working-on-sgx540/1336 "2012-03-16T14:22:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![baudouis](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@baudouis](https://forums.imgtec.com/u/baudouis)\
**Post date:** [March 16, 2012, 2:22pm UTC](https://forums.imgtec.com/t/is-fbo-with-eglimage-working-on-sgx540/1336/1 "2012-03-16T14:22:12Z")

</div>

Hi all,  
i try to perform off screen rendering using FBO and using as target texture a Android native Buffer.  
To do so, i created a Android GraphicBuffer (with width and height = 1024)  
&nbsp; GraphicBuffer\*&nbsp; buffer = new GraphicBuffer(texWidth, texHeight,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HAL\_PIXEL\_FORMAT\_RGB\_565,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GraphicBuffer::USAGE\_HW\_TEXTURE |&nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GRALLOC\_USAGE\_SW\_READ\_OFTEN |  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GRALLOC\_USAGE\_SW\_WRITE\_OFTEN);  
  
Then from that GraphicBuffer i get a native buffer handle that i use to create an EGLImage (ImageKHR)  
&nbsp; EGLImageKHR pEGLImage = \_eglCreateImageKHR(eglGetCurrentDisplay(),  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EGL\_NO\_CONTEXT, EGL\_NATIVE\_BUFFER\_ANDROID, (EGLClientBuffer)anb, attrs);  
  
  
Then i initialize the FBO in order to render into that ImageKHR  
&nbsp;&nbsp;&nbsp; // create a framebuffer object  
&nbsp;&nbsp;&nbsp; glGenFramebuffersOES(1, framebuffers);  
&nbsp;&nbsp;&nbsp; framebuffer = framebuffers[0];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp; glBindFramebufferOES(GL\_FRAMEBUFFER\_OES, framebuffer);&nbsp;&nbsp;&nbsp;   
  
&nbsp;&nbsp;&nbsp; //Create Depth buffer  
&nbsp;&nbsp;&nbsp; glGenRenderbuffersOES(1, depthRb);  
&nbsp;&nbsp;&nbsp; Renderbuf = depthRb[0];  
&nbsp;&nbsp;&nbsp; glBindRenderbufferOES(GL\_RENDERBUFFER\_OES, Renderbuf);  
  
&nbsp;&nbsp;&nbsp; glRenderbufferStorageOES(GL\_RENDERBUFFER\_OES, GL\_DEPTH\_COMPONENT16\_OES, width, height);  
  
&nbsp;&nbsp;&nbsp; glFramebufferRenderbufferOES(GL\_FRAMEBUFFER\_OES, GL\_DEPTH\_ATTACHMENT\_OES, GL\_RENDERBUFFER\_OES, Renderbuf);  
  
&nbsp;&nbsp;&nbsp; // Create GL texture, bind to GL\_TEXTURE\_2D, etc.  
&nbsp;&nbsp;&nbsp; glGenTextures(1, textures);  
&nbsp;&nbsp;&nbsp; texture = textures[0];   
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp; //color texture  
&nbsp;&nbsp;&nbsp; glBindTexture(GL\_TEXTURE\_2D, texture);  
&nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp; glTexParameterx(GL\_TEXTURE\_2D, GL\_TEXTURE\_WRAP\_S, GL\_CLAMP\_TO\_EDGE);  
&nbsp;&nbsp;&nbsp; glTexParameterx(GL\_TEXTURE\_2D, GL\_TEXTURE\_WRAP\_T, GL\_CLAMP\_TO\_EDGE);  
&nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp; glTexParameterx(GL\_TEXTURE\_2D, GL\_TEXTURE\_MAG\_FILTER, GL\_LINEAR);  
&nbsp;&nbsp;&nbsp; glTexParameterx(GL\_TEXTURE\_2D, GL\_TEXTURE\_MIN\_FILTER, GL\_LINEAR);  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp; \_glEGLImageTargetTexture2DOES(GL\_TEXTURE\_2D, pEGLImage);  
  
&nbsp;&nbsp;&nbsp; // attach the texture to FBO color attachment point  
&nbsp;&nbsp;&nbsp; glFramebufferTexture2DOES(GL\_FRAMEBUFFER\_OES,  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GL\_COLOR\_ATTACHMENT0\_OES, GL\_TEXTURE\_2D,  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; texture, NULL);  
&nbsp;   
&nbsp; // check FBO status  
&nbsp;&nbsp;&nbsp; int status = glCheckFramebufferStatusOES(GL\_FRAMEBUFFER\_OES);  
&nbsp;&nbsp;   
&nbsp;&nbsp; //Then Bind the FBO  
&nbsp;&nbsp; glBindFramebufferOES(GL\_FRAMEBUFFER\_OES, framebuffer);  
  
After that i’m doing my rendering that i expect to be at teh end in my GraphicBuffer  
  
  
The problem i have is that i’m checking error after each gl call and there is no error; the FBO status is COMPLETE so NO error is raised. But when i look at the FBO nothing is rendered.  
  
I tried that code on other GPUs and it is working fine so i’m suspecting that i’m missing something for SGX. But after long days of investigation still same result: Nothing is rendered.  
  
It seems that Size is not the problem (Power of 2) may be RGB565 but is tried with RGB888 and still nothing.  
  
COuld you help me giving idea for investigation or link on document or even better providing solution ?  
  
Thanks in advance.  
  
Seb

---

<div class="post-metadata">

**Author:** ![cuda-geek](https://avatars.discourse-cdn.com/v4/letter/c/54ee81/32.png) [@cuda-geek](https://forums.imgtec.com/u/cuda-geek)\
**Post date:** [March 21, 2012, 1:40pm UTC](https://forums.imgtec.com/t/is-fbo-with-eglimage-working-on-sgx540/1336/2 "2012-03-21T13:40:41Z")

</div>

Did you try to use HAL\_PIXEL\_FORMAT\_RGBA\_8888 format of textures?  
  
  
  
cuda.geek2012-03-21 14:47:19

---

<div class="post-metadata">

**Author:** ![baudouis](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@baudouis](https://forums.imgtec.com/u/baudouis)\
**Post date:** [March 21, 2012, 2:25pm UTC](https://forums.imgtec.com/t/is-fbo-with-eglimage-working-on-sgx540/1336/3 "2012-03-21T14:25:46Z")

</div>

Yes i tried also but it is the same it is as if the FBO is not doing anything (even reporting the error)  
  
If 565 was not supported i would expect an error no ?  
  
BR  
  
Seb

---

<div class="post-metadata">

**Author:** ![cuda-geek](https://avatars.discourse-cdn.com/v4/letter/c/54ee81/32.png) [@cuda-geek](https://forums.imgtec.com/u/cuda-geek)\
**Post date:** [March 21, 2012, 2:46pm UTC](https://forums.imgtec.com/t/is-fbo-with-eglimage-working-on-sgx540/1336/4 "2012-03-21T14:46:02Z")

</div>

I noticed that libui has very silent errors ![Smile]()  
  
What hardware has your device? I mean processor and gpu unit. Realization of libui is platform dependent. Open code from [https://github.com/android/platform\_frameworks\_base/blob/dd1880ee5bea09e9d37c6db29ef20e49d619c094/libs/ui/GraphicBufferMapper.cpp](https://github.com/android/platform_frameworks_base/blob/dd1880ee5bea09e9d37c6db29ef20e49d619c094/libs/ui/GraphicBufferMapper.cpp) said that U can create &nbsp;   
4b:  
 &nbsp; &nbsp; &nbsp; &nbsp;HAL\_PIXEL\_FORMAT\_RGBA\_8888  
 &nbsp; &nbsp; &nbsp; &nbsp;HAL\_PIXEL\_FORMAT\_RGBX\_8888  
 &nbsp; &nbsp; &nbsp; &nbsp;HAL\_PIXEL\_FORMAT\_BGRA\_8888  
3b:  
 &nbsp; &nbsp; &nbsp; &nbsp;HAL\_PIXEL\_FORMAT\_RGB\_888  
2b:  
 &nbsp; &nbsp; &nbsp; &nbsp;HAL\_PIXEL\_FORMAT\_RGB\_565  
 &nbsp; &nbsp; &nbsp; &nbsp;HAL\_PIXEL\_FORMAT\_RGBA\_5551  
 &nbsp; &nbsp; &nbsp; &nbsp;HAL\_PIXEL\_FORMAT\_RGBA\_4444  
  
Maybe U can more… But this must work. I can’t say about any optimization…

---

<div class="post-metadata">

**Author:** ![baudouis](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@baudouis](https://forums.imgtec.com/u/baudouis)\
**Post date:** [March 21, 2012, 4:22pm UTC](https://forums.imgtec.com/t/is-fbo-with-eglimage-working-on-sgx540/1336/5 "2012-03-21T16:22:13Z")

</div>

I tried with&nbsp; HAL\_PIXEL\_FORMAT\_RGB\_888 and teh result is the same.  
I will try with HAL\_PIXEL\_FORMAT\_RGBA\_8888.  
  
Thanks for the idea  
Seb

---

<div class="post-metadata">

**Author:** ![JoeDavis](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.imgtec.com/joedavis/32/71_2.png) [@JoeDavis](https://forums.imgtec.com/u/JoeDavis)\
**Post date:** [April 10, 2012, 11:04am UTC](https://forums.imgtec.com/t/is-fbo-with-eglimage-working-on-sgx540/1336/6 "2012-04-10T11:04:24Z")

</div>

Hi Seb,  
  
Can you explain your use case? There are caveats when using EGLImage in this way, for example setting up a suitable synchronization framework to avoid tearing (if tearing is a concern). You should keep this in mind when deciding if using EGLImage is the best option for you.  
  
I've discussed this issue with our driver team. The driver is designed in such a way that drawing commands issued for FBOs will not be executed until that FBO is referenced by the main framebuffer's rendering. The idea behind this is to optimize out FBO rendering that doesn't affect the final image to avoid redundant rendering.   
  
I would suggest drawing an off-screen primitive that references the FBO (e.g. a triangle) into the main framebuffer to force the FBO to render, if you are not doing so already.  
  
Let me know if this does not resolve your problem.  
  
Thanks,  
Joe  
  
  
  
Joe2012-04-10 14:53:42

---

<div class="post-metadata">

**Author:** ![baudouis](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@baudouis](https://forums.imgtec.com/u/baudouis)\
**Post date:** [April 13, 2012, 12:47pm UTC](https://forums.imgtec.com/t/is-fbo-with-eglimage-working-on-sgx540/1336/7 "2012-04-13T12:47:33Z")

</div>

Hi Joe,  
  
As you advised, i added some code to use the FBO to draw a rectangle into a pBuffer Surface.  
But doing that didn’t change anything.  
  
Sometime i can see part of my texture rendered into the FBO but that part of texture is not rendered at the right place. Even if it is not working the part of texture that is rendered seems OK which make me think that RGB565 is working fine.  
  
As for texture that i bind to FBO i’m using a native\_buffer given thanks to EGLImage, is Imagination expecting some specific parameter when creating the native buffer ?  
  
Again the same code is working fine on LG2 Revolution&nbsp; using&nbsp; Adreno 200 or GalaxySII using MALI400-MP.  
  
Do you have any new idea to try ? i would expect that FBO is working fine.  
  
Thanks and Best Regards,  
  
Sebastien
