public BufferRegion next() {

        dirtyRegion.bo = bufferObject;
        dirtyRegion.regions.clear();

        if (bufferObject.regions.size() == 0) {
            if (!bufferObject.isUpdateNeeded()) return null;
            dirtyRegion.fullBufferRegion = true;
            dirtyRegion.end = bufferObject.getData().limit();
            dirtyRegion.start = 0;
            return dirtyRegion;
        }


        while (pos < bufferObject.regions.size()) {
            BufferRegion dr = bufferObject.regions.get(pos++);
            if (dr.isDirty()) {
                if (dirtyRegion.regions.size() == 0) dirtyRegion.start = dr.start;
                dirtyRegion.end = dr.end;
                dirtyRegion.regions.add(dr);
            } else if (dirtyRegion.regions.size() != 0) break;
        }

        if (dirtyRegion.regions.size() == 0) return null;
        dirtyRegion.fullBufferRegion = dirtyRegion.regions.size() == bufferObject.regions.size();
        dirtyRegion.markDirty();

        return dirtyRegion;
    }
An helper class that iterates and merges dirty regions

@author Riccardo Balbo
jme3-core/src/main/java/com/jme3/shader/bufferobject/DirtyRegionsIterator.java