mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-28 16:06:28 +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();
|
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() {
|
protected void removeDeletedInstances() {
|
||||||
// Figure out which elements are to be removed.
|
// Figure out which elements are to be removed.
|
||||||
final int oldSize = this.data.size();
|
final int oldSize = this.data.size();
|
||||||
|
|
|
@ -150,31 +150,20 @@ public class GPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
|
||||||
|
|
||||||
if (size <= 0) return;
|
if (size <= 0) return;
|
||||||
|
|
||||||
final int stride = instanceFormat.getStride();
|
try (MappedBuffer mapped = instanceVBO.getBuffer(0, glBufferSize)) {
|
||||||
final BitSet dirtySet = getDirtyBitSet();
|
|
||||||
|
|
||||||
if (dirtySet.isEmpty()) return;
|
final StructWriter<D> writer = type.asInstanced()
|
||||||
|
.getWriter(mapped);
|
||||||
|
|
||||||
final int firstDirty = dirtySet.nextSetBit(0);
|
for (int i = 0; i < size; i++) {
|
||||||
final int lastDirty = dirtySet.previousSetBit(size);
|
final D element = data.get(i);
|
||||||
|
if (element.checkDirtyAndClear()) {
|
||||||
final int offset = firstDirty * stride;
|
writer.seek(i);
|
||||||
final int length = (1 + lastDirty - firstDirty) * stride;
|
writer.write(element);
|
||||||
|
}
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Flywheel.log.error("Error updating GPUInstancer:", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue