Search in sources :

Example 6 with VertexResourceBuilder

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

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

Example 8 with VertexResourceBuilder

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

the class VertexGLAttributeTest method testVector3fBinding.

@Test
public void testVector3fBinding() {
    VertexResourceBuilder builder = new VertexResourceBuilder();
    VertexAttributeBinding<Vector3fc, Vector3f> a1 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
    VertexResource resource = builder.build();
    a1.put(new Vector3f(10, 150, 1.5f));
    a1.put(new Vector3f(15.1f, 15.04f, 15.5f));
    a1.put(new Vector3f(16f, 150, 31.5f));
    assertEquals(3, a1.getPosition());
    int stride = Float.BYTES * 3;
    resource.writeBuffer(buffer -> {
        assertEquals(3 * 3 * Float.BYTES, buffer.limit());
        assertEquals(10, buffer.getFloat(Float.BYTES * 0), 0.001f);
        assertEquals(150, buffer.getFloat(Float.BYTES * 1), 0.001f);
        assertEquals(1.5f, buffer.getFloat(Float.BYTES * 2), 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(15.5f, buffer.getFloat((stride) + Float.BYTES * 2), 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(31.5f, buffer.getFloat((stride * 2) + Float.BYTES * 2), 0.001f);
    });
}
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 9 with VertexResourceBuilder

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

the class VertexGLAttributeTest method testVector2fBinding.

@Test
public void testVector2fBinding() {
    VertexResourceBuilder builder = new VertexResourceBuilder();
    VertexAttributeBinding<Vector2fc, Vector2f> a1 = builder.add(0, GLAttributes.VECTOR_2_F_VERTEX_ATTRIBUTE);
    VertexResource resource = builder.build();
    a1.put(new Vector2f(10, 150));
    a1.put(new Vector2f(15.1f, 15.04f));
    a1.put(new Vector2f(16f, 150));
    assertEquals(3, a1.getPosition());
    int stride = Float.BYTES * 2;
    resource.writeBuffer(buffer -> {
        assertEquals(3 * 2 * Float.BYTES, buffer.limit());
        assertEquals(10, buffer.getFloat(Float.BYTES * 0), 0.001f);
        assertEquals(150, buffer.getFloat(Float.BYTES * 1), 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(16f, buffer.getFloat((stride * 2) + Float.BYTES * 0), 0.001f);
        assertEquals(150f, buffer.getFloat((stride * 2) + Float.BYTES * 1), 0.001f);
    });
}
Also used : VertexResource(org.terasology.engine.rendering.assets.mesh.resource.VertexResource) VertexResourceBuilder(org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder) Vector2fc(org.joml.Vector2fc) Vector2f(org.joml.Vector2f) Test(org.junit.Test)

Example 10 with VertexResourceBuilder

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

the class VertexGLAttributeTest method testColorBinding.

@Test
public void testColorBinding() {
    VertexResourceBuilder builder = new VertexResourceBuilder();
    VertexAttributeBinding<Colorc, Color> a1 = builder.add(0, GLAttributes.COLOR_4_F_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 = Float.BYTES * 4;
    resource.writeBuffer(buffer -> {
        assertEquals(4 * 4 * Float.BYTES, buffer.limit());
        assertEquals(1.0f, buffer.getFloat(Float.BYTES * 0), 0.001f);
        assertEquals(1.0f, buffer.getFloat(Float.BYTES * 1), 0.001f);
        assertEquals(1.0f, buffer.getFloat(Float.BYTES * 2), 0.001f);
        assertEquals(1.0f, buffer.getFloat(Float.BYTES * 3), 0.001f);
        assertEquals(1.0f, buffer.getFloat(stride + Float.BYTES * 0));
        assertEquals(0, buffer.getFloat(stride + Float.BYTES * 1));
        assertEquals(0, buffer.getFloat(stride + Float.BYTES * 2));
        assertEquals(1.0f, buffer.getFloat(stride + Float.BYTES * 3));
        assertEquals(0, buffer.getFloat((2 * stride) + Float.BYTES * 0));
        assertEquals(1.0f, buffer.getFloat((2 * stride) + Float.BYTES * 1));
        assertEquals(0, buffer.getFloat((2 * stride) + Float.BYTES * 2));
        assertEquals(1.0f, buffer.getFloat((2 * stride) + Float.BYTES * 3));
        assertEquals(0, buffer.getFloat((3 * stride) + Float.BYTES * 0));
        assertEquals(0, buffer.getFloat((3 * stride) + Float.BYTES * 1));
        assertEquals(1.0f, buffer.getFloat((3 * stride) + Float.BYTES * 2));
        assertEquals(1.0f, buffer.getFloat((3 * stride) + Float.BYTES * 3));
    });
}
Also used : VertexResource(org.terasology.engine.rendering.assets.mesh.resource.VertexResource) VertexResourceBuilder(org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder) Colorc(org.terasology.nui.Colorc) Color(org.terasology.nui.Color) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)19 VertexResourceBuilder (org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder)19 VertexResource (org.terasology.engine.rendering.assets.mesh.resource.VertexResource)16 Vector3f (org.joml.Vector3f)8 Vector3fc (org.joml.Vector3fc)8 VertexByteAttributeBinding (org.terasology.engine.rendering.assets.mesh.resource.VertexByteAttributeBinding)3 VertexIntegerAttributeBinding (org.terasology.engine.rendering.assets.mesh.resource.VertexIntegerAttributeBinding)3 VertexFloatAttributeBinding (org.terasology.engine.rendering.assets.mesh.resource.VertexFloatAttributeBinding)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 VertexShortAttributeBinding (org.terasology.engine.rendering.assets.mesh.resource.VertexShortAttributeBinding)1