memyself
memyself

Reputation: 12638

how to create line-strip across multiple VBOs?

I'm working on a simple opengl application where I plot a bunch of data represented as a line. For performance reasons, I split up the data into multiple chunks and upload them into several VOBs. Later, I render each VBO individually. The following is some example code:

n_COORDINATES_PER_VERTEX = 2
NBR_DATA_POINTS_PER_VBO = 1000

# plot each VBO
for segment in range(segments):

    # bind the named buffer object so we can work with it.
    glBindBuffer(GL_ARRAY_BUFFER, vbos[segment])

    # specifies the location and data format of an array of vertex coordinates to use when rendering
    glVertexPointer(n_COORDINATES_PER_VERTEX, GL_FLOAT, 0, 0)

    # render primitives from array data
    glDrawArrays(GL_LINE_STRIP, 0, NBR_DATA_POINTS_PER_VBO)

This works really well, but unfortunately the there's a visual gap between the last point of the previous VBO and the first point of the next VBO. This makes sense, since the GL_LINE_STRIP is only created for the data inside each VBO.

Therefore my question: How can I achieve that the multiple VBOs are rendered as one single line, without jumps inbetween?

Upvotes: 0

Views: 1103

Answers (1)

Ani
Ani

Reputation: 10906

You can do this by

  1. Duplicating the last point in one VBO as the first point in the next VBO or
  2. Use GL_LINES instead and add the first point of the next VBO to the previous VBO.

To make an unbroken polyline, you need to share common points across VBOS (I see no other option), you may choose any method you wish.

    n_COORDINATES_PER_VERTEX = 2
    NBR_DATA_POINTS_PER_VBO = 1000

    # One extra point that is the first vertex of the next batch
    NBR_DATA_POINTS_REAL = NBR_DATA_POINTS_PER_VBO + 1

    # Use GL_LINE_STRIP and duplicate vertices
    # plot each VBO
    for segment in range(segments):

        # Duplicate
        if (not_last_segment)
            vbos[segment][NBR_DATA_POINTS_REAL - 1] = vbos[segment + 1][0];

        # bind the named buffer object so we can work with it.
        glBindBuffer(GL_ARRAY_BUFFER, vbos[segment])

        # specifies the location and data format of an array of vertex coordinates to use when rendering
        glVertexPointer(n_COORDINATES_PER_VERTEX, GL_FLOAT, 0, 0)

        # render primitives from array data
        glDrawArrays(GL_LINE_STRIP, 0, NBR_DATA_POINTS_REAL)

Something like that - it looks like you can't render all the points in one go - so I'll skip my solution that involved glDrawElements which you can use to draw an indexed mesh.

Upvotes: 2

Related Questions