use of org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder in project Terasology by MovingBlocks.
the class VertexResourceTest method testPutWithBufferedResource.
@Test
public void testPutWithBufferedResource() {
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.put(secondResource);
assertEquals(3, a1.elements());
VectorAssert.assertEquals(new Vector3f(12.0f, 0.0f, 13.0f), a1.get(0, new Vector3f()), .0001f);
VectorAssert.assertEquals(new Vector3f(12.5f, 13f, 1.5f), a1.get(1, new Vector3f()), .0001f);
VectorAssert.assertEquals(new Vector3f(13.0f, 0.0f, 1.5f), a1.get(2, new Vector3f()), .0001f);
}
use of org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder in project Terasology by MovingBlocks.
the class VertexResourceTest method testReserveVertexResource.
@Test
public void testReserveVertexResource() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexAttributeBinding<Vector3fc, Vector3f> a1 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
VertexResource resource = builder.build();
a1.reserve(10);
a1.put(new Vector3f(10, 10, 10));
a1.put(new Vector3f(5, 10, 10));
a1.put(new Vector3f(15, 10, 10));
assertEquals(3, a1.getPosition());
resource.writeBuffer(buffer -> {
assertNotNull(buffer);
assertEquals(Float.BYTES * 3 * 10, buffer.capacity());
assertEquals(Float.BYTES * 3 * 3, buffer.limit());
int index = 0;
assertEquals(10.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
assertEquals(10.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
assertEquals(10.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
assertEquals(5.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
assertEquals(10.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
assertEquals(10.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
assertEquals(15.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
assertEquals(10.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
assertEquals(10.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
});
}
use of org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder in project Terasology by MovingBlocks.
the class VertexGLAttributeTest method testByteBinding.
@Test
public void testByteBinding() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexByteAttributeBinding a1 = builder.add(0, GLAttributes.BYTE_1_VERTEX_ATTRIBUTE);
VertexResource resource = builder.build();
a1.put((byte) 10);
a1.put((byte) 150);
a1.put((byte) 100);
a1.put((byte) 100);
assertEquals(4, a1.getPosition());
resource.writeBuffer(buffer -> {
assertEquals(4 * Byte.BYTES, buffer.limit());
assertEquals(10, Byte.toUnsignedInt(buffer.get(Byte.BYTES * 0)));
assertEquals(150, Byte.toUnsignedInt(buffer.get(Byte.BYTES * 1)));
assertEquals(100, Byte.toUnsignedInt(buffer.get(Byte.BYTES * 2)));
assertEquals(100, Byte.toUnsignedInt(buffer.get(Byte.BYTES * 3)));
});
}
use of org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder in project Terasology by MovingBlocks.
the class VertexGLAttributeTest method testVector4fBinding.
@Test
public void testVector4fBinding() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexAttributeBinding<Vector4fc, Vector4f> a1 = builder.add(0, GLAttributes.VECTOR_4_F_VERTEX_ATTRIBUTE);
VertexResource resource = builder.build();
a1.put(new Vector4f(10, 150, -10, 12));
a1.put(new Vector4f(15.1f, 15.04f, 10, 12));
a1.put(new Vector4f(16f, 150, -10, 12));
assertEquals(3, a1.getPosition());
int stride = Float.BYTES * 4;
resource.writeBuffer(buffer -> {
assertEquals(3 * 4 * Float.BYTES, buffer.limit());
assertEquals(10, buffer.getFloat(Float.BYTES * 0), 0.001f);
assertEquals(150, buffer.getFloat(Float.BYTES * 1), 0.001f);
assertEquals(-10, buffer.getFloat(Float.BYTES * 2), 0.001f);
assertEquals(12, buffer.getFloat(Float.BYTES * 3), 0.001f);
assertEquals(15.1f, buffer.getFloat((stride) + Float.BYTES * 0), 0.001f);
assertEquals(15.04f, buffer.getFloat((stride) + Float.BYTES * 1), 0.001f);
assertEquals(10, buffer.getFloat((stride) + Float.BYTES * 2), 0.001f);
assertEquals(12, buffer.getFloat((stride) + Float.BYTES * 3), 0.001f);
assertEquals(16f, buffer.getFloat((stride * 2) + Float.BYTES * 0), 0.001f);
assertEquals(150f, buffer.getFloat((stride * 2) + Float.BYTES * 1), 0.001f);
assertEquals(-10, buffer.getFloat((stride * 2) + Float.BYTES * 2), 0.001f);
assertEquals(12, buffer.getFloat((stride * 2) + Float.BYTES * 3), 0.001f);
});
}
Aggregations