geometrian
geometrian

Reputation: 15387

glBlitFramebuffer causing Access Violation

I'm trying to copy from a FBO to the window's framebuffer. As far as I know, the window framebuffer has 8 bits for each of R, G, B, and A, and has a depthbuffer (probably 24 bits). The FBO has a single texture attachment (format RGBA8) and no renderbuffers.

The problem is that when I try to blit the FBO to the screen, I get an access violation (Windows term for SIGSEGV). Blit code:

//Earlier: const int screen_rect[4] = {0,0,512,512};

glBindFramebuffer(GL_READ_FRAMEBUFFER,fbo->framebuffer);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER,               0);
glFinish();
//checking GL errors here gives no error
glBlitFramebuffer(
    screen_rect[0],screen_rect[1],screen_rect[2],screen_rect[3],
    screen_rect[0],screen_rect[1],screen_rect[2],screen_rect[3],
    GL_COLOR_BUFFER_BIT,
    GL_NEAREST //EDIT: I've also tried GL_LINEAR
);
glFinish();
//never reaches here
glBindFramebuffer(GL_DRAW_FRAMEBUFFER,0);
glBindFramebuffer(GL_READ_FRAMEBUFFER,0);

The FBO is GL_FRAMEBUFFER_COMPLETE_EXT and no GL errors occur at any point. The FBO and the window framebuffer are the same size.

Running on NVIDIA GeForce 580M GTX with driver 301.42 (to date, latest).

Any ideas why this might be happening?

[EDIT: I have found that the problem does not occur when blitting from a FBO to another FBO, although no data seems to be copied]

Upvotes: 2

Views: 1185

Answers (1)

geometrian
geometrian

Reputation: 15387

It seems that this implementation is EXTREMELY picky about the order commands go in. I figured out the following after reverse engineering some existing code. Perhaps there's some arcane reason they must be in this order, but I don't know what.

In any case, I believe the segfaulting behavior to be a bug in NVIDIA's OpenGL implementation.

Without further ado, the key commands, in order:

GLenum buffers1[] = {GL_BACK};
glBindFramebuffer(GL_DRAW_FRAMEBUFFER,0);
glDrawBuffers(1,buffers1);

glBindFramebuffer(GL_READ_FRAMEBUFFER,fbo->framebuffer);
glReadBuffer(GL_COLOR_ATTACHMENT1);

glBlitFramebuffer(...)

Upvotes: 2

Related Questions