FBO and Shadow Mapping Depth Texture

I am confused. I am trying to use a FBO with Shadow Mapping.

If I use a renderbuffer for my depth storage, e.g.
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT32, maxTexSize, maxTexSize);

then how do I read it from a glsl shader for the comparison? glReadPixels into a texture? glCopyTexImage2D?

On the other hand, it appears I can simply attach a depth texture directly, e.g.
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
GL_DEPTH_ATTACHMENT_EXT,
GL_TEXTURE_2D, depth_tex, 0);

and then bind it and use it in glsl. This sounds better - it is example 7 in the spec.

Is this a better approach? Why would one ever use a renderbuffer for shadow mapping?

Thanks for any insight

Why would one ever use a renderbuffer for shadow mapping?
You wouldn’t.

The purpose of a renderbuffer is to provide storage space for framebuffer data that you won’t need to use later. For example, if you’re mirrors with Render To Texture, you need a depth buffer. But you only need it for rendering purposes; you don’t need to keep it around. The color buffer is of course a texture, but the depth buffer can be a renderbuffer. And a shared one for mirrors, if you are so inclined.

So if you’re rendering to something that you won’t use as anything but framebuffer data, use a renderbuffer. If you will need to access that data later as a texture, use a texture.

Thanks Korval,

Now I understand