From bf50f8bc30f8893f206ef026349b19126b680708 Mon Sep 17 00:00:00 2001 From: mcenderdragon Date: Wed, 14 Feb 2018 07:00:25 +0100 Subject: [PATCH] Add function to BufferBuilder to directly insert byte data. Closes #4722 --- .../client/renderer/BufferBuilder.java.patch | 10 +++- .../test/BufferBuilderExpansionTest.java | 48 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/patches/minecraft/net/minecraft/client/renderer/BufferBuilder.java.patch b/patches/minecraft/net/minecraft/client/renderer/BufferBuilder.java.patch index 1de09e9a5..fab959546 100644 --- a/patches/minecraft/net/minecraft/client/renderer/BufferBuilder.java.patch +++ b/patches/minecraft/net/minecraft/client/renderer/BufferBuilder.java.patch @@ -40,7 +40,7 @@ } this.func_181667_k(); -@@ -605,4 +607,19 @@ +@@ -605,4 +607,27 @@ return this.field_179018_e; } } @@ -58,5 +58,13 @@ + public boolean isColorDisabled() + { + return this.field_78939_q; ++ } ++ ++ public void putBulkData(ByteBuffer buffer) ++ { ++ func_181670_b(buffer.limit() + this.field_179011_q.func_177338_f()); ++ this.field_179001_a.position(this.field_178997_d * this.field_179011_q.func_177338_f()); ++ this.field_179001_a.put(buffer); ++ this.field_178997_d += buffer.limit() / this.field_179011_q.func_177338_f(); + } } diff --git a/src/test/java/net/minecraftforge/test/BufferBuilderExpansionTest.java b/src/test/java/net/minecraftforge/test/BufferBuilderExpansionTest.java index d19f9e63b..053f01178 100644 --- a/src/test/java/net/minecraftforge/test/BufferBuilderExpansionTest.java +++ b/src/test/java/net/minecraftforge/test/BufferBuilderExpansionTest.java @@ -6,6 +6,7 @@ import net.minecraft.client.renderer.vertex.VertexFormat; import org.junit.Test; import java.util.Arrays; +import java.nio.ByteBuffer; import static org.junit.Assert.assertTrue; @@ -82,4 +83,51 @@ public class BufferBuilderExpansionTest assertTrue("BufferBuilder's capacity didn't change.", buffer.getByteBuffer().capacity() > prevCap); } + @Test//Test the expansion of the buffer with putBulkData + public void testAddVertexExpansionBytes() + { + BufferBuilder buffer = new BufferBuilder(BUFFER_SIZE / 4); + int prevCap = buffer.getByteBuffer().capacity(); + + ByteBuffer buf = ByteBuffer.allocate(3 * 4 * 4); //3 floats per the 4 verticles (32bit float as 4 8bit bytes) + for(int i=0;i<4;i++) + buf.putFloat(1.233F); //Just a random value. + + buffer.begin(0x07, format); + for (int i = 0; i < num_quads + 2; i++) + { + buffer.putBulkData(buf); + } + buffer.finishDrawing(); + + assertTrue("BufferBuilder's capacity didn't change.", buffer.getByteBuffer().capacity() > prevCap); + } + + @Test//Test the expansion of the buffer if putBulkData fills it and pos / tex / endVertex is used. + public void testMixedExpansionBytes() + { + BufferBuilder buffer = new BufferBuilder(BUFFER_SIZE / 4); + int prevCap = buffer.getByteBuffer().capacity(); + + ByteBuffer buf = ByteBuffer.allocate(3 * 4 * 4); + for(int i=0;i<4;i++) + buf.putFloat(1.233F); + + buffer.begin(0x07, format); + for (int i = 0; i < num_quads; i++) + { + buffer.putBulkData(buf); + } + + for (int i = 0; i < num_quads + 2; i++) + { + for (int j = 0; j < 4; j++) + { + buffer.pos(1.233, 1.233, 1.233).endVertex(); + } + } + buffer.finishDrawing(); + + assertTrue("BufferBuilder's capacity didn't change.", buffer.getByteBuffer().capacity() > prevCap); + } }