use of org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder in project Terasology by MovingBlocks.
the class VertexGLAttributeTest method testShortBinding.
@Test
public void testShortBinding() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexShortAttributeBinding a1 = builder.add(0, GLAttributes.SHORT_1_VERTEX_ATTRIBUTE);
VertexResource resource = builder.build();
a1.put((short) 10);
a1.put((short) 150);
a1.put((short) 100);
a1.put((short) 100);
assertEquals(4, a1.getPosition());
resource.writeBuffer(buffer -> {
assertEquals(4 * Short.BYTES, buffer.limit());
assertEquals(10, Short.toUnsignedInt(buffer.getShort(Short.BYTES * 0)));
assertEquals(150, Short.toUnsignedInt(buffer.getShort(Short.BYTES * 1)));
assertEquals(100, Short.toUnsignedInt(buffer.getShort(Short.BYTES * 2)));
assertEquals(100, Short.toUnsignedInt(buffer.getShort(Short.BYTES * 3)));
});
}
use of org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder in project Terasology by MovingBlocks.
the class VertexGLAttributeTest method testIntBinding.
@Test
public void testIntBinding() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexIntegerAttributeBinding a1 = builder.add(0, GLAttributes.INT_1_VERTEX_ATTRIBUTE);
VertexResource resource = builder.build();
a1.put(10);
a1.put(20);
a1.put(150);
a1.put(100);
a1.put(-100);
assertEquals(5, a1.getPosition());
resource.writeBuffer(buffer -> {
assertEquals(5 * Integer.BYTES, buffer.limit());
assertEquals(10, buffer.getInt(Integer.BYTES * 0));
assertEquals(20, buffer.getInt(Integer.BYTES * 1));
assertEquals(150, buffer.getInt(Integer.BYTES * 2));
assertEquals(100, buffer.getInt(Integer.BYTES * 3));
assertEquals(-100, buffer.getInt(Integer.BYTES * 4));
});
}
use of org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder in project Terasology by MovingBlocks.
the class VertexGLAttributeTest method testColorPackedBinding.
@Test
public void testColorPackedBinding() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexAttributeBinding<Colorc, Color> a1 = builder.add(0, GLAttributes.COLOR_4_PACKED_VERTEX_ATTRIBUTE);
VertexResource resource = builder.build();
a1.put(Color.white);
a1.put(Color.red);
a1.put(Color.green);
a1.put(Color.blue);
assertEquals(4, a1.getPosition());
int stride = Byte.BYTES * 4;
resource.writeBuffer(buffer -> {
assertEquals(4 * 4 * Byte.BYTES, buffer.limit());
assertEquals(255, Byte.toUnsignedInt(buffer.get(Byte.BYTES * 0)));
assertEquals(255, Byte.toUnsignedInt(buffer.get(Byte.BYTES * 1)));
assertEquals(255, Byte.toUnsignedInt(buffer.get(Byte.BYTES * 2)));
assertEquals(255, Byte.toUnsignedInt(buffer.get(Byte.BYTES * 3)));
assertEquals(255, Byte.toUnsignedInt(buffer.get(stride + Byte.BYTES * 0)));
assertEquals(0, Byte.toUnsignedInt(buffer.get(stride + Byte.BYTES * 1)));
assertEquals(0, Byte.toUnsignedInt(buffer.get(stride + Byte.BYTES * 2)));
assertEquals(255, Byte.toUnsignedInt(buffer.get(stride + Byte.BYTES * 3)));
assertEquals(0, Byte.toUnsignedInt(buffer.get((2 * stride) + Byte.BYTES * 0)));
assertEquals(255, Byte.toUnsignedInt(buffer.get((2 * stride) + Byte.BYTES * 1)));
assertEquals(0, Byte.toUnsignedInt(buffer.get((2 * stride) + Byte.BYTES * 2)));
assertEquals(255, Byte.toUnsignedInt(buffer.get((2 * stride) + Byte.BYTES * 3)));
assertEquals(0, Byte.toUnsignedInt(buffer.get((3 * stride) + Byte.BYTES * 0)));
assertEquals(0, Byte.toUnsignedInt(buffer.get((3 * stride) + Byte.BYTES * 1)));
assertEquals(255, Byte.toUnsignedInt(buffer.get((3 * stride) + Byte.BYTES * 2)));
assertEquals(255, Byte.toUnsignedInt(buffer.get((3 * stride) + Byte.BYTES * 3)));
});
}
use of org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder in project Terasology by MovingBlocks.
the class VertexGLAttributeTest method testFloatBinding.
@Test
public void testFloatBinding() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexFloatAttributeBinding a1 = builder.add(0, GLAttributes.FLOAT_1_VERTEX_ATTRIBUTE);
VertexResource resource = builder.build();
a1.put(10.0f);
a1.put(15.0f);
a1.put(15.5f);
a1.put(2.0f);
a1.put(-100.0f);
assertEquals(5, a1.getPosition());
resource.writeBuffer(buffer -> {
assertEquals(5 * Float.BYTES, buffer.limit());
assertEquals(10.0f, buffer.getFloat(Float.BYTES * 0), 0.0001f);
assertEquals(15.0f, buffer.getFloat(Float.BYTES * 1), 0.0001f);
assertEquals(15.5f, buffer.getFloat(Float.BYTES * 2), 0.0001f);
assertEquals(2.0f, buffer.getFloat(Float.BYTES * 3), 0.0001f);
assertEquals(-100.0f, buffer.getFloat(Float.BYTES * 4), 0.0001f);
});
}
use of org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder in project Terasology by MovingBlocks.
the class VertexAttributeBindingTest method testPutAllBindingVector.
@Test
public void testPutAllBindingVector() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexAttributeBinding<Vector3fc, Vector3f> a1 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
builder.build();
a1.put(new Vector3fc[] { new Vector3f(10, 5, 2), new Vector3f(2, 15, 2), new Vector3f(1, 5, 13), new Vector3f(1, 1, 1) });
VectorAssert.assertEquals(new Vector3f(10, 5, 2), a1.get(0, new Vector3f()), 0.001f);
VectorAssert.assertEquals(new Vector3f(2, 15, 2), a1.get(1, new Vector3f()), 0.001f);
VectorAssert.assertEquals(new Vector3f(1, 5, 13), a1.get(2, new Vector3f()), 0.001f);
VectorAssert.assertEquals(new Vector3f(1, 1, 1), a1.get(3, new Vector3f()), 0.001f);
}
Aggregations