Reading data using glReadPixel() with multisampling

后端 未结 1 1549
暗喜
暗喜 2021-01-06 06:05

Presently I am trying to read the pixel data from the frame Buffer in order to capture the screen in IOS. GlreadPixels command works fine when using the following code to se

相关标签:
1条回答
  • 2021-01-06 06:33

    When using multisampled FBOs you cannot just read the sample buffer (as it doesn't contain simple pixels). You first need to resolve the sample buffers into a single buffer.

    You do this by creating another non-multisampled FBO (let's call it resultFramebuffer) with the neccessary renderbuffer storage you want to read and then calling:

    glBindFramebuffer(GL_READ_FRAMEBUFFER, sampleFramebuffer);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resultFramebuffer);
    glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
    

    And then you read from the result buffer (of course the actual constant and function names may contain OES or APPLE). If you don't need the final depth values, the result buffer doesn't need a depth renderbuffer.

    EDIT: As you wrote in your comment and what I searched, there is a dedicated function glResolveMultisampleFramebufferAPPLE you have to use instead of glBlitFramebuffer. The rest stays the same.

    0 讨论(0)
提交回复
热议问题