2021-12-15 09:35:48 +01:00
|
|
|
package com.jozufozu.flywheel.mixin;
|
|
|
|
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
|
2021-12-22 07:47:29 +01:00
|
|
|
import javax.annotation.Nonnull;
|
2021-12-15 09:35:48 +01:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2021-12-23 23:41:10 +01:00
|
|
|
import org.lwjgl.system.MemoryUtil;
|
2021-12-15 09:35:48 +01:00
|
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
|
|
import org.spongepowered.asm.mixin.Shadow;
|
|
|
|
|
2021-12-23 23:41:10 +01:00
|
|
|
import com.jozufozu.flywheel.backend.instancing.SuperBufferSource;
|
2021-12-15 09:35:48 +01:00
|
|
|
import com.jozufozu.flywheel.backend.model.DirectVertexConsumer;
|
2021-12-23 23:41:10 +01:00
|
|
|
import com.jozufozu.flywheel.backend.model.BufferBuilderHack;
|
2021-12-15 09:35:48 +01:00
|
|
|
import com.mojang.blaze3d.vertex.BufferBuilder;
|
|
|
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
|
|
|
import com.mojang.blaze3d.vertex.VertexFormatElement;
|
|
|
|
|
|
|
|
@Mixin(BufferBuilder.class)
|
2021-12-23 23:41:10 +01:00
|
|
|
public abstract class BufferBuilderMixin implements BufferBuilderHack {
|
2021-12-15 09:35:48 +01:00
|
|
|
@Shadow
|
|
|
|
private ByteBuffer buffer;
|
|
|
|
|
|
|
|
@Shadow
|
2021-12-23 23:41:10 +01:00
|
|
|
private boolean building;
|
2021-12-15 09:35:48 +01:00
|
|
|
|
|
|
|
@Shadow
|
2021-12-23 23:41:10 +01:00
|
|
|
public abstract void begin(VertexFormat.Mode p_166780_, VertexFormat p_166781_);
|
2021-12-15 09:35:48 +01:00
|
|
|
|
|
|
|
@Shadow
|
2021-12-23 23:41:10 +01:00
|
|
|
private VertexFormat.Mode mode;
|
|
|
|
|
|
|
|
@Shadow
|
|
|
|
private VertexFormat format;
|
2021-12-15 09:35:48 +01:00
|
|
|
|
|
|
|
@Shadow
|
|
|
|
@Nullable
|
|
|
|
private VertexFormatElement currentElement;
|
|
|
|
|
|
|
|
@Shadow
|
|
|
|
private int elementIndex;
|
|
|
|
|
|
|
|
@Shadow
|
2021-12-23 23:41:10 +01:00
|
|
|
private int vertices;
|
2021-12-15 09:35:48 +01:00
|
|
|
|
|
|
|
@Override
|
2021-12-23 23:41:10 +01:00
|
|
|
public void freeBuffer() {
|
|
|
|
if (this.buffer != null) {
|
|
|
|
MemoryUtil.memFree(this.buffer);
|
|
|
|
this.buffer = null;
|
|
|
|
}
|
|
|
|
}
|
2021-12-15 09:35:48 +01:00
|
|
|
|
2021-12-23 23:41:10 +01:00
|
|
|
@Override
|
|
|
|
public void hackBegin(@Nonnull ByteBuffer buffer, @Nonnull VertexFormat format, int vertexCount) {
|
|
|
|
this.building = true;
|
|
|
|
this.mode = VertexFormat.Mode.QUADS;
|
2021-12-15 09:35:48 +01:00
|
|
|
|
2021-12-23 23:41:10 +01:00
|
|
|
this.buffer = buffer;
|
|
|
|
this.format = format;
|
|
|
|
this.vertices = vertexCount;
|
2021-12-16 19:49:26 +01:00
|
|
|
|
2021-12-23 23:41:10 +01:00
|
|
|
this.currentElement = this.format.getElements().get(0);
|
|
|
|
this.elementIndex = 0;
|
2021-12-15 09:35:48 +01:00
|
|
|
}
|
|
|
|
}
|