GlReadPixels () sets the GL_INVALID_OPERATION flag for no reason

I am trying to implement color matching using FBO. I have a multisampled FBO (fbo [0]), which I use to render the scene, and I have a non-multisampled FBO (fbo [1]), which I use to select a color.

The problem is that when I try to read pixel data from fbo [1], everything goes well until glReadPixels calls the GL_INVALID_OPERATION flag. I checked the manual and cannot find the reason.

Code for creating FBO:

glBindRenderbuffer(GL_RENDERBUFFER, rbo[0]); glRenderbufferStorageMultisample(GL_RENDERBUFFER, numSamples, GL_RGBA8, resolution[0], resolution[1]); glBindRenderbuffer(GL_RENDERBUFFER, rbo[1]); glRenderbufferStorageMultisample(GL_RENDERBUFFER, numSamples, GL_DEPTH24_STENCIL8, resolution[0], resolution[1]); glBindRenderbuffer(GL_RENDERBUFFER, rbo[2]); glRenderbufferStorage(GL_RENDERBUFFER, GL_R32UI, resolution[0], resolution[1]); glBindRenderbuffer(GL_RENDERBUFFER, rbo[3]); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, resolution[0], resolution[1]); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo[1]); glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo[3]); glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo[2]); OGLChecker::checkFBO(GL_DRAW_FRAMEBUFFER); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo[0]); glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo[1]); glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo[0]); OGLChecker::checkFBO(GL_DRAW_FRAMEBUFFER); 

My control panel remains silent, so the FBOs are complete. Then select code

 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo[1]); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // bla, bla, bla // do the rendering unsigned int result; glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo[1]); int sb; glReadBuffer(GL_COLOR_ATTACHMENT0); glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); glGetIntegerv(GL_SAMPLE_BUFFERS, &sb); // glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); OGLChecker::getGlError(); std::cerr << "Sample buffers " << sb << std::endl; glReadPixels(pos.x(), resolution.y() - pos.y(), 1, 1, GL_RED, GL_UNSIGNED_INT, &result); OGLChecker::getGlError(); return result; 

conclusion:

 Sample buffers 0 OpenGL Error : Invalid Operation 

Interesting fact: if I uncomment glBindFramebuffer (GL_READ_FRAMEBUFFER, 0); then an error does not occur, and the pixels are read from the screen (but I do not need it).

What could be wrong here?

+6
source share
2 answers

Given that it is “fixed” if you uncomment this line of code, I wonder if your driver is set to 0 in GL_SAMPLE_BUFFERS. From http://www.opengl.org/sdk/docs/man/xhtml/glReadPixels. xml :

 GL_INVALID_OPERATION is generated if GL_READ_FRAMEBUFFER_BINDING is non-zero, the read framebuffer is complete, and the value of GL_SAMPLE_BUFFERS for the read framebuffer is greater than zero. 
0
source

If you use the NVIDIA binary driver on Linux and switch to a non-graphical virtual console (e.g. CTRL + ALT + F1 ), any attempt to glReadPixels() will return GL_INVALID_OPERATION (0x502).

Decision. Return to the graphical console (usually CTRL + ALT + F7 ).

0
source

All Articles