Invalid framebuffer operation after glCheckFramebufferStatus

断了今生、忘了曾经 提交于 2020-04-11 18:05:32

问题


I am getting a weird OpenGL error when running my application on my HD4000 (Windows 64bit, driver version 15.28.20.64.3347).

I boiled it down to a few OpenGL calls to reproduce it:

  1. Create two framebuffer objects.
  2. Create a texture and bind it as GL_COLOR_ATTACHMENT0 to both FBOs.
  3. Call glTexImage2D a second time on the texture
  4. Bind the first FBO and call glCheckFramebufferStatus (returns GL_FRAMEBUFFER_COMPLETE).
  5. Bind the second FBO and call glClear. The glClear gives an GL_INVALID_FRAMEBUFFER_OPERATION.

Step 3 and 4 are required to reproduce the error, which I find especially disturbing for the glCheckFramebufferStatus call. The problem also does not occur on other graphics cards (including the Nvidia card on the same machine).

If you call glCheckFramebufferStatus on the second FBO, it also returns GL_FRAMEBUFFER_COMPLETE. However, when inspecting the internal OpenGL state with apitrace, it says that the second FBO has now a color attachment with object name zero.

Re-binding the texture to the second FBO after the glCheckFramebufferStatus call resolves the error. This is working as a workaround for now, but I suppose that binding textures to various FBOs each frame is not a good idea.

Here is the C++ code that reproduces the error:

// Create a texture and bind it to two FBOs
GLuint textureName;
glGenTextures(1, &textureName); 
glBindTexture(GL_TEXTURE_RECTANGLE, textureName); 
glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 

GLuint fboNames[2];
glGenFramebuffers(2, fboNames); 
glBindFramebuffer(GL_FRAMEBUFFER, fboNames[0]); 
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, textureName, 0); 

glBindFramebuffer(GL_FRAMEBUFFER, fboNames[1]);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, textureName, 0);

glBindTexture(GL_TEXTURE_RECTANGLE, textureName); 
glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 

glBindFramebuffer(GL_FRAMEBUFFER, fboNames[0]); 

// Removing this line resolves the error
glCheckFramebufferStatus(GL_FRAMEBUFFER); // Returns GL_FRAMEBUFFER_COMPLETE

glBindFramebuffer(GL_FRAMEBUFFER, fboNames[1]);
GLenum bufferTarget = GL_COLOR_ATTACHMENT0;
glDrawBuffers(1, &bufferTarget);

// Adding this line resolves the error 
// glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_RECTANGLE, 1, 0); 

glCheckFramebufferStatus(GL_FRAMEBUFFER); // Returns GL_FRAMEBUFFER_COMPLETE

//This call causes a GL_INVALID_FRAMEBUFFER_OPERATION error.
glClear(GL_COLOR_BUFFER_BIT);

Here is a minimal Visual Studio 2013 Project to reproduce it: https://www.dropbox.com/s/5142j26d839gkp9/HD4000Error.zip

Now, my question is: Am I doing something illegal with OpenGL here or is this simply a driver bug?


回答1:


We reported this issue to Intel and it seems that it was in fact a bug. It is fixed in the current driver version.



来源:https://stackoverflow.com/questions/21241786/invalid-framebuffer-operation-after-glcheckframebufferstatus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!