change: reuse same buffer to work around mem leaks in 1.19

This commit is contained in:
ZtereoHYPE 2022-07-27 00:17:46 +02:00
parent b15b7a1d87
commit ab607ff7b7

View file

@ -8,6 +8,8 @@ import java.util.ArrayList;
//todo: redo all of the star rendering to be able to use the same vertex buffer object with a uniform or with the posestack //todo: redo all of the star rendering to be able to use the same vertex buffer object with a uniform or with the posestack
public class StarManager { public class StarManager {
private static final BufferBuilder starBufferBuilder = Tesselator.getInstance().getBuilder();
private static final int STAR_ATTEMPTS = 1500; private static final int STAR_ATTEMPTS = 1500;
public static ArrayList<Star> starList = new ArrayList<>(); public static ArrayList<Star> starList = new ArrayList<>();
@ -34,16 +36,15 @@ public class StarManager {
public static void updateStars(int ticks, VertexBuffer starBuffer) { public static void updateStars(int ticks, VertexBuffer starBuffer) {
if (!ExampleMod.toggle) return; if (!ExampleMod.toggle) return;
BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder(); starBufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION);
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION);
for (Star star : starList) { for (Star star : starList) {
star.tick(ticks); star.tick(ticks);
star.setVertices(bufferBuilder); star.setVertices(starBufferBuilder);
} }
starBuffer.bind(); starBuffer.bind();
starBuffer.upload(bufferBuilder.end()); starBuffer.upload(starBufferBuilder.end());
VertexBuffer.unbind(); VertexBuffer.unbind();
} }
} }