Search in sources :

Example 1 with VertexResource

use of org.terasology.engine.rendering.assets.mesh.resource.VertexResource 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 VertexResource

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

Example 3 with VertexResource

use of org.terasology.engine.rendering.assets.mesh.resource.VertexResource 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 4 with VertexResource

use of org.terasology.engine.rendering.assets.mesh.resource.VertexResource in project Terasology by MovingBlocks.

the class VertexResourceTest method testRewind.

@Test
public void testRewind() {
    VertexResourceBuilder builder = new VertexResourceBuilder();
    VertexIntegerAttributeBinding a1 = builder.add(0, GLAttributes.INT_1_VERTEX_ATTRIBUTE);
    VertexResource resource = builder.build();
    a1.put(10);
    a1.put(20);
    assertEquals(2, a1.getPosition());
    resource.writeBuffer(buffer -> {
        assertEquals(2 * Integer.BYTES, buffer.limit());
        assertEquals(10, buffer.getInt(Integer.BYTES * 0));
        assertEquals(20, buffer.getInt(Integer.BYTES * 1));
    });
    // rewind buffer
    a1.rewind();
    // position is at 0
    assertEquals(0, a1.getPosition());
    // set 15 for position 0
    a1.put(15);
    resource.writeBuffer(buffer -> {
        assertEquals(2 * Integer.BYTES, buffer.limit());
        assertEquals(15, buffer.getInt(Integer.BYTES * 0));
        assertEquals(20, buffer.getInt(Integer.BYTES * 1));
    });
    // set 5 for position 1
    a1.put(5);
    resource.writeBuffer(buffer -> {
        assertEquals(2 * Integer.BYTES, buffer.limit());
        assertEquals(15, buffer.getInt(Integer.BYTES * 0));
        assertEquals(5, buffer.getInt(Integer.BYTES * 1));
    });
}
Also used : VertexResource(org.terasology.engine.rendering.assets.mesh.resource.VertexResource) VertexResourceBuilder(org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder) VertexIntegerAttributeBinding(org.terasology.engine.rendering.assets.mesh.resource.VertexIntegerAttributeBinding) Test(org.junit.Test)

Example 5 with VertexResource

use of org.terasology.engine.rendering.assets.mesh.resource.VertexResource in project Terasology by MovingBlocks.

the class VertexResourceTest method testPutWithByteBuffer.

@Test
public void testPutWithByteBuffer() {
    VertexResourceBuilder builder = new VertexResourceBuilder();
    VertexAttributeBinding<Vector3fc, Vector3f> a1 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
    VertexResource resource = builder.build();
    ByteBuffer buffer = BufferUtils.createByteBuffer(Float.BYTES * 6);
    buffer.putFloat(0 * Float.BYTES, 12.0f);
    buffer.putFloat(1 * Float.BYTES, 20.0f);
    buffer.putFloat(2 * Float.BYTES, 50.0f);
    buffer.putFloat(3 * Float.BYTES, 25.0f);
    buffer.putFloat(4 * Float.BYTES, 15.0f);
    buffer.putFloat(5 * Float.BYTES, 1.5f);
    resource.put(buffer);
    resource.put(buffer);
    assertEquals(4, a1.elements());
    VectorAssert.assertEquals(new Vector3f(12.0f, 20.0f, 50.0f), a1.get(0, new Vector3f()), .0001f);
    VectorAssert.assertEquals(new Vector3f(25.0f, 15.0f, 1.5f), a1.get(1, new Vector3f()), .0001f);
    VectorAssert.assertEquals(new Vector3f(12.0f, 20.0f, 50.0f), a1.get(2, new Vector3f()), .0001f);
    VectorAssert.assertEquals(new Vector3f(25.0f, 15.0f, 1.5f), a1.get(3, new Vector3f()), .0001f);
}
Also used : VertexResource(org.terasology.engine.rendering.assets.mesh.resource.VertexResource) Vector3fc(org.joml.Vector3fc) VertexResourceBuilder(org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder) Vector3f(org.joml.Vector3f) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

VertexResource (org.terasology.engine.rendering.assets.mesh.resource.VertexResource)18 Test (org.junit.Test)16 VertexResourceBuilder (org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder)16 Vector3f (org.joml.Vector3f)7 Vector3fc (org.joml.Vector3fc)7 VertexByteAttributeBinding (org.terasology.engine.rendering.assets.mesh.resource.VertexByteAttributeBinding)3 VertexIntegerAttributeBinding (org.terasology.engine.rendering.assets.mesh.resource.VertexIntegerAttributeBinding)2 Color (org.terasology.nui.Color)2 Colorc (org.terasology.nui.Colorc)2 ByteBuffer (java.nio.ByteBuffer)1 Vector2f (org.joml.Vector2f)1 Vector2fc (org.joml.Vector2fc)1 Vector4f (org.joml.Vector4f)1 Vector4fc (org.joml.Vector4fc)1 VertexFloatAttributeBinding (org.terasology.engine.rendering.assets.mesh.resource.VertexFloatAttributeBinding)1 VertexShortAttributeBinding (org.terasology.engine.rendering.assets.mesh.resource.VertexShortAttributeBinding)1