PDA

View Full Version : Depth only FBO, incomplete draw buffer



rwahn
08-02-2011, 03:25 PM
I'm trying to setup a FBO with only a depth texture attached but I always end up with GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER from glCheckFramebufferStatus. As far as I understand the fbo arb extension it should be alright having only a depth attachment if gldrawbuffer is set to none. I'm probably missing something very simple but i don't see it. If I attach a colorbuffer everything works as expected. Here's the code:


glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);

unsigned int texID;
unsigned int fboID;
int depthBufferDim = 128;
glGenFramebuffers(1, &fboID);
glBindFramebuffer(GL_FRAMEBUFFER, fboID);

glGenTextures(1, &texID);
glBindTexture(GL_TEXTURE_2D, texID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, depthBufferDim, depthBufferDim, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture(GL_TEXTURE_2D, 0);

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texID, 0);

GLuint st = glCheckFramebufferStatus(GL_FRAMEBUFFER);
switch(st){
case GL_FRAMEBUFFER_COMPLETE:
std::cout << "GL_FRAMEBUFFER_COMPLETE" <<std::endl;
break;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
std::cout << "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT" <<std::endl;
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT :
std::cout << "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT" <<std::endl;
break;
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
std::cout << "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER" <<std::endl;
break;
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
std::cout << "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER" <<std::endl;
break;
case GL_FRAMEBUFFER_UNSUPPORTED:
std::cout << "GL_FRAMEBUFFER_UNSUPPORTED" <<std::endl;
break;
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
std::cout << "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE" <<std::endl;
break;
case GL_FRAMEBUFFER_UNDEFINED :
std::cout << "GL_FRAMEBUFFER_UNDEFINED" <<std::endl;
break;
}


I'm using latest AMD drivers, I have that issue on Windows and Linux. Can't test it on another video card.

kowal
08-02-2011, 04:40 PM
From wiki:
http://www.opengl.org/wiki/GL_EXT_framebuffer_object

Depth only FBO initialization code is pretty much the same as Yours, but there is additional call:

glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);

Code from wiki worked for me (NVIDIA GF9800GT 275.21 Linux)

arekkusu
08-02-2011, 08:47 PM
glDrawBuffer/glReadBuffer affect *the currently bound draw framebuffer*.

So call them after binding the FBO you want to modify.

rwahn
08-02-2011, 09:05 PM
Thank you! That wiki entry is great.
It wasn't the missing tex paramater but I missed out the fact that the drawbuffer state is saved per framebuffer. So moving glDrawBuffer(GL_NONE) and glReadBuffer(GL_NONE) behind the bindFramebuffer call did the trick.