# Problem optimizing dynamic reflections (Cube maps)

**URL:** <https://forums.imgtec.com/t/problem-optimizing-dynamic-reflections-cube-maps/1116>\
**Category:** PowerVR Insider\
**Created:** [June 27, 2011, 8:10pm UTC](https://forums.imgtec.com/t/problem-optimizing-dynamic-reflections-cube-maps/1116 "2011-06-27T20:10:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonkan](https://avatars.discourse-cdn.com/v4/letter/j/c77e96/32.png) [@jonkan](https://forums.imgtec.com/u/jonkan)\
**Post date:** [June 27, 2011, 8:10pm UTC](https://forums.imgtec.com/t/problem-optimizing-dynamic-reflections-cube-maps/1116/1 "2011-06-27T20:10:21Z")

</div>

Hello.  
  
  
I’m playing around with reflections on the iPhone 4 (OpenGL ES 2.0) and have just managed to achieve dynamic reflections via rendering to Cube Map (using FBO’s).  
  
  
  
  
  
I currently have 6 objects in my scene showing reflections of its 5 neighbors.  
  
  
Each object has its own cube map texture and as one can imagine this produces quite a workload.  
  
  
One trick to speed things up was simply **not** to update all the objects reflections every frame, instead I only update one cube map at the time (per frame).  
  
  
  
  
  
Rendering a frame looks somewhat like this:  
  
  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;Choose object to update  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;Bind object’s FBO  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;Loop all 6 cube map faces  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Transform the ModelViewMatrix  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Loop all 5 _otherObjects_  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Render _otherObject_  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End loop  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;End loop  
  
  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;Bind default FBO  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;Loop all 6 objects  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Bind CubeMapTexture  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Render object  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;End loop  
  
  
  
  
  
  
  
  
I do get the expected results, but I’m looking for ways to improve performance!!  
  
  
  
  
  
As I mentioned I’m only updating one cube map per frame, boosting fps pretty well.  
  
  
Also I’ve reduced the FBO cube map texture size (128x128 -\> 64x64, not much difference?).  
  
  
Supplying a low-poly version of each model for the rendering to the cube maps.  
  
  
Simplifying the shaders used for the objects when rendering to the cube maps.  
  
  
(the last two did not affect that much as I’d hoped, but still improvements).  
  
  
  
  
  
As of these changes I’ve upped the frame rate from about 13 to 40 fps, so still not quite happy…  
  
  
  
  
  
  
  
  
  
  
  
The most recent attempt of optimization (which I just cannot figure out) was to change the texture format of the FBO’s hoping to reduce some texture bandwidth.  
  
  
I’m trying to figure out how to use **GL\_UNSIGNED\_SHORT\_5\_6\_5** instead of **GL\_UNSIGNED\_BYTE** , but I’ve only managed to get it to work with the latter.  
  
  
  
  
  
I’ve google’d the sh\*t out of this but I struggle to find any clues…  
  
  
From what I can tell I should just be able to change my (currently working) line:  
  
  
  
  
  
GLenum textureTarget = GL\_TEXTURE\_CUBE\_MAP\_POSITIVE\_X + i;  
  
  
glTexImage2D(textureTarget, 0, GL\_RGBA, texSize, texSize, 0, GL\_RGBA, GL\_UNSIGNED\_BYTE, 0);  
  
  
  
  
  
to:  
  
  
  
  
  
glTexImage2D(textureTarget, 0, GL\_RGB, texSize, texSize, 0, GL\_RGB, GL\_UNSIGNED\_SHORT\_5\_6\_5, 0);  
  
  
  
  
  
But that just gives me “GL\_FRAMEBUFFER\_UNSUPPORTED” when checking FBO status, surely I’m missing something…??  
  
  
  
  
  
I’ve looked at the OGLES2RenderToTexture sample in the Training Course, which uses the same line (exept the texture target, GL\_TEXTURE\_2D instead) and runs just fine…?  
  
  
Other than the texture target in that line I cannot find any differences in how things are setup… (apart form the fact that I have multiple FBO’s and so on).  
  
  
  
  
  
Anyone with a clue?  
  
  
  
  
  
Also, any other tips related to this topic would be greatly appreciated!!  
  
  
I’m still a newbie on this stuff, so I may or may not know what I’m talking about… :)🙂  
  
  
  
  
  
  
  
  
Regards Jonas  
  
  
  
  
  
jonkan2011-09-15 21:52:06

---

<div class="post-metadata">

**Author:** ![jonkan](https://avatars.discourse-cdn.com/v4/letter/j/c77e96/32.png) [@jonkan](https://forums.imgtec.com/u/jonkan)\
**Post date:** [September 15, 2011, 7:50pm UTC](https://forums.imgtec.com/t/problem-optimizing-dynamic-reflections-cube-maps/1116/2 "2011-09-15T19:50:38Z")

</div>

I’ve been at it again and I’m still trying to solve the problem why the texture format UNSIGNED\_SHORT\_5\_6\_5 doesn’t work…  
  
  
I thought I could add some things.  
  
  
  
  
  
GLenum textureTarget = GL\_TEXTURE\_CUBE\_MAP\_POSITIVE\_X + i;  
  
  
glTexImage2D(textureTarget, 0, GL\_RGB, texSize, texSize, 0, GL\_RGB, GL\_UNSIGNED\_SHORT\_5\_6\_5, 0);  
  
  
glFramebufferTexture2D(GL\_FRAMEBUFFER, GL\_COLOR\_ATTACHMENT0, textureTarget, cubeMapTexID[i], 0);  
  
  
  
  
  
If I do a glGetError() I don’t get any error, however as I mentioned before from glCheckFramebufferStatus(GL\_FRAMEBUFFER) I get GL\_FRAMEBUFFER\_UNSUPPORTED.  
  
  
  
  
  
Is it simply not possible to render to a cube map texture with this format??  
  
  
  
  
  
//Jonasjonkan2011-09-15 23:06:22
