From 84cea781516545956fdbaf520f8466af2f4b2acb Mon Sep 17 00:00:00 2001 From: PeytonPlayz595 <106421860+PeytonPlayz595@users.noreply.github.com> Date: Tue, 11 Jul 2023 20:05:13 -0400 Subject: [PATCH] Fixed Models (Again) --- .../com/mojang/minecraft/model/ModelPart.java | 12 ++-- .../net/PeytonPlayz585/glemu/ModeBuffer.java | 58 +++++++++++++++++++ 2 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 src/teavm/java/net/PeytonPlayz585/glemu/ModeBuffer.java diff --git a/src/teavm/java/com/mojang/minecraft/model/ModelPart.java b/src/teavm/java/com/mojang/minecraft/model/ModelPart.java index 2f61d76..84c96d4 100644 --- a/src/teavm/java/com/mojang/minecraft/model/ModelPart.java +++ b/src/teavm/java/com/mojang/minecraft/model/ModelPart.java @@ -3,6 +3,9 @@ package com.mojang.minecraft.model; import com.mojang.minecraft.model.TexturedQuad; import com.mojang.minecraft.model.Vec3D; import com.mojang.minecraft.model.Vertex; + +import net.PeytonPlayz585.glemu.ModeBuffer; + import org.lwjgl.opengl.GL11; public final class ModelPart { @@ -128,7 +131,7 @@ public final class ModelPart { public void generateList(float var1) { this.list = GL11.glGenLists(1); GL11.glNewList(this.list, 4864); - GL11.glBegin(7); + GL11.glBeginQuery(7); for(int var2 = 0; var2 < this.quads.length; ++var2) { TexturedQuad var10000 = this.quads[var2]; @@ -140,12 +143,13 @@ public final class ModelPart { for(int var7 = 0; var7 < 4; ++var7) { Vertex var8; - GL11.glTexCoord2f((var8 = var4.vertices[var7]).u, var8.v); - GL11.glVertex3f(var8.vector.x * var3, var8.vector.y * var3, var8.vector.z * var3); + final ModeBuffer mb = new ModeBuffer(1024); + mb.glTexCoord2f((var8 = var4.vertices[var7]).u, var8.v); + mb.glVertex3f(var8.vector.x * var3, var8.vector.y * var3, var8.vector.z * var3); } } - GL11.glEnd(); + GL11.glEndQuery(); GL11.glEndList(); this.hasList = true; } diff --git a/src/teavm/java/net/PeytonPlayz585/glemu/ModeBuffer.java b/src/teavm/java/net/PeytonPlayz585/glemu/ModeBuffer.java new file mode 100644 index 0000000..f6aaee7 --- /dev/null +++ b/src/teavm/java/net/PeytonPlayz585/glemu/ModeBuffer.java @@ -0,0 +1,58 @@ +package net.PeytonPlayz585.glemu; + +import java.nio.FloatBuffer; + +import net.lax1dude.eaglercraft.GLAllocation; + +/** + * Utility class that emulates immediate mode vertex data submission. + * Can be used to create VBO data. + */ +public final class ModeBuffer { + + private FloatBuffer buffer; + + public ModeBuffer(final int startSize) { + this.buffer = GLAllocation.createDirectFloatBuffer(startSize); + } + + private void checkSize(final int count) { + while ( buffer.remaining() < count ) { + final FloatBuffer newBuffer = GLAllocation.createDirectFloatBuffer(buffer.capacity() << 1); + buffer.flip(); + newBuffer.put(buffer); + buffer = newBuffer; + } + } + + public FloatBuffer getBuffer() { + buffer.flip(); + return buffer; + } + + public void glVertex2f(final float x, final float y) { + checkSize(2); + buffer.put(x).put(y); + } + + public void glVertex3f(final float x, final float y, final float z) { + checkSize(3); + buffer.put(x).put(y).put(z); + } + + public void glVertex4f(final float x, final float y, final float z, final float w) { + checkSize(4); + buffer.put(x).put(y).put(z).put(w); + } + + public void glNormal3f(final float x, final float y, final float z) { + checkSize(3); + buffer.put(x).put(y).put(z); + } + + public void glTexCoord2f(final float s, final float t) { + checkSize(2); + buffer.put(s).put(t); + } + +} \ No newline at end of file