-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
was looking at integrating ofxFastFboReader approach into ofFbo but after doing some benchmarking I found a faster approach with what we have already.
- on desktop the current read back for ofFbo uses ofTexture::readToPixels and gives:
approx 30fps for a 4096x4096 GL_RGB FBO with 0 samples
//----------------------------------------------------------
void ofFbo::readToPixels(ofPixels & pixels, int attachmentPoint){
if(!bIsAllocated) return;
#ifndef TARGET_OPENGLES
getTexture(attachmentPoint).readToPixels(pixels); <-- desktop is currently using this approach
#else
- with ofxFastFboReader addon which has always seemed the fastest approach:
approx 33fps for a 4096x4096 GL_RGB FBO with 0 samples
However while trying some different approaches I found that
- using the code that OPENGLES uses in OF
approx 40fps for a 4096x4096 GL_RGB FBO with 0 samples <-- winner by 10fps
//----------------------------------------------------------
void ofFbo::readToPixels(ofPixels & pixels, int attachmentPoint){
if(!bIsAllocated) return;
//#ifndef TARGET_OPENGLES
// getTexture(attachmentPoint).readToPixels(pixels);
//#else
//this code is faster on desktop than above, but it doesn't support multisampling
pixels.allocate(settings.width,settings.height,ofGetImageTypeFromGLType(settings.internalformat));
bind();
int format = ofGetGLFormatFromInternal(settings.internalformat);
glReadPixels(0,0,settings.width, settings.height, format, GL_UNSIGNED_BYTE, pixels.getData());
unbind();
//#endif
}
When we do multisampling the OPENGLES code stops working.
It can be fixed by blitting and is still faster than the current approach by 5fps.
But the added complexity may not be worth it.
Here is the multisample friendly version:
//----------------------------------------------------------
void ofFbo::readToPixels(ofPixels & pixels, int attachmentPoint){
if(!bIsAllocated) return;
//#ifndef TARGET_OPENGLES
// getTexture(attachmentPoint).readToPixels(pixels);
//#else
if(settings.numSamples > 0){
//we need a non multisample fbo to blit the multisamped fbo to.
if( !nonMultiSampleFbo ){
nonMultiSampleFbo = std::make_shared<ofFbo>();
nonMultiSampleFbo->allocate(settings.width,settings.height,settings.internalformat,0);
}
//blit the multisample fbo to non multisample fbo
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, fbo);
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, nonMultiSampleFbo->getId());
glBlitFramebufferEXT(0, 0, settings.width,settings.height, 0, 0, settings.width,settings.height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
//do the normal appproach for reading fbo to pixels with the non multisample one
pixels.allocate(settings.width,settings.height,ofGetImageTypeFromGLType(settings.internalformat));
nonMultiSampleFbo->bind();
int format = ofGetGLFormatFromInternal(settings.internalformat);
glReadPixels(0,0,settings.width, settings.height, format, GL_UNSIGNED_BYTE, pixels.getData());
nonMultiSampleFbo->unbind();
}else{
pixels.allocate(settings.width,settings.height,ofGetImageTypeFromGLType(settings.internalformat));
bind();
int format = ofGetGLFormatFromInternal(settings.internalformat);
glReadPixels(0,0,settings.width, settings.height, format, GL_UNSIGNED_BYTE, pixels.getData());
unbind();
}
//#endif
}
Proposal: I am thinking to use the current approach for multisample and the TARGET_OPENGLES
approach when numSamples = 0. That way we use the existing code but get a 10fps boost for non multisampled FBO capture.
However if we do implement the above approach we would get multisample read back working on iOS / Android when I think it is currently broken.
Thoughts?