Hi guys,
I’ve having the hardest time porting my shadow map tutorial to iPhone: The framebuffer creation fails whatever I tried so far:
GLenum status;
glGenFramebuffers(1, &shadowFBOId);
glBindFramebuffer(GL_FRAMEBUFFER,shadowFBOId);
glGenTextures(1, &colorTextureId);
glBindTexture(GL_TEXTURE_2D, colorTextureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, renderWidth, renderHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D, colorTextureId, 0);
glGenTextures(1, &shadowMapTextureId);
glBindTexture(GL_TEXTURE_2D, shadowMapTextureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, renderWidth, renderHeight, 0, GL_DEPTH_COMPONENT16, GL_UNSIGNED_SHORT, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,shadowMapTextureId,0 );
status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
I’ve tried to use a renderBuffer for the depth attachment and it is working fine:
GLuint depthRenderbuffer;
glGenRenderbuffers(1, &depthRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, renderWidth, renderHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer);
So I think there is an issue in my glTexImage2D for the depth buffer.
Anyone has a clue ?
By the way, the error I get in status is GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
Just checked out the SDK 2.5, iphone version doesn’t have the training course 29: ShadowMapping !
Any plan to update it ?
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
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):
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
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.