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.
glGenTextures(1, &depthTexture);
GLenum target = cubic?GL_TEXTURE_CUBE_MAP:GL_TEXTURE_2D;
glBindTexture(target, depthTexture);
glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
if (!cubic)
{
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, depthType, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0);
}
else
{
for (int i=0; i<6; i++)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, depthType, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X, depthTexture, 0);
}