Login  Register

VBO Performance Misunderstanding

Posted by alicana on Apr 18, 2015; 11:29am
URL: https://forum.jogamp.org/VBO-Performance-Misunderstanding-tp4034319.html

Hi all,

I have a stream from external source (an app), with this stream I'm trying to draw a point for each. WARNING: I need an expandable buffer. I changed Wade Walker's code, thanks to him, as follow:

private int[] createAndFillVertexBuffer(GL2 gl, ArrayList<IData> listDataObjects) {

        int[] aiNumOfVertices = new int[] { listDataObjects.size() };

        if (aiVertexBufferIndices[0] == -1) {
                  if (!gl.isFunctionAvailable("glGenBuffers") || !gl.isFunctionAvailable("glBindBuffer")
                                        || !gl.isFunctionAvailable("glBufferData") || !gl.isFunctionAvailable("glDeleteBuffers")) {
                                System.err.println("VBO unsupported!");
                }

                        gl.glGenBuffers(1, aiVertexBufferIndices, 0);
                        gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, aiVertexBufferIndices[0]);

                        allocated = (listDataObjects.size() * 2 * Buffers.SIZEOF_DOUBLE * 3);
                        gl.glBufferData(GL2.GL_ARRAY_BUFFER, allocated, null, GL2.GL_STREAM_DRAW);

                }

                gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, aiVertexBufferIndices[0]);

                int tempAllocated = next_power_of_two(listDataObjects.size() * 2 * Buffers.SIZEOF_DOUBLE * 3) * 2;

                if (allocated < tempAllocated) {

                        allocated = tempAllocated;
                        gl.glBufferData(GL2.GL_ARRAY_BUFFER, allocated, null, GL2.GL_STREAM_DRAW);

}

                ByteBuffer bytebuffer = gl.glMapBuffer(GL2.GL_ARRAY_BUFFER, GL2.GL_WRITE_ONLY);
                DoubleBuffer doublebuffer = bytebuffer.order(ByteOrder.nativeOrder()).asDoubleBuffer();

                for (IData dataobject : listDataObjects)
                        storeVerticesAndColors(doublebuffer, dataobject);

                gl.glUnmapBuffer(GL2.GL_ARRAY_BUFFER);

                return (aiNumOfVertices);

        }


As you see above, I'm trying to change buffer size (Correct me If I'm wrong, I guess its working, not throw exception yet)

if (allocated < tempAllocated) {

        allocated = tempAllocated;
        gl.glBufferData(GL2.GL_ARRAY_BUFFER, allocated, null, GL2.GL_STREAM_DRAW);

}


I used to draw points imidiate mode and draws 2M points in 400 milliseconds.

But, somehow, VBO approach does not give me that performance :(

display time: 265 ms, number of point: 310000
display time: 314 ms, number of point: 375000
display time: 405 ms, number of point: 454724
display time: 450 ms, number of point: 550000
display time: 510 ms, number of point: 660000
display time: 745 ms, number of point: 790000
display time: 750 ms, number of point: 970000
display time: 970 ms, number of point: 1160000
display time: 1150 ms, number of point: 1391426