FBO with depth texture only

Hi all!

Currently I am using FBOs for shadow mapping. I ported the code from my C++/OpenGL program to Java/JOGL and unfortunately the code does not work properly.

Here is my code to generate the FBO and depth texture:

                
gl.glGenFramebuffersEXT(1, fboHandleBuffer, 0);
m_DepthRendererObj = fboHandleBuffer[0];
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, m_DepthRendererObj);

final int[] shadow=new int[1];
gl.glGenTextures(1, shadow, 0);
m_ShadowDepthTexture=shadow[0];
gl.glBindTexture(GL.GL_TEXTURE_2D,m_ShadowDepthTexture);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST );
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST );
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_COMPARE_FUNC, GL.GL_LEQUAL);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_COMPARE_MODE, GL.GL_COMPARE_R_TO_TEXTURE);
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_DEPTH_COMPONENT16,  depth_size, depth_size, 0, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, null);
gl.glDrawBuffer(GL.GL_NONE);
gl.glReadBuffer(GL.GL_NONE);
gl.glFramebufferTexture2DEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_DEPTH_ATTACHMENT_EXT, GL.GL_TEXTURE_2D, m_ShadowDepthTexture, 0);

First of all it is not possible to generate a texture with mag and min filtering set to linear and attach it to a FBO. I tried it with several color textures and it always throws an exception in the glFramebufferTexture2DEXT-line. If I set the min and mag filtering to nearest it works. Linear filtering should work in general and it works fine with C++ and OpenGL.

So if I use the depth texture with nearest filtering it can be created, but it never writes anything to it. I initialised it the same way as I do in my other programs - but it does not work. I read back the pixels from the texture and they are all set to 1.
If I disable the FBO and depth render to the normal render buffer I can read the pixels back and they hold different values - the way it should be.

To make a long story short:

  1. Is there any known bug with JOGL concerning linear filtered textures attached to FBOs? I haven’t found any info on the web.
  2. Do I have to call the functions in a different order to make it work?
  3. Has anyone tried rendering to depth textures through an FBO with JOGL?
    3a) and if - what do I have to change to make it work?

Thanks!
Dee

I’ve never had trouble with linear mapping and fbos (although I didn’t try it for a depth texture). What exception was thrown we you tried? I do find it odd that if fails, but my only suggestion would be to try not having the depth texture bound at the same time the fbo is bound. You shouldn’t have them bound when rendering to the fbo, so maybe the drivers don’t like having the texture bound while attaching it, too?

This is just a guess; I always find it odd that JOGL behaves differently than C++ and OpenGL, it’s just wrapping the opengl calls so perhaps someone could enlighten me as to how jogl screws up?

It doesn’t. Most of the time the problem is due to a user code error or a missing rewind() call on a buffer.

Unbinding the texture before binding it to the FBO did the trick!
It is quite fascinating because I can use linear filtered textures as well now…
Never had the problem with C…

Well, thanks a lot !!!

Cheers
Dee