Best strategy for drawing multiple objects to FBO?

#1

Hi

I’m trying to draw a number of moving objects (>300) and show their trails. Every object is a combination of meshes.
I use an FBO and draw in it the objects sequentially from the map where they are stored. This is done in the general update method. The FBO is then drawn to screen in the general draw method.
Is this a good strategy for working with FBOs? Are there other approaches with better performance? WOuld it help if the FBO is a shared pointer passed to every instance so it draws itself to it?

Any tips for improving the performance with this would be appreciated.

VisualManager.cpp

void VisualManager::drawFbo(){
  rgbaFbo.begin();
    ofEnableAlphaBlending();
    for(auto pair:particleMap) {
      ofVec2f position = pair.second->getPosition();
      ofPushMatrix();
      ofTranslate(position.x, position.y);
      pair.second->draw();
      ofPopMatrix();
    }
    ofDisableBlendMode();

    ofEnableBlendMode(OF_BLENDMODE_ALPHA);
    ofFill();
    ofSetColor(0,0,0, fadeAmnt);
    ofDrawRectangle(0,0,ofGetWidth(),ofGetHeight());
    ofDisableBlendMode();
    ofDisableAlphaBlending();
  rgbaFbo.end();
}

void VisualManager::update(){
    for(auto pair:particleMap) {
      pair.second->update();
    }
    drawFbo();
}

void VisualManager::draw(){
  ofEnableBlendMode(OF_BLENDMODE_DISABLED);
  rgbaFbo.draw(0,0);
  ofDisableBlendMode();

}
1 Like
#2

Hi sgrinschpun,

I’m far from an OpenGL expert, but I can share what is coming to my mind:

  • I don’t think the performance issue is due to the use of a ofFbo
  • A general draw method seems ok to me
  • Have you dig into the OF/examples/gl directory ? Perhaps there are relevants examples, depending on the nature of your objects: billboardExample ? computeShaderParticlesExample ? gpuParticleSystemExample ? vboMeshDrawInstancedExample ? vboExample ?
  • A simple thing to try: use ofVboMesh instead of ofMesh (an introduction to this class here)
  • Try to mix all your objects into a single one, a ofVbo ? I had good results with this approach in the past.

Someone more experimented should confirm I’m not writing nonsenses :slight_smile:

#3

It seems correct to me. Which performance problem are you facing? what are you measuring?

Not related to performance, but I think you can change this:

void VisualManager::draw(){
  ofEnableBlendMode(OF_BLENDMODE_DISABLED);
  rgbaFbo.draw(0,0);
  ofDisableBlendMode();
}

Into this:

void VisualManager::draw(){
  rgbaFbo.draw(0,0);
}