Search in sources :

Example 1 with VertexByteAttributeBinding

use of org.terasology.engine.rendering.assets.mesh.resource.VertexByteAttributeBinding 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)));
    });
}
Also used : VertexResource(org.terasology.engine.rendering.assets.mesh.resource.VertexResource) Vector3fc(org.joml.Vector3fc) VertexByteAttributeBinding(org.terasology.engine.rendering.assets.mesh.resource.VertexByteAttributeBinding) VertexResourceBuilder(org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder) Vector3f(org.joml.Vector3f) Test(org.junit.Test)

Example 2 with VertexByteAttributeBinding

use of org.terasology.engine.rendering.assets.mesh.resource.VertexByteAttributeBinding 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);
    });
}
Also used : VertexResource(org.terasology.engine.rendering.assets.mesh.resource.VertexResource) Vector3fc(org.joml.Vector3fc) VertexByteAttributeBinding(org.terasology.engine.rendering.assets.mesh.resource.VertexByteAttributeBinding) VertexResourceBuilder(org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder) Vector3f(org.joml.Vector3f) Test(org.junit.Test)

Example 3 with VertexByteAttributeBinding

use of org.terasology.engine.rendering.assets.mesh.resource.VertexByteAttributeBinding 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)));
    });
}
Also used : VertexResource(org.terasology.engine.rendering.assets.mesh.resource.VertexResource) VertexByteAttributeBinding(org.terasology.engine.rendering.assets.mesh.resource.VertexByteAttributeBinding) VertexResourceBuilder(org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 VertexByteAttributeBinding (org.terasology.engine.rendering.assets.mesh.resource.VertexByteAttributeBinding)3 VertexResource (org.terasology.engine.rendering.assets.mesh.resource.VertexResource)3 VertexResourceBuilder (org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder)3 Vector3f (org.joml.Vector3f)2 Vector3fc (org.joml.Vector3fc)2