Merge remote-tracking branch 'origin/1.19/dev' into 1.19/fabric/dev

This commit is contained in:
PepperCode1 2022-12-27 16:12:32 -08:00
commit c4b7e869bb
12 changed files with 38 additions and 13 deletions

View file

@ -19,6 +19,7 @@ public interface Material<D extends InstanceData> {
*
* @param key An object that uniquely identifies the model.
* @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.
*/
Instancer<D> model(Object key, Supplier<Model> modelSupplier);

View file

@ -42,4 +42,9 @@ public class BatchedMaterial<D extends InstanceData> implements Material<D> {
models.values()
.forEach(CPUInstancer::clear);
}
public void delete() {
models.values().forEach(CPUInstancer::delete);
models.clear();
}
}

View file

@ -67,6 +67,9 @@ public class BatchedMaterialGroup implements MaterialGroup {
}
public void delete() {
materials.values()
.forEach(BatchedMaterial::delete);
materials.clear();
}

View file

@ -64,11 +64,13 @@ public class BatchingEngine implements Engine {
@Override
public void delete() {
for (Map<RenderType, BatchedMaterialGroup> groups : layers.values()) {
groups.values().forEach(BatchedMaterialGroup::delete);
}
}
@Override
public void beginFrame(Camera info) {
}
@Override

View file

@ -73,4 +73,8 @@ public class CPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
public void notifyDirty() {
// noop
}
public void delete() {
modelData.delete();
}
}

View file

@ -104,6 +104,8 @@ public class GPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
instanceVBO.delete();
vao.delete();
modelData.delete();
}
protected void renderSetup() {

View file

@ -43,6 +43,10 @@ public class InstancedMaterial<D extends InstanceData> implements Material<D> {
});
}
public Collection<GPUInstancer<D>> getAllInstancers() {
return models.values();
}
public int getInstanceCount() {
return models.values().stream().mapToInt(GPUInstancer::getInstanceCount).sum();
}
@ -57,11 +61,6 @@ public class InstancedMaterial<D extends InstanceData> implements Material<D> {
.allMatch(GPUInstancer::isEmpty);
}
public void delete() {
models.values().forEach(GPUInstancer::delete);
models.clear();
}
/**
* Clear all instance data without freeing resources.
*/
@ -70,7 +69,8 @@ public class InstancedMaterial<D extends InstanceData> implements Material<D> {
.forEach(GPUInstancer::clear);
}
public Collection<GPUInstancer<D>> getAllInstancers() {
return models.values();
public void delete() {
models.values().forEach(GPUInstancer::delete);
models.clear();
}
}

View file

@ -94,7 +94,7 @@ public class InstancedMaterialGroup<P extends WorldProgram> implements MaterialG
if (material.nothingToRender()) continue;
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
program.bind();
@ -155,7 +155,7 @@ public class InstancedMaterialGroup<P extends WorldProgram> implements MaterialG
.onAMDWindows()) {
return FallbackAllocator.INSTANCE;
} else {
return new ModelPool(Formats.POS_TEX_NORMAL);
return new ModelPool(Formats.BLOCK);
}
}
}

View file

@ -117,7 +117,6 @@ public class InstancingEngine<P extends WorldProgram> implements Engine {
@Override
public void delete() {
for (Map<RenderType, InstancedMaterialGroup<P>> groups : layers.values()) {
groups.values().forEach(InstancedMaterialGroup::delete);
}
}

View file

@ -14,6 +14,10 @@ public class ArrayModelRenderer {
this.model = model;
}
public Model getModel() {
return model;
}
/**
* Renders this model, checking first if there is anything to render.
*/

View file

@ -8,7 +8,7 @@ public enum FallbackAllocator implements ModelAllocator {
@Override
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);
return out;
}

View file

@ -1,7 +1,10 @@
package com.jozufozu.flywheel.core.hardcoded;
import java.nio.ByteBuffer;
import java.util.List;
import org.lwjgl.system.MemoryUtil;
import com.jozufozu.flywheel.api.vertex.VertexList;
import com.jozufozu.flywheel.api.vertex.VertexType;
import com.jozufozu.flywheel.core.Formats;
@ -26,12 +29,14 @@ public class ModelPart implements Model {
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) {
cuboid.buffer(writer);
}
reader = writer.intoReader();
MemoryUtil.memFree(buffer);
}
public static PartBuilder builder(String name, int sizeU, int sizeV) {