in mujoco_py/gl/eglshim.c [231:288]
void copyFBOToPBO(mjrContext* con,
unsigned int pbo_rgb, unsigned int pbo_depth,
mjrRect viewport, int bufferOffset)
{
GLbitfield mask = (pbo_rgb ? GL_COLOR_BUFFER_BIT : 0) |
(pbo_depth ? GL_DEPTH_BUFFER_BIT : 0);
if (!mask)
return;
// multisample: blit to resolve buffer and read from there
if (con->offSamples)
{
// make sure blit is supported
if( !glBlitFramebuffer )
return;
// prepare for resolve-blit
glBindFramebuffer(GL_READ_FRAMEBUFFER, con->offFBO);
glReadBuffer(GL_COLOR_ATTACHMENT0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, con->offFBO_r);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
// resolve-blit
glBlitFramebuffer(viewport.left, viewport.bottom,
viewport.left + viewport.width, viewport.bottom + viewport.height,
viewport.left, viewport.bottom,
viewport.left + viewport.width, viewport.bottom + viewport.height,
mask, GL_NEAREST);
// read from resolved
glBindFramebuffer(GL_READ_FRAMEBUFFER, con->offFBO_r);
}
// no multisample: read from offscreen
else
glBindFramebuffer(GL_READ_FRAMEBUFFER, con->offFBO);
glReadBuffer(GL_COLOR_ATTACHMENT0);
if (pbo_rgb) {
glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, pbo_rgb);
glReadPixels(viewport.left, viewport.bottom, viewport.width, viewport.height,
GL_RGB, GL_UNSIGNED_BYTE,
bufferOffset * viewport.width * viewport.height * 3);
glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0);
}
if (pbo_depth) {
glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, pbo_depth);
glReadPixels(viewport.left, viewport.bottom, viewport.width, viewport.height,
GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT,
bufferOffset * viewport.width * viewport.height * sizeof(short));
glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0);
}
// restore currentBuffer
glBindFramebuffer(GL_FRAMEBUFFER, con->offFBO);
glReadBuffer(GL_COLOR_ATTACHMENT0);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
}