9

Every time after I call glClear(GL_COLOR_BUFFER_BIT);, I get the OpenGL error "invalid framebuffer operation".

The call seems to work just fine, and nothing seems wrong. I call glClear(GL_COLOR_BUFFER_BIT); first thing in the ::paintGL() method.

Huh? Should I just disregard this error?

houbysoft
  • 32,532
  • 24
  • 103
  • 156
  • @cbamber85: no, but I've just put in a `glClearColor(0,0,0,0)` to see if it made any difference, and the other is still there. – houbysoft Jun 18 '12 at 19:33
  • Very possibly the error has been raised by a previous OpenGL call that the code didn't check. Verify that all OpenGL operations are guarded by error checking. – Stefan Hanke Jun 18 '12 at 20:21
  • @StefanHanke: the call to `glClear()` has error-checking code before and after. The error is not set directly before, and it is set directly after. Clearly it's the `glClear()` call that is the culprit. – houbysoft Jun 18 '12 at 20:27
  • Does the code use FBOs for some rendering? – Stefan Hanke Jun 18 '12 at 20:37
  • @StefanHanke: for now, no, it's just a simple program drawing some GL_QUADS. – houbysoft Jun 18 '12 at 20:49
  • What version of OpenGL are you using? – cmannett85 Jun 19 '12 at 06:32
  • @cbamber85: 1.7.7 (the default version bundled with Mac OS X Lion). – houbysoft Jun 25 '12 at 14:57
  • @houbysoft I don't know what that number is, but it can't be OpenGL. On Linux, you would type `glxinfo` and look at `OpenGL version string` - you'll have to search for MacOS equivalent. For example, my says: `4.2.0 NVIDIA 295.49`, which is the version number, vendor, and driver version. – cmannett85 Jun 25 '12 at 15:02
  • @cbamber85: I took that 1.7.7 from the bundle plist. Anyway, running `glxinfo | grep "OpenGL version string"` gives `2.1 APPLE-7.18.18`. – houbysoft Jun 25 '12 at 15:06
  • Could also be a driver bug: http://stackoverflow.com/questions/21241786/ – totaam Nov 16 '16 at 04:00

2 Answers2

5

My best guess is that your framebuffer is not complete and calling glClear on an incomplete framebuffer is throwing the error.

Check the status of the framebuffer using glCheckFramebufferStatus and make sure it returns GL_FRAMEBUFFER_COMPLETE.

James
  • 5,355
  • 2
  • 18
  • 30
  • I got the same error as the original poster, and I verified my framebuffers **are** complete. I'm running OpenGL-ES3 on iPhone and the texture which is being cleared is an sRGB-texture - when changing that to a normal "rgb"-texture, the "invalid framebuffer operation" error on glClear stops. From the info given by the OP I can't tell if this is the same in this case, but either way this may provide a hint to someone else running into this issue. – kalmiya Aug 15 '16 at 20:13
  • Update: in my case srgb8 isn't supported as "ColorRenderable" (using GL_SRGB8_ALPHA8 as an alternative works). As James said, glCheckFrameBufferStatus **should** have returned an error, but it doesn't, meaning there is a bug in the openGL implementation I'm using ( OpenGL-ES3 in xcode 7.3 on osx). – kalmiya Aug 16 '16 at 07:15
3

I was having this issue on osx using NSOpenGLView with a CVDisplayLink to trigger the render callback.

Be sure to wait for the NSOpenGLView to be fully displayed before starting rendering, i.e. :

-(void)viewDidAppear {
    [super viewDidAppear];

    CVDisplayLinkStart(_displayLink);
}

Doing it in viewDidLoad is too early.

ZpaceZombor
  • 877
  • 1
  • 10
  • 8