Flywheel/src/main/java/com/jozufozu/flywheel/mixin/BufferBuilderMixin.java
Jozufozu c0ddc860d9 RenderLayers directly store DrawBuffers
- Inspired by pepper's BlockEntityTypeExtensions
 - Document the batching engine internals.
2022-01-06 15:25:00 -08:00

64 lines
1.4 KiB
Java

package com.jozufozu.flywheel.mixin;
import java.nio.ByteBuffer;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.lwjgl.system.MemoryUtil;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import com.jozufozu.flywheel.backend.model.BufferBuilderExtension;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.blaze3d.vertex.VertexFormatElement;
@Mixin(BufferBuilder.class)
public abstract class BufferBuilderMixin implements BufferBuilderExtension {
@Shadow
private ByteBuffer buffer;
@Shadow
private boolean building;
@Shadow
public abstract void begin(VertexFormat.Mode p_166780_, VertexFormat p_166781_);
@Shadow
private VertexFormat.Mode mode;
@Shadow
private VertexFormat format;
@Shadow
@Nullable
private VertexFormatElement currentElement;
@Shadow
private int elementIndex;
@Shadow
private int vertices;
@Override
public void flywheel$freeBuffer() {
if (this.buffer != null) {
MemoryUtil.memFree(this.buffer);
this.buffer = null;
}
}
@Override
public void flywheel$injectForRender(@Nonnull ByteBuffer buffer, @Nonnull VertexFormat format, int vertexCount) {
this.building = true;
this.mode = VertexFormat.Mode.QUADS;
this.buffer = buffer;
this.format = format;
this.vertices = vertexCount;
this.currentElement = this.format.getElements().get(0);
this.elementIndex = 0;
}
}