# Shadowmapping on iphone 3GS ?

**URL:** <https://forums.imgtec.com/t/shadowmapping-on-iphone-3gs/493>\
**Category:** PowerVR Insider\
**Created:** [September 29, 2009, 11:56pm UTC](https://forums.imgtec.com/t/shadowmapping-on-iphone-3gs/493 "2009-09-29T23:56:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicolasbol](https://avatars.discourse-cdn.com/v4/letter/n/ad7895/32.png) [@nicolasbol](https://forums.imgtec.com/u/nicolasbol)\
**Post date:** [September 29, 2009, 11:56pm UTC](https://forums.imgtec.com/t/shadowmapping-on-iphone-3gs/493/1 "2009-09-29T23:56:04Z")

</div>

Hi guys,  
  
  
  
  
  
I’ve having the hardest time porting my shadow map tutorial to iPhone: The framebuffer creation fails whatever I tried so far:  
  
  
  
  
  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GLenum status;  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glGenFramebuffers(1, &shadowFBOId);  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glBindFramebuffer(GL\_FRAMEBUFFER,shadowFBOId);  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
  
  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glGenTextures(1, &colorTextureId);  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glBindTexture(GL\_TEXTURE\_2D, colorTextureId);  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glTexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_WRAP\_S, GL\_CLAMP\_TO\_EDGE);  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glTexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_WRAP\_T, GL\_CLAMP\_TO\_EDGE);  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glTexParameterf(GL\_TEXTURE\_2D, GL\_TEXTURE\_MAG\_FILTER, GL\_NEAREST);  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glTexParameterf(GL\_TEXTURE\_2D, GL\_TEXTURE\_MIN\_FILTER, GL\_NEAREST);  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glTexImage2D(GL\_TEXTURE\_2D, 0, GL\_RGBA, renderWidth, renderHeight, 0, GL\_RGBA, GL\_UNSIGNED\_BYTE, NULL);  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glFramebufferTexture2D(GL\_FRAMEBUFFER, GL\_COLOR\_ATTACHMENT0,GL\_TEXTURE\_2D, colorTextureId, 0);  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
  
  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glGenTextures(1, &shadowMapTextureId);  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glBindTexture(GL\_TEXTURE\_2D, shadowMapTextureId);  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glTexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_WRAP\_S, GL\_CLAMP\_TO\_EDGE);  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glTexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_WRAP\_T, GL\_CLAMP\_TO\_EDGE);  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glTexParameterf(GL\_TEXTURE\_2D, GL\_TEXTURE\_MAG\_FILTER, GL\_NEAREST);  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glTexParameterf(GL\_TEXTURE\_2D, GL\_TEXTURE\_MIN\_FILTER, GL\_NEAREST);  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glTexImage2D( GL\_TEXTURE\_2D, 0, GL\_DEPTH\_COMPONENT, renderWidth, renderHeight, 0, GL\_DEPTH\_COMPONENT16, GL\_UNSIGNED\_SHORT, NULL);  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;glFramebufferTexture2D(GL\_FRAMEBUFFER,GL\_DEPTH\_ATTACHMENT,GL\_TEXTURE\_2D,shadowMapTextureId,0 );  
  
  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status = glCheckFramebufferStatus(GL\_FRAMEBUFFER);  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
  
  
  
  
  
I’ve tried to use a renderBuffer for the depth attachment and it is working fine:  
  
  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GLuint depthRenderbuffer;  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glGenRenderbuffers(1, &depthRenderbuffer);  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glBindRenderbuffer(GL\_RENDERBUFFER, depthRenderbuffer);  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glRenderbufferStorage(GL\_RENDERBUFFER, GL\_DEPTH\_COMPONENT16, renderWidth, renderHeight);  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glFramebufferRenderbuffer(GL\_FRAMEBUFFER, GL\_DEPTH\_ATTACHMENT, GL\_RENDERBUFFER, depthRenderbuffer);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
  
  
  
  
  
  
  
  
