How to read Pixel data from the MultiSampled framebuffer?

Hey
Presently i am working on iphone app that includes OpenGl es 1.X and trying to read the pixel data from the frame Buffer in order to capture the screen in IOS. GlreadPixels command work fine when using the following code to setup frame buffer :-

//buffers
// Create a depth buffer that has the same size as the color buffer.
glGenRenderbuffersOES(1, &m_depthRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_depthRenderbuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT24_OES, width, height);

// Create the framebuffer object.

glGenFramebuffersOES(1, &framebuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebuffer);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES,
                             GL_RENDERBUFFER_OES, m_colorRenderbuffer);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES,
                             GL_RENDERBUFFER_OES, m_depthRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_colorRenderbuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebuffer);

but when i use depth buffer and colorbuffer for Multi-Sampling glreadpixels() dont capture any pixel data as with earlier code …for multi-sampling i use following code :-

glGenFramebuffersOES(1, &sampleFramebuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, sampleFramebuffer);

//GLuint sampleColorRenderbuffer;
glGenRenderbuffersOES(1, &sampleColorRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, sampleColorRenderbuffer);
glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER_OES, 4, GL_RGBA8_OES, width, height);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, sampleColorRenderbuffer);

//glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER_OES, 4, GL_RGBA8_OES, width, height);
//glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, sampleColorRenderbuffer);

GLuint sampleDepthRenderbuffer;
glGenRenderbuffersOES(1, &sampleDepthRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, sampleDepthRenderbuffer);
glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER_OES, 4, GL_DEPTH_COMPONENT24_OES, width, height);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, sampleDepthRenderbuffer);
//glBindRenderbufferOES(GL_RENDERBUFFER_OES,sampleColorRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_colorRenderbuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, sampleFramebuffer);

i use the follwing code to read pixel data :-

CGRect screenBounds = [[UIScreen mainScreen] bounds];

int backingWidth = screenBounds.size.width;
int backingHeight =screenBounds.size.height;

glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
NSInteger myDataLength = backingWidth * backingHeight * 4;

buffer= (GLuint *) malloc(myDataLength);
glReadPixels(0, 0, backingWidth, backingHeight, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

Any idea how to capture correct pixel data with multi-Sampling technique…or Am i doing something wrong. Please guide me in right direction. Thanks

You cannot read pixel data from a multisampled framebuffer, you need to blit it to a single-sampled framebuffer first.

Thanks for Replying…hmm k following blitting code is right or wrong ?

glBindFramebufferOES(GL_READ_FRAMEBUFFER_APPLE, sampleFramebuffer);
	glBindFramebufferOES(GL_DRAW_FRAMEBUFFER_APPLE, framebuffer);
	glResolveMultisampleFramebufferAPPLE();

Hey all done… got another issue regarding the performance while using glReadpixels() for reading the frame buffer …the performance decreases unexpectedly… without using glReadPixels() the FPS is around 30 and with glreadPixels the fps is 2-3 . is it normal or m lacking something ?

Using glReadPixels is always expensive, how expensive depends on the platform. But most platforms need to stall rendering and wait for rendering to finish, with a possible resolve to another buffer, then an un-cached buffer generally needs to be read then the format needs to be converted. You should avoid glReadPixels at all cost for anything that you want to perform well. If you really need to use it, you might be able try various pixel format combinations, you can also try reading the target at the latest possible point in your frame.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.