PDA

View Full Version : Depth Only FrameBuffer?



Sanctus
10-31-2009, 09:29 AM
Hye guys.
I'd like to have only a depth buffer on a framebuffer.
I have the code like this


glGenFramebuffersEXT(1, &this->bufferID);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, this->bufferID);
glGenTextures(1, &this->depth);
glBindTexture(GL_TEXTURE_2D, this->depth);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, Width, Height, 0,GL_DEPTH_COMPONENT, GL_FLOAT, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,GL_TEXTURE_2D,this->depth, 0);
CheckBufferStatus(this->bufferID);
glGenerateMipmapEXT(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,0);


CheckBufferStatus gives me this:
[ERROR] Unsupported by FBO implementation.

I'm trying to implement shadow maps in a deferred engine and thus I need to render the depth for the light matrixes to this depth buffer.
Anyone has any idea as to why this doesn't work?

Dave Driesen
10-31-2009, 10:06 AM
I am absolutely positive that using GL_LINEAR_MIPMAP_LINEAR on GL_TEXTURE_MAG_FILTER breaks shadow map FBO's on my development machines. Tested again to be sure. For this reason, I am using:



glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);


Don't know if this is your problem or if there's a way around it but it might be worth a shot using GL_LINEAR to see what it gives you.

Alfonse Reinheart
10-31-2009, 10:55 AM
I am absolutely positive that using GL_LINEAR_MIPMAP_LINEAR on GL_TEXTURE_MAG_FILTER breaks shadow map FBO's on my development machines.

Technically, it shouldn't work at all. There are 2 accepted values for TEXTURE_MAG_FILTER: GL_LINEAR and GL_NEAREST. Mip-map filtering is what you do in minification settings, not magnification.

Sanctus
10-31-2009, 11:11 AM
I modified that.
Now the error only was only shown when before this line
glGenerateMipmapEXT(GL_TEXTURE_2D);
after that the buffer is ok. I didn't modify the matrixes at all just to test if the depth buffer works.
It does not. I have the depth from my regular buffer shown quite well and a bit lower the depth map only buffer which shows nothing (white).
I do draw the scene 2 times a frame(second time with no shader. Give the fact that the vert shader usually does nothing it should work the same).
To set my buffer I used this:


glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, buffer->bufferID);
int type =0;
GLenum buffers[4];
int c=0;
if(buffer->color)
{
buffers[c] = GL_COLOR_ATTACHMENT0_EXT;
c++;
}
if(buffer->normal)
{
buffers[c] = GL_COLOR_ATTACHMENT0_EXT+1;
c++;
}
if(buffer->specular)
{
buffers[c] = GL_COLOR_ATTACHMENT0_EXT+2;
c++;
}
//if(c)
glDrawBuffers(c,buffers);
Could anyone help me further please?
Thanks

Alfonse Reinheart
10-31-2009, 12:06 PM
Why are you trying to generate mipmaps for a texture that has undefined data? Remember, you didn't upload any data to that texture. You shouldn't be calling glGenerateMipmap() unless you have actually put some data in the buffer.

And why are you trying to mipmap a depth buffer to begin with?


(second time with no shader. Give the fact that the vert shader usually does nothing it should work the same).

Did you ask for invariance between shader and non-shader in your vertex shader that "does nothing"? If not, then you aren't guaranteed to get it.

Dave Driesen
10-31-2009, 12:38 PM
When it comes to depth buffers, white isn't necessarily bad (pardon my optimistic reasoning). Try rendering a polygon into the camera or something and see if the resulting depth buffer is still all white? This should give you really low values which will become black upon visualisation as they approach the near plane. Depth value precision isn't a linear thing and often, the geometry being drawn is too far away from the camera to show as anything but white and your depth buffer will seem to "not work" when in fact it's ok in itself.

V-man
11-01-2009, 09:42 PM
Why are you trying to generate mipmaps for a texture that has undefined data? Remember, you didn't upload any data to that texture. You shouldn't be calling glGenerateMipmap() unless you have actually put some data in the buffer.


glGenerateMipmap() is just used to allocate the mipmaps in this case. The same can be achieved with all the calls to glTexImage2D for each mipmap allocation.

DmitryM
11-02-2009, 04:39 AM
I don't get it. Does driver remember there was no data upload?
If it doesn't, then it has to generate mipmaps.

arekkusu
11-02-2009, 07:44 AM
No it doesn't. It will happily sample undefined garbage in the mipmaps.

If you don't want to allocate or use mipmaps, turn them off:
glTexParameteri(..., GL_TEXTURE_MIN_FILTER, GL_LINEAR);

Mipmaps don't make a lot of sense for shadow maps. What does it mean to average two depth values?

DmitryM
11-02-2009, 08:18 AM
No it doesn't. It will happily sample undefined garbage in the mipmaps.

So the call to glGenerateMipmaps is not correct in the code provided.



Mipmaps don't make a lot of sense for shadow maps. What does it mean to average two depth values?

It really makes sense in case of exponential shadow maps (ESM) :)

V-man
11-03-2009, 07:26 AM
So the call to glGenerateMipmaps is not correct in the code provided.


Careful. It is called glGenerateMipmap.
There is nothing wrong with it. Have a look at GL_EXT_framebuffer_object at http://www.opengl.org/registry

one of the examples is doing exactly that.