diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/GPUInstancer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/GPUInstancer.java new file mode 100644 index 000000000..51ce4d700 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/GPUInstancer.java @@ -0,0 +1,325 @@ +package com.jozufozu.flywheel.backend.instancing; + +import java.util.ArrayList; +import java.util.BitSet; + +import com.jozufozu.flywheel.backend.Backend; +import com.jozufozu.flywheel.backend.gl.GlVertexArray; +import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; +import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer; +import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType; +import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer; +import com.jozufozu.flywheel.backend.model.ModelAllocator; +import com.jozufozu.flywheel.backend.model.IBufferedModel; +import com.jozufozu.flywheel.core.model.IModel; +import com.jozufozu.flywheel.util.AttribUtil; + +/** + * An instancer is how you interact with an instanced model. + *
+ * Instanced models can have many copies, and on most systems it's very fast to draw all of the copies at once. + * There is no limit to how many copies an instanced model can have. + * Each copy is represented by an InstanceData object. + *
+ *+ * When you call {@link #createInstance()} you are given an InstanceData object that you can manipulate however + * you want. The changes you make to the InstanceData object are automatically made visible, and persistent. + * Changing the position of your InstanceData object every frame means that that copy of the model will be in a + * different position in the world each frame. Setting the position of your InstanceData once and not touching it + * again means that your model will be in the same position in the world every frame. This persistence is useful + * because it means the properties of your model don't have to be re-evaluated every frame. + *
+ * + * @param- * Instanced models can have many copies, and on most systems it's very fast to draw all of the copies at once. - * There is no limit to how many copies an instanced model can have. - * Each copy is represented by an InstanceData object. - *
- *- * When you call {@link #createInstance()} you are given an InstanceData object that you can manipulate however - * you want. The changes you make to the InstanceData object are automatically made visible, and persistent. - * Changing the position of your InstanceData object every frame means that that copy of the model will be in a - * different position in the world each frame. Setting the position of your InstanceData once and not touching it - * again means that your model will be in the same position in the world every frame. This persistence is useful - * because it means the properties of your model don't have to be re-evaluated every frame. - *
- * - * @param implements MaterialGroup
private final ArrayList owner, IRenderState state) {
this.owner = owner;
@@ -38,8 +38,8 @@ public class MaterialGroupImpl implements MaterialGroup
*/
@SuppressWarnings("unchecked")
@Override
- public implements MaterialGroup
}
public void clear() {
- materials.values().forEach(InstanceMaterialImpl::clear);
+ materials.values().forEach(MaterialImpl::clear);
}
public void delete() {
materials.values()
- .forEach(InstanceMaterialImpl::delete);
+ .forEach(MaterialImpl::delete);
materials.clear();
renderers.clear();
}
- private InstanceMaterialImpl> createInstanceMaterial(MaterialSpec> type) {
- InstanceMaterialImpl> material = new InstanceMaterialImpl<>(type);
+ private MaterialImpl> createInstanceMaterial(MaterialSpec> type) {
+ MaterialImpl> material = new MaterialImpl<>(type);
this.renderers.add(new MaterialRenderer<>(owner.getProgram(type.getProgramName()), material, this::setup));
diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/InstanceMaterialImpl.java b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialImpl.java
similarity index 77%
rename from src/main/java/com/jozufozu/flywheel/backend/material/InstanceMaterialImpl.java
rename to src/main/java/com/jozufozu/flywheel/backend/material/MaterialImpl.java
index 7f91c98e9..ad0bb535c 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/material/InstanceMaterialImpl.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialImpl.java
@@ -6,6 +6,7 @@ import java.util.function.Supplier;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.jozufozu.flywheel.backend.RenderWork;
+import com.jozufozu.flywheel.backend.instancing.GPUInstancer;
import com.jozufozu.flywheel.backend.instancing.InstanceData;
import com.jozufozu.flywheel.backend.instancing.Instancer;
import com.jozufozu.flywheel.backend.model.ModelPool;
@@ -15,19 +16,19 @@ import com.jozufozu.flywheel.core.model.IModel;
* A collection of Instancers that all have the same format.
* @param