flush method

void flush()

Sort and execute all deferred draws (back-to-front for alpha blending).

Implementation

void flush() {
  for (var i = 1; i < _drawCount; i++) {
    final entry = _drawPool[i];
    var j = i - 1;
    while (j >= 0 && _drawPool[j].distance < entry.distance) {
      _drawPool[j + 1] = _drawPool[j];
      j--;
    }
    _drawPool[j + 1] = entry;
  }

  // Draw and then release the objects in the draw pool.
  for (var i = 0; i < _drawCount; i++) {
    _drawPool[i].object!.draw(this);
    _drawPool[i].object = null;
  }
  _lastDrawCount = _drawCount;
  _drawCount = 0;
}