Add function to BufferBuilder to directly insert byte data. Closes #4722

This commit is contained in:
mcenderdragon 2018-02-14 07:00:25 +01:00 committed by LexManos
parent d18c03968e
commit bf50f8bc30
2 changed files with 57 additions and 1 deletions

View file

@ -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();
+ }
}

View file

@ -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);
}
}