FBO Creating: Why always incomplete read buffer?

The code come from Martin Eisemann’s sample project “Floating Texture”,
everyone can use it under GPL: sourceforge.net/projects/floatingtexture/

I got VS 2010 as my Compiler&Linker, the external libraries include GLEW GLUT and OpenCV

Here is the problem:

  1. There are 3 FBO to be created:


  mInputTexID = createFBOTexture(width, height);
  mInputFBO = createFBO(mInputTexID);

  mBGTexID = createFBOTexture(width, height);
  mBGRBID  = createFBORenderbuffer(width, height);
  mBGFBO   = createFBO(mBGTexID, mBGRBID);

  mVisTexID = createFBOTexture(mShadowRes, mShadowRes, GL_TEXTURE_2D, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT,    
                                             GL_FLOAT,  GL_LINEAR, GL_LINEAR, GL_CLAMP, GL_CLAMP);
  const GLenum attachment[] = {GL_DEPTH_ATTACHMENT_EXT};
  mVisFBO = createFBO(&mVisTexID, attachment, 1);


First two FBO work fine while the last one–mVisFBO can not be created, I get GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT when glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT) is called.

Here are the routines:



 GLuint createFBOTexture(const int width, const int height, 
			const GLenum target = GL_TEXTURE_2D, 
			const GLenum internalFormat = GL_RGBA16F_ARB,
			const GLenum format = GL_RGBA, 
			const GLenum type = GL_FLOAT, 
			const GLenum mag_filter = GL_LINEAR, 
			const GLenum min_filter = GL_LINEAR,
			const GLenum wrap_s = GL_CLAMP, 
			const GLenum wrap_t = GL_CLAMP)
{
  // generate texture id //
  GLuint texID;
  glGenTextures(1, &texID);

  // set parameters //
  glBindTexture(GL_TEXTURE_2D, texID);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t);

  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);

  glTexImage2D(target, 0, internalFormat, width, height, 0, format, type, 0);

  return texID;
}


GLuint createFBORenderbuffer(const int width, const int height, 
			     const GLenum internalFormat = GL_DEPTH_COMPONENT24)
{
  GLuint rbID;
  glGenRenderbuffersEXT(1, &rbID);
  glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rbID);
  glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, internalFormat, width, height);

  return rbID;
}

GLuint createFBO(const GLuint texID = 0, const GLuint renderbufferID = 0)
{
  const int    numTexs = (texID == 0) ? 0 : 1;  
  const GLenum texAttachments[] = {GL_COLOR_ATTACHMENT0_EXT};
  const GLenum attachment[] = {GL_DEPTH_ATTACHMENT_EXT};
  const int    numrb = (renderbufferID != 0) ? 1 : 0;
  const GLenum db[] = {GL_COLOR_ATTACHMENT0_EXT};

  return createFBO(&texID, texAttachments, numTexs, 
		   &renderbufferID, attachment, numrb,
		   db, numTexs);
}

GLuint createFBO(const GLuint texIDs[],
		 const GLenum texAttachments[],
		 const int numTexs, 
		 const GLuint rbIDs[] = NULL,
		 const GLenum rbAttachments[] = NULL,
		 const int numrb = 0,
		 const GLenum db[] = NULL,
		 const int numdb = 0)
{
  GLuint fboID = 0;

  // generate framebuffer //
  glGenFramebuffersEXT(1, &fboID);
  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboID);


  // attach texture to frambuffer //
    checkMaxDrawBuffers(numTexs);

    for(int i=0; i<numTexs; ++i){
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, 
			      texAttachments[i],
			      GL_TEXTURE_2D, texIDs[i], 0);
     }    

  // attach renderbuffer to framebuffer //
    for(int i=0; i<numrb; ++i){
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, rbAttachments[i], 
				 GL_RENDERBUFFER_EXT, rbIDs[i]);     
     } 

  // set drawbuffers //
  switch(numdb){
  case 0:
    glDrawBuffer(GL_NONE);
    break;
  case 1:
    glDrawBuffer(db[0]);
    break;
  default:
    glDrawBuffers(numdb, db);
    break;
  }

  // set parameters //
  glEnable(GL_DEPTH_TEST);
  glDepthFunc(GL_LEQUAL);

  // check for errors //
  GLenum status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);

  //Here  I got the Error :GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT

  return fboID;
}


Thanks for any tips&help!!!

Please don’t make your text this big!!! Just use the regular font size!!!

See? Isn’t that much better?

As for your question, you didn’t put a color image into the FBO. Your code explicitly checks this and correctly calls glDrawBuffer(GL_NONE). What you didn’t do is call glReadBuffer(GL_NONE), which is why you’re getting INCOMPLETE_READ_BUFFER.

With the exception of UNSUPPORTED, the incomplete messages are generally quite specific as to what has gone wrong.

Thanks for your help, Alfonse Reinheart! Both on the FBO and font size issues :slight_smile:

For anyone stuck in similiar problems :

I add glReadBuffer(GL_NONE) when there are no draw buffers



  // set drawbuffers //
  switch(numdb){
  case 0:
    glDrawBuffer(GL_NONE);
    glReadBuffer(GL_NONE);
    break;
  case 1:
    glDrawBuffer(db[0]);
    break;
  default:
    glDrawBuffers(numdb, db);
    break;
  }