public static FloatBuffer makeInterleavedBuffer(
            float[] positionData,
            float[] normals,
            float[] uvData,
            float[] tileXyData,
            int tiles) {

        int dataLength = positionData.length + normals.length * tiles + uvData.length + tileXyData.length;

        final FloatBuffer interleavedBuffer = ByteBuffer.allocateDirect(dataLength * Const.BYTES_PER_FLOAT)
                .order(ByteOrder.nativeOrder()).asFloatBuffer();

        int positionOffset = 0, normalOffset = 0, textureOffset = 0, tileXyOffset = 0;

        for (int i = 0; i < tiles; i++) {
            for (int j = 0; j < Const.POINTS_PER_TILE; j++) {
                interleavedBuffer.put(positionData, positionOffset, Const.POSITION_DATA_SIZE);
                positionOffset += Const.POSITION_DATA_SIZE;

                interleavedBuffer.put(normals, normalOffset, Const.NORMALS_DATA_SIZE);
                // Normals are the same

                interleavedBuffer.put(uvData, textureOffset, Const.TEXTURE_COORDS_DATA_SIZE);
                textureOffset += Const.TEXTURE_COORDS_DATA_SIZE;

                interleavedBuffer.put(tileXyData, tileXyOffset, Const.TILE_DATA_SIZE);
                tileXyOffset += Const.TILE_DATA_SIZE;
            }
        }


        interleavedBuffer.position(0);
        return interleavedBuffer;
    }
Started by Artem Kholodnyi on 11/1/15 12:48 PM
library/src/main/java/com/yalantis/starwars/render/Buffers.java