PBO* GLResource::getPBO( int size ) { int i; int supindex = -1, infindex = -1; int supdelta = 0, infdelta = 0; /*int total = 0; for ( i = 0; i < pboList.count(); ++i ) total += pboList.at(i)->size(); qDebug() << "Total PBO bytes :" << total << pboList.count();*/ for ( i = 0; i < pboList.count(); ++i ) { PBO *p = pboList.at(i); if ( p->isFree() ) { if ( p->size() == size ) { p->setFree( false ); return p; } if ( p->size() > size ) { int d = p->size() - size; if ( supindex == -1 || d < supdelta ) { supdelta = d; supindex = i; } } else { int d = size - p->size(); if ( infindex == -1 || d < infdelta ) { infdelta = d; infindex = i; } } } } if ( supindex != -1 ) { PBO *p = pboList.at( supindex ); p->setFree( false ); return p; } if ( infindex != -1 ) { PBO *p = pboList.at( infindex ); if ( !p->resize( size ) ) { qDebug() << "pbo resize error"; return NULL; } p->setFree( false ); return p; } PBO *p = new PBO( size ); if ( !p->isValid() ) { delete p; qDebug() << "new pbo error"; return NULL; } pboList.append( p ); p->setFree( false ); return p; }