So I think there is an issue in my glTexImage2D for the depth buffer.  
  
  
  
  
  
Anyone has a clue ?

---

<div class="post-metadata">

**Author:** ![nicolasbol](https://avatars.discourse-cdn.com/v4/letter/n/ad7895/32.png) [@nicolasbol](https://forums.imgtec.com/u/nicolasbol)\
**Post date:** [September 29, 2009, 11:58pm UTC](https://forums.imgtec.com/t/shadowmapping-on-iphone-3gs/493/2 "2009-09-29T23:58:54Z")

</div>

By the way, the error I get in status is GL\_FRAMEBUFFER\_INCOMPLETE\_ATTACHMENT

---

<div class="post-metadata">

**Author:** ![nicolasbol](https://avatars.discourse-cdn.com/v4/letter/n/ad7895/32.png) [@nicolasbol](https://forums.imgtec.com/u/nicolasbol)\
**Post date:** [September 30, 2009, 4:49am UTC](https://forums.imgtec.com/t/shadowmapping-on-iphone-3gs/493/3 "2009-09-30T04:49:28Z")

</div>

Just checked out the SDK 2.5, iphone version doesn’t have the training course 29: ShadowMapping ☹ !  
  
  
  
  
  
Any plan to update it ?

---

<div class="post-metadata">

**Author:** ![xmas](https://avatars.discourse-cdn.com/v4/letter/x/958977/32.png) [@xmas](https://forums.imgtec.com/u/xmas)\
**Post date:** [September 30, 2009, 12:10pm UTC](https://forums.imgtec.com/t/shadowmapping-on-iphone-3gs/493/4 "2009-09-30T12:10:59Z")

</div>

Depth textures are an extension (GL\_OES\_depth\_texture) to OpenGL ES 2.0 and are currently not supported on the iPhone. Always check the extension string before using non-core functionality.  
  
  
  
  
  
You could try other shadow map approaches (object ID, encode depth to RGBA texture), though. Xmas2009-09-30 14:16:26

---

<div class="post-metadata">

**Author:** ![nicolasbol](https://avatars.discourse-cdn.com/v4/letter/n/ad7895/32.png) [@nicolasbol](https://forums.imgtec.com/u/nicolasbol)\
**Post date:** [October 4, 2009, 6:20am UTC](https://forums.imgtec.com/t/shadowmapping-on-iphone-3gs/493/5 "2009-10-04T06:20:28Z")

</div>

Thanks XMas.  
  
  
  
  
  
I’m packing the depth value in a RGBA (32bits) texture for now and I’m pretty happy with the result (only that I am still looking for an artist so I won’t have to borrow John C’s georgous Hellknight):  
  
  
  
  
  
 ![](http://fabiensanglard.net/dEngine/shadowMapping.png)  
  
  
  
  
  
I don’t think I need so much precision (plus I’m starting to consum a lot of bandwidth) so I’m now trying to render to a 16 bits texture:GL\_RGBA4 or GL\_RGB565 none of them are working, I am not sure where to look to check if they are supported.nicolasbol2009-10-04 08:31:07

---

<div class="post-metadata">

**Author:** ![xmas](https://avatars.discourse-cdn.com/v4/letter/x/958977/32.png) [@xmas](https://forums.imgtec.com/u/xmas)\
**Post date:** [October 5, 2009, 7:18am UTC](https://forums.imgtec.com/t/shadowmapping-on-iphone-3gs/493/6 "2009-10-05T07:18:31Z")

</div>

The sized formats GL\_RGBA4 and GL\_RGB565 are for renderbuffer creation, not for textures. OpenGL ES does not support sized internal texture formats. If you want to use 16-bit textures, just use GL\_UNSIGNED\_SHORT\_5\_6\_5 or GL\_UNSIGNED\_SHORT\_4\_4\_4\_4 as type argument to glTexImage2D.  
  
  
  
  
  
Both RGBA4444 and RGB565 textures should be supported as rendertargets.
