mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-30 06:44:58 +01:00
Merge remote-tracking branch 'origin/1.19/dev' into 1.19/fabric/dev
This commit is contained in:
commit
c4b7e869bb
12 changed files with 38 additions and 13 deletions
|
@ -19,6 +19,7 @@ public interface Material<D extends InstanceData> {
|
||||||
*
|
*
|
||||||
* @param key An object that uniquely identifies the model.
|
* @param key An object that uniquely identifies the model.
|
||||||
* @param modelSupplier A factory that creates the Model that you want to render.
|
* @param modelSupplier A factory that creates the Model that you want to render.
|
||||||
|
* <b>Each time {@link Supplier#get()} is called, a new Model must be created.</b>
|
||||||
* @return An instancer for the given model, capable of rendering many copies for little cost.
|
* @return An instancer for the given model, capable of rendering many copies for little cost.
|
||||||
*/
|
*/
|
||||||
Instancer<D> model(Object key, Supplier<Model> modelSupplier);
|
Instancer<D> model(Object key, Supplier<Model> modelSupplier);
|
||||||
|
|
|
@ -42,4 +42,9 @@ public class BatchedMaterial<D extends InstanceData> implements Material<D> {
|
||||||
models.values()
|
models.values()
|
||||||
.forEach(CPUInstancer::clear);
|
.forEach(CPUInstancer::clear);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void delete() {
|
||||||
|
models.values().forEach(CPUInstancer::delete);
|
||||||
|
models.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,9 @@ public class BatchedMaterialGroup implements MaterialGroup {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() {
|
public void delete() {
|
||||||
|
materials.values()
|
||||||
|
.forEach(BatchedMaterial::delete);
|
||||||
|
|
||||||
materials.clear();
|
materials.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,11 +64,13 @@ public class BatchingEngine implements Engine {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete() {
|
public void delete() {
|
||||||
|
for (Map<RenderType, BatchedMaterialGroup> groups : layers.values()) {
|
||||||
|
groups.values().forEach(BatchedMaterialGroup::delete);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beginFrame(Camera info) {
|
public void beginFrame(Camera info) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -73,4 +73,8 @@ public class CPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
|
||||||
public void notifyDirty() {
|
public void notifyDirty() {
|
||||||
// noop
|
// noop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void delete() {
|
||||||
|
modelData.delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,6 +104,8 @@ public class GPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
|
||||||
|
|
||||||
instanceVBO.delete();
|
instanceVBO.delete();
|
||||||
vao.delete();
|
vao.delete();
|
||||||
|
|
||||||
|
modelData.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void renderSetup() {
|
protected void renderSetup() {
|
||||||
|
|
|
@ -43,6 +43,10 @@ public class InstancedMaterial<D extends InstanceData> implements Material<D> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<GPUInstancer<D>> getAllInstancers() {
|
||||||
|
return models.values();
|
||||||
|
}
|
||||||
|
|
||||||
public int getInstanceCount() {
|
public int getInstanceCount() {
|
||||||
return models.values().stream().mapToInt(GPUInstancer::getInstanceCount).sum();
|
return models.values().stream().mapToInt(GPUInstancer::getInstanceCount).sum();
|
||||||
}
|
}
|
||||||
|
@ -57,11 +61,6 @@ public class InstancedMaterial<D extends InstanceData> implements Material<D> {
|
||||||
.allMatch(GPUInstancer::isEmpty);
|
.allMatch(GPUInstancer::isEmpty);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() {
|
|
||||||
models.values().forEach(GPUInstancer::delete);
|
|
||||||
models.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear all instance data without freeing resources.
|
* Clear all instance data without freeing resources.
|
||||||
*/
|
*/
|
||||||
|
@ -70,7 +69,8 @@ public class InstancedMaterial<D extends InstanceData> implements Material<D> {
|
||||||
.forEach(GPUInstancer::clear);
|
.forEach(GPUInstancer::clear);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<GPUInstancer<D>> getAllInstancers() {
|
public void delete() {
|
||||||
return models.values();
|
models.values().forEach(GPUInstancer::delete);
|
||||||
|
models.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,7 @@ public class InstancedMaterialGroup<P extends WorldProgram> implements MaterialG
|
||||||
if (material.nothingToRender()) continue;
|
if (material.nothingToRender()) continue;
|
||||||
|
|
||||||
P program = owner.context.getProgram(ProgramContext.create(entry.getKey()
|
P program = owner.context.getProgram(ProgramContext.create(entry.getKey()
|
||||||
.getProgramSpec(), Formats.POS_TEX_NORMAL, layer));
|
.getProgramSpec(), Formats.BLOCK, layer));
|
||||||
|
|
||||||
// XXX Shader is bound and not reset or restored
|
// XXX Shader is bound and not reset or restored
|
||||||
program.bind();
|
program.bind();
|
||||||
|
@ -155,7 +155,7 @@ public class InstancedMaterialGroup<P extends WorldProgram> implements MaterialG
|
||||||
.onAMDWindows()) {
|
.onAMDWindows()) {
|
||||||
return FallbackAllocator.INSTANCE;
|
return FallbackAllocator.INSTANCE;
|
||||||
} else {
|
} else {
|
||||||
return new ModelPool(Formats.POS_TEX_NORMAL);
|
return new ModelPool(Formats.BLOCK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,6 @@ public class InstancingEngine<P extends WorldProgram> implements Engine {
|
||||||
@Override
|
@Override
|
||||||
public void delete() {
|
public void delete() {
|
||||||
for (Map<RenderType, InstancedMaterialGroup<P>> groups : layers.values()) {
|
for (Map<RenderType, InstancedMaterialGroup<P>> groups : layers.values()) {
|
||||||
|
|
||||||
groups.values().forEach(InstancedMaterialGroup::delete);
|
groups.values().forEach(InstancedMaterialGroup::delete);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,10 @@ public class ArrayModelRenderer {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Model getModel() {
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders this model, checking first if there is anything to render.
|
* Renders this model, checking first if there is anything to render.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -8,7 +8,7 @@ public enum FallbackAllocator implements ModelAllocator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BufferedModel alloc(Model model, Callback allocationCallback) {
|
public BufferedModel alloc(Model model, Callback allocationCallback) {
|
||||||
IndexedModel out = new IndexedModel(model, Formats.POS_TEX_NORMAL);
|
IndexedModel out = new IndexedModel(model, Formats.BLOCK);
|
||||||
allocationCallback.onAlloc(out);
|
allocationCallback.onAlloc(out);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package com.jozufozu.flywheel.core.hardcoded;
|
package com.jozufozu.flywheel.core.hardcoded;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.vertex.VertexList;
|
import com.jozufozu.flywheel.api.vertex.VertexList;
|
||||||
import com.jozufozu.flywheel.api.vertex.VertexType;
|
import com.jozufozu.flywheel.api.vertex.VertexType;
|
||||||
import com.jozufozu.flywheel.core.Formats;
|
import com.jozufozu.flywheel.core.Formats;
|
||||||
|
@ -26,12 +29,14 @@ public class ModelPart implements Model {
|
||||||
this.vertices = vertices;
|
this.vertices = vertices;
|
||||||
}
|
}
|
||||||
|
|
||||||
PosTexNormalWriterUnsafe writer = Formats.POS_TEX_NORMAL.createWriter(MemoryTracker.create(size()));
|
ByteBuffer buffer = MemoryTracker.create(size());
|
||||||
|
PosTexNormalWriterUnsafe writer = Formats.POS_TEX_NORMAL.createWriter(buffer);
|
||||||
for (PartBuilder.CuboidBuilder cuboid : cuboids) {
|
for (PartBuilder.CuboidBuilder cuboid : cuboids) {
|
||||||
cuboid.buffer(writer);
|
cuboid.buffer(writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
reader = writer.intoReader();
|
reader = writer.intoReader();
|
||||||
|
MemoryUtil.memFree(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PartBuilder builder(String name, int sizeU, int sizeV) {
|
public static PartBuilder builder(String name, int sizeU, int sizeV) {
|
||||||
|
|
Loading…
Reference in a new issue