partial FBO drawing?

Hi

My app window is large: 1000 x 1000.

I’m using an FBO (obtained from SiW in http://forum.openframeworks.cc/t/ofx-061-gt;-iphone-3.2:-need-fbos-solved/4372/7), the associated texture’s contents of which are expected to change at every frame. The changes are much smaller in bounds than the bounds of the texture; they usually range from 10x10 to 100x100.

My problem is that my app’s frame rate sucks because calling myFBO->draw(0, 0, ofGetScreenWidth(), ofGetScreenHeight()) at every App::draw() is costly.

What would be the best strategy for drawing variable sub-bounds of an FBO’s texture to the screen?

Thanks in advance
Alex

Are you sure it’s the draw() that’s slowing everything down? draw() should be fast. I’d guess it’s actually the drawing into the FBO that’s slow.

That said, you can draw a sub-region of a texture by manually using glTexCoord2f and glVertex2f, drawing a rectangle that is the size of the screen/drawing area and setting the glTexCoords to the sub region you want to look at.

Thanks Kyle.

Are you sure it’s the draw() that’s slowing everything down? draw() should be fast. I’d guess it’s actually the drawing into the FBO that’s slow.

I just ran some tests and, even without modifying the contents of my fbo, fboP->draw(0, 0, w, h) reduces my app’s frame rate (linearly), i.e., for a requested frame rate of 60 – ofSetFrameRate(60):

  
App::draw()  
{  
	// BG => osfGetFrameRate() => 60  
  
	ofBackground(50, 100, 200);  
}  
  
App::draw()  
{  
	// BG + blend FBO once => osfGetFrameRate() => 24  
  
	ofBackground(50, 100, 200);  
  
	ofEnableAlphaBlending();  
	glBlendFunc(GL_SRC_ALPHA, GL_SRC_COLOR);  
	fboP->draw(0, 0, screenWidth, screenHeight);  
	ofDisableAlphaBlending();  
}  
  
App::draw()  
{  
	// BG + blend FBO twice => osfGetFrameRate() => 12  
  
	ofBackground(50, 100, 200);  
  
	ofEnableAlphaBlending();  
	glBlendFunc(GL_SRC_ALPHA, GL_SRC_COLOR);  
	fboP->draw(0, 0, screenWidth, screenHeight);  
	fboP->draw(0, 0, screenWidth, screenHeight);  
	ofDisableAlphaBlending();  
}  

Last, just for the hell of it, I ran a blend-less speed test; now, I get 30 fps w. 1 fbo->draw() call:

  
App::draw()  
{  
	// BG + draw FBO once => osfGetFrameRate() => 30  
  
	ofBackground(50, 100, 200);  
	fboP->draw(0, 0, screenWidth, screenHeight);  
}  
  

So as you can see, the cost of blending is less than the cost of drawing, and as I plan to layer up to 5 fbos, I’m definitely in need of some optimization such as sub-draw.

And I now turn to your last paragraph:

That said, you can draw a sub-region of a texture by manually using glTexCoord2f and glVertex2f, drawing a rectangle that is the size of the screen/drawing area and setting the glTexCoords to the sub region you want to look at.

I need to wrap my head around this for a while but that looks like the clue I was looking for. Thanks a lot.

Alex