ofFbo readToPixels with selected region?

This is mainly a follow up to my last query but I thought it worth a new topic heading as the subject has shifted slightly.

Using ofFbo, is there a workaround to either:

ofFbo.readToPixels(pixels) <<but only take a selected block of pixels, say, top right quarter, from the ofFbo object?

or:

ofFbo.getColor(p.x,p.y) <<where p.x, p.y specify a coordinate within the ofFbo? (ie NOT doing the readToPixels step)

A way of doing either of the above would be handy to me, does anyone know?

Thanks
Sam

(n.b. I’m also assuming I cannot ‘reallocate’ an ofFbo object once it is created, is this the case? I seem to get a crash when I run ofFbo.allocate(blockwidth,blockheight…) and vary blockwidth,blockheight between loops)

you should be able to reallocate an fbo, if it crashes it’s probably a bug. can you post an issue in github: https://github.com/openframeworks/openFrameworks/issues

about getting only a region of an fbo, you can’t do it as it is now but it would be easy to implement. if you look in the implementation of ofFbo readPixels in desktop does:

  
  
    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.getPixels());  
	unbind();  
  

so it would be relatively simple to modify that method to add some parameters for x,y,w,h or a rectangle to grab only part of the fbo

heh yeah, I don’t know why I didn’t look in the implementation.
Dropping in a start x,y and end x,y seems to work.

  
void ofFbo::readToPixels(ofPixels & pixels, int startgrabX, int startgrabY, int endgrabX, int endgrabY, int attachmentPoint){  
#ifndef TARGET_OPENGLES  
	getTextureReference(attachmentPoint).readToPixels(pixels);  
#else  
	bind();  
	int format,type;  
    int grabwidth, grabheight;  
	ofGetGlFormatAndType(settings.internalformat,format,type);  
    if(endgrabX==0) endgrabX = settings.width;  
    if(endgrabY==0) endgrabY = settings.height;  
	glReadPixels(startgrabX,startgrabY,endgrabX,endgrabY, format, GL_UNSIGNED_BYTE, pixels.getPixels());  
	unbind();  
#endif  
}