In my application I render to a texture attached to the framebuffer object. Then a framebuffer attachment is blitted to the screen. Here are relevant parts of the code:
//initialization
glGenFramebuffers(1, &fboId);
glBindFramebuffer(GL_FRAMEBUFFER, fboId);
glGenTextures(1, &fboTexId);
glBindTexture(GL_TEXTURE_2D, fboTexId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
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_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fboTexId, 0);
GLuint rboDepth;
glGenRenderbuffers(1, &rboDepth);
glBindRenderbuffer(GL_RENDERBUFFER, rboDepth);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, w, h);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboDepth);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE)
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
return false;
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
//render loop
glViewport(0, 0, w, h);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindFramebuffer(GL_FRAMEBUFFER, fboId);
glViewport(0, 0, w, h);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
render();
int sample_buffers = 0;
glGetFramebufferParameteriv(GL_FRAMEBUFFER, GL_SAMPLE_BUFFERS, &sample_buffers);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
sample_buffers = 0;
glGetFramebufferParameteriv(GL_FRAMEBUFFER, GL_SAMPLE_BUFFERS, &sample_buffers);
glBindFramebuffer(GL_READ_FRAMEBUFFER, fboId);
glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_LINEAR);
The above code works fine but when change a destination rectangle, for example:
glBlitFramebuffer(0, 0, w, h, 0, 0, w / 2, h / 2, GL_COLOR_BUFFER_BIT, GL_LINEAR);
I get OpenGL error 1282 - GL_INVALID_OPERATION. The message from the debug context looks like this:
Error has been generated. GL error GL_INVALID_OPERATION in BlitFramebuffer: (ID: 3482180659) Generic error
Documentation says:
GL_INVALID_OPERATION is generated if the value of GL_SAMPLE_BUFFERS for either read or draw buffers is greater than zero and the dimensions of the source and destination rectangles is not identical.
but sample buffers for the generated framebuffer and default framebuffer equals 0. Why do I get GL_INVALID_OPERATION ? Changing glBlitFramebuffer
filter to GL_NEAREST
doesn’t help.