use of org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder in project Terasology by MovingBlocks.
the class VertexAttributeBindingTest method testPutAllBindingInt.
@Test
public void testPutAllBindingInt() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexIntegerAttributeBinding a1 = builder.add(0, GLAttributes.INT_1_VERTEX_ATTRIBUTE);
builder.build();
a1.put(new int[] { 10, 2, 1, 1 });
assertEquals(10, a1.get(0));
assertEquals(2, a1.get(1));
assertEquals(1, a1.get(2));
assertEquals(1, a1.get(3));
}
use of org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder in project Terasology by MovingBlocks.
the class VertexAttributeBindingTest method testPutAllBindingFloat.
@Test
public void testPutAllBindingFloat() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexFloatAttributeBinding a1 = builder.add(0, GLAttributes.FLOAT_1_VERTEX_ATTRIBUTE);
builder.build();
a1.put(new float[] { 10f, .5f, 12.5f, 13.5f });
assertEquals(10f, a1.get(0), 0.001f);
assertEquals(.5f, a1.get(1), 0.001f);
assertEquals(12.5f, a1.get(2), 0.001f);
assertEquals(13.5f, a1.get(3), 0.001f);
}
use of org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder in project Terasology by MovingBlocks.
the class VertexResourceTest method testInterleave.
@Test
public void testInterleave() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexAttributeBinding<Vector3fc, Vector3f> a1 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
VertexByteAttributeBinding a2 = builder.add(0, GLAttributes.BYTE_1_VERTEX_ATTRIBUTE);
VertexResource resource = builder.build();
a1.put(new Vector3f(10, 0, -4));
a2.put(UnsignedBytes.checkedCast(2));
a2.put(UnsignedBytes.checkedCast(10));
assertEquals(2, a2.getPosition());
assertEquals(1, a1.getPosition());
int stride = (Float.BYTES * 3) + Byte.BYTES;
resource.writeBuffer(buffer -> {
assertEquals(buffer.limit(), stride * 2);
assertEquals(10, buffer.getFloat((0 * Float.BYTES)), 0.001f);
assertEquals(0, buffer.getFloat((1 * Float.BYTES)), 0.001f);
assertEquals(-4, buffer.getFloat(2 * Float.BYTES), 0.001f);
assertEquals(2, buffer.get((3 * Float.BYTES)));
assertEquals(0, buffer.getFloat(stride + (0 * Float.BYTES)), 0.001f);
assertEquals(0, buffer.getFloat(stride + (1 * Float.BYTES)), 0.001f);
assertEquals(0, buffer.getFloat(stride + (2 * Float.BYTES)), 0.001f);
assertEquals(10, buffer.get(stride + (3 * Float.BYTES)));
});
}
use of org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder in project Terasology by MovingBlocks.
the class VertexResourceTest method testReplaceBufferedResource.
@Test
public void testReplaceBufferedResource() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexAttributeBinding<Vector3fc, Vector3f> a1 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
VertexResource firstResource = builder.build();
a1.put(new Vector3f(12.0f, 0.0f, 13.0f));
a1.put(new Vector3f(12.5f, 13f, 1.5f));
builder = new VertexResourceBuilder();
VertexAttributeBinding<Vector3fc, Vector3f> b2 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
VertexResource secondResource = builder.build();
b2.put(new Vector3f(13.0f, 0.0f, 1.5f));
firstResource.replace(secondResource);
assertEquals(1, a1.elements());
VectorAssert.assertEquals(new Vector3f(13.0f, 0.0f, 1.5f), a1.get(0, new Vector3f()), .0001f);
}
use of org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder in project Terasology by MovingBlocks.
the class VertexResourceTest method testAllocation.
@Test
public void testAllocation() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexAttributeBinding<Vector3fc, Vector3f> a1 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
VertexByteAttributeBinding a2 = builder.add(0, GLAttributes.BYTE_1_VERTEX_ATTRIBUTE);
VertexResource resource = builder.build();
a1.allocate(10);
int stride = (Float.BYTES * 3) + Byte.BYTES;
resource.writeBuffer(buffer -> {
assertEquals(buffer.limit(), stride * 10);
assertEquals(buffer.capacity(), stride * 10);
});
}
Aggregations