Search in sources :

Example 11 with VertexResource

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

the class OpenGLMeshBase method updateState.

default boolean updateState(VBOContext state) {
    GL30.glBindBuffer(GL30.GL_ARRAY_BUFFER, state.vbo);
    for (int x = 0; x < state.entries.length; x++) {
        if (state.entries[x].version != state.entries[x].resource.getVersion()) {
            if (state.entries[x].size != state.entries[x].resource.inSize()) {
                return false;
            }
            VertexResource resource = state.entries[x].resource;
            int offset = state.entries[x].offset;
            resource.writeBuffer((buffer) -> {
                GL30.glBufferSubData(GL30.GL_ARRAY_BUFFER, offset, buffer);
            });
        }
    }
    GL30.glBindBuffer(GL30.GL_ARRAY_BUFFER, 0);
    return true;
}
Also used : VertexResource(org.terasology.engine.rendering.assets.mesh.resource.VertexResource)

Example 12 with VertexResource

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

Example 13 with VertexResource

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

Example 14 with VertexResource

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

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

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