# FBO with GL\_TEXTURE\_CUBE\_MAP

**URL:** <https://forums.imgtec.com/t/fbo-with-gl-texture-cube-map/1388>\
**Category:** PowerVR Insider\
**Created:** [April 18, 2012, 5:04am UTC](https://forums.imgtec.com/t/fbo-with-gl-texture-cube-map/1388 "2012-04-18T05:04:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackasser](https://avatars.discourse-cdn.com/v4/letter/j/5fc32e/32.png) [@jackasser](https://forums.imgtec.com/u/jackasser)\
**Post date:** [April 18, 2012, 5:04am UTC](https://forums.imgtec.com/t/fbo-with-gl-texture-cube-map/1388/1 "2012-04-18T05:04:13Z")

</div>

Is it possible to create a depth component only FBO targeting a GL\_TEXTURE\_CUBE\_MAP. What I want to do is to extend my spot light shadow mapper into an omni directional shadow mapper by attaching a cube texture to the FBO instead.  
  
  
  
  
  
I’m fully aware that I would need to render the scene in 6 passes, one for each side of the cube face since GLES 2 do not have geometry shaders, but that’s ok. There’s still a big win for only one texture unit (samplerCube) when doing the shadow depth tests, instead of 6 different samplers and choosing cube face manually.  
  
  
  
  
  
I can’t get this to work unfortunately. I get incomplete attachment all the time.

Code:

  
glGenTextures(1, &depthTexture);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GLenum target = cubic?GL\_TEXTURE\_CUBE\_MAP:GL\_TEXTURE\_2D;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glBindTexture(target, depthTexture);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glTexParameteri(target, GL\_TEXTURE\_WRAP\_S, GL\_CLAMP\_TO\_EDGE);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glTexParameteri(target, GL\_TEXTURE\_WRAP\_T, GL\_CLAMP\_TO\_EDGE);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glTexParameteri(target, GL\_TEXTURE\_MAG\_FILTER, GL\_NEAREST);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glTexParameteri(target, GL\_TEXTURE\_MIN\_FILTER, GL\_NEAREST);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!cubic)  
&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; glTexImage2D(GL\_TEXTURE\_2D, 0, GL\_DEPTH\_COMPONENT, width, height, 0, GL\_DEPTH\_COMPONENT, depthType, NULL);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glFramebufferTexture2D(GL\_FRAMEBUFFER, GL\_DEPTH\_ATTACHMENT, GL\_TEXTURE\_2D, depthTexture, 0);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
&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; for (int i=0; i\<6; i++)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glTexImage2D(GL\_TEXTURE\_CUBE\_MAP\_POSITIVE\_X+i, 0, GL\_DEPTH\_COMPONENT, width, height, 0, GL\_DEPTH\_COMPONENT, depthType, NULL);  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glFramebufferTexture2D(GL\_FRAMEBUFFER, GL\_DEPTH\_ATTACHMENT, GL\_TEXTURE\_CUBE\_MAP\_POSITIVE\_X, depthTexture, 0);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

---

<div class="post-metadata">

**Author:** ![jackasser](https://avatars.discourse-cdn.com/v4/letter/j/5fc32e/32.png) [@jackasser](https://forums.imgtec.com/u/jackasser)\
**Post date:** [April 20, 2012, 10:34am UTC](https://forums.imgtec.com/t/fbo-with-gl-texture-cube-map/1388/2 "2012-04-20T10:34:29Z")

</div>

Still haven’t been able to get this working… ☹ Maybe it’s impossible to render to a cube depth map in GLES2?

---

<div class="post-metadata">

**Author:** ![claymontgomery](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.imgtec.com/claymontgomery/32/132_2.png) [@claymontgomery](https://forums.imgtec.com/u/claymontgomery)\
**Post date:** [April 20, 2012, 9:42pm UTC](https://forums.imgtec.com/t/fbo-with-gl-texture-cube-map/1388/3 "2012-04-20T21:42:12Z")

</div>

Jack,  
  
&nbsp;&nbsp; I wrote a wiki article some time ago about using FBOs with the PowerVR OpenGL ES drivers that might help:  
  
[http://processors.wiki.ti.com/index.php/Render\_to\_Texture\_with\_OpenGL\_ES](http://processors.wiki.ti.com/index.php/Render_to_Texture_with_OpenGL_ES)  
  
Capturing the depth image into a texture requires the  
  
OES\_depth\_texture extension which was only available beginning with the PowerVR OpenGL ES drivers build from their  
  
1.4 DDK.  
Check if the driver you are using has this extension declared.  
  
Regards, Clay

---

<div class="post-metadata">

**Author:** ![jackasser](https://avatars.discourse-cdn.com/v4/letter/j/5fc32e/32.png) [@jackasser](https://forums.imgtec.com/u/jackasser)\
**Post date:** [April 22, 2012, 10:55am UTC](https://forums.imgtec.com/t/fbo-with-gl-texture-cube-map/1388/4 "2012-04-22T10:55:30Z")

</div>

I can already capture the depth to a texture2d but not to a texturecubemap target. Is that possible?

---

<div class="post-metadata">

**Author:** ![bobgardner](https://avatars.discourse-cdn.com/v4/letter/b/ea5d25/32.png) [@bobgardner](https://forums.imgtec.com/u/bobgardner)\
**Post date:** [April 23, 2012, 8:15am UTC](https://forums.imgtec.com/t/fbo-with-gl-texture-cube-map/1388/5 "2012-04-23T08:15:22Z")

</div>

Hi JackAsser,  
  
  
  
  
  
Sadly, what your attempting to do is not supported by the current specification for OpenGL ES. If your using GL\_DEPTH\_COMPONENT then your only option is GL\_TEXTURE\_2D.  
  
  
  
  
  
Apologies,  
  
  
BobBobGardner2012-04-23 11:37:14

---

<div class="post-metadata">

**Author:** ![jackasser](https://avatars.discourse-cdn.com/v4/letter/j/5fc32e/32.png) [@jackasser](https://forums.imgtec.com/u/jackasser)\
**Post date:** [April 23, 2012, 4:13pm UTC](https://forums.imgtec.com/t/fbo-with-gl-texture-cube-map/1388/6 "2012-04-23T16:13:43Z")

</div>

Yeps, so I assumed by now. I’m using an alternative path where I render the depth values into the color channels instead. For 16-bit float precision I choose the OES\_HALF\_FLOAT format for that. This way I can reuse the cube map for up to 4 light sources at the same time, each using one channel at 16-bit float precision.
