mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-27 23:47:09 +01:00
No need for getDirtyBitSet
- Faster and simpler to just do one loop
This commit is contained in:
parent
ffe17e4449
commit
a43fe2bc9a
2 changed files with 11 additions and 35 deletions
|
@ -70,19 +70,6 @@ public abstract class AbstractInstancer<D extends InstanceData> implements Insta
|
|||
return getModelVertexCount() * numInstances();
|
||||
}
|
||||
|
||||
protected BitSet getDirtyBitSet() {
|
||||
final int size = data.size();
|
||||
final BitSet dirtySet = new BitSet(size);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
D element = data.get(i);
|
||||
if (element.checkDirtyAndClear()) {
|
||||
dirtySet.set(i);
|
||||
}
|
||||
}
|
||||
return dirtySet;
|
||||
}
|
||||
|
||||
protected void removeDeletedInstances() {
|
||||
// Figure out which elements are to be removed.
|
||||
final int oldSize = this.data.size();
|
||||
|
|
|
@ -150,31 +150,20 @@ public class GPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
|
|||
|
||||
if (size <= 0) return;
|
||||
|
||||
final int stride = instanceFormat.getStride();
|
||||
final BitSet dirtySet = getDirtyBitSet();
|
||||
try (MappedBuffer mapped = instanceVBO.getBuffer(0, glBufferSize)) {
|
||||
|
||||
if (dirtySet.isEmpty()) return;
|
||||
final StructWriter<D> writer = type.asInstanced()
|
||||
.getWriter(mapped);
|
||||
|
||||
final int firstDirty = dirtySet.nextSetBit(0);
|
||||
final int lastDirty = dirtySet.previousSetBit(size);
|
||||
|
||||
final int offset = firstDirty * stride;
|
||||
final int length = (1 + lastDirty - firstDirty) * stride;
|
||||
|
||||
if (length > 0) {
|
||||
try (MappedBuffer mapped = instanceVBO.getBuffer(offset, length)) {
|
||||
|
||||
StructWriter<D> writer = type.asInstanced()
|
||||
.getWriter(mapped);
|
||||
|
||||
dirtySet.stream()
|
||||
.forEach(i -> {
|
||||
writer.seek(i);
|
||||
writer.write(data.get(i));
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Flywheel.log.error("Error updating GPUInstancer:", e);
|
||||
for (int i = 0; i < size; i++) {
|
||||
final D element = data.get(i);
|
||||
if (element.checkDirtyAndClear()) {
|
||||
writer.seek(i);
|
||||
writer.write(element);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Flywheel.log.error("Error updating GPUInstancer:", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue