FBO with GL_TEXTURE_CUBE_MAP

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);
            
            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);
            }

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

Jack,

   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

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



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

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

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.