Skip to content

Commit

Permalink
Add function to BufferBuilder to directly insert byte data. Closes Mi…
Browse files Browse the repository at this point in the history
  • Loading branch information
mcenderdragon authored and LexManos committed Feb 14, 2018
1 parent d18c039 commit bf50f8b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
}

this.func_181667_k();
@@ -605,4 +607,19 @@
@@ -605,4 +607,27 @@
return this.field_179018_e;
}
}
Expand All @@ -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();
+ }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.junit.Test;

import java.util.Arrays;
import java.nio.ByteBuffer;

import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -82,4 +83,51 @@ public void testMixedExpansion()
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);
}
}

0 comments on commit bf50f8b

Please sign in to comment.