Hi,
I am attempting to get multisample framebuffer code happening.
Attached is a standalone function that attempts to generate and combine a multisample framebuffer with a multisample texture, clear the buffer, blit a bit to the default framebuffer, then read back some of the main framebuffer. However the data read back is all zero, while the clearing of the buffer used a non-zero color.
I would like to know why the data read back is not what the buffer was cleared with.
Thanks in advance,
Actually the file uploader refused to accept my code as valid, so here it is.
void verify_multisample_fbo(void)
{
int i,j;
GLuint multisample_texture;
GLuint multisample_fbo;
GLuint width = 1280;
GLuint height = 1020;
GLenum status;
GLenum err;
float array[4][4][4];
glViewport(0,0,1280,1020);
glGenTextures(1, &multisample_texture);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, multisample_texture);
glGenFramebuffers(1, &multisample_fbo);
glBindFramebuffer(GL_FRAMEBUFFER, multisample_fbo);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 16, GL_RGBA8, width, height, GL_TRUE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, multisample_texture, 0);
assert((err = glGetError()) == GL_NO_ERROR);
status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
assert(status == GL_FRAMEBUFFER_COMPLETE);
glClearColor(0.5, 0.6, 0.7, 0.8);
glClear(GL_COLOR_BUFFER_BIT);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindFramebuffer(GL_READ_FRAMEBUFFER, multisample_fbo);
glReadBuffer(GL_COLOR_ATTACHMENT0);
status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
assert(status == GL_FRAMEBUFFER_COMPLETE);
status = glCheckFramebufferStatus(GL_READ_FRAMEBUFFER);
assert(status == GL_FRAMEBUFFER_COMPLETE);
glBlitFramebuffer(0,0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glReadPixels(0,0,4,4, GL_RGBA, GL_FLOAT, array);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
assert((err = glGetError()) == GL_NO_ERROR);
for(i = 0; i < 4; i++)
{
for(j = 0; j < 4; j++)
{
printf("Pixel [%d,%d] = %4.3f %4.3f %4.3f %4.3f
", i, j,
array[i][j][0], array[i][j][1], array[i][j][2], array[i][j][3]);
}
}
exit(0);
}