VBO vs immediate mode.

My program will draw a 100000 of lines. And each line is consist of Begin point and End Point (2 vertex per line). I want to draw each line seperately because the user may freeze(hide)certain lines while using the program. Currently I am using the immediate mode
glBegin(GL_LINES);

glEnd();
to draw the lines.

I use the Vertex Array method to draw the lines seperately but it’s slower than the immediate mode. Does anyone know why?

Using vertex arrays will give significant improvement if you use one call for let’s say 1000 lines.

If you don’t have to modify vertex coordinates for lines then you could try the following approach:
Init:

  1. create and pass vertex array
    Render:
  2. create index array containing indices only for these lines you need to draw
  3. use one call to glDrawElements to render all lines

Since user will not hide/show lines every single frame, you don’t have to reconstruct index array every time.

Originally posted by k_szczech:
[b] Using vertex arrays will give significant improvement if you use one call for let’s say 1000 lines.

If you don’t have to modify vertex coordinates for lines then you could try the following approach:
Init:

  1. create and pass vertex array
    Render:
  2. create index array containing indices only for these lines you need to draw
  3. use one call to glDrawElements to render all lines

Since user will not hide/show lines every single frame, you don’t have to reconstruct index array every time. [/b]
Thanks for the reply.

If say this is a CAD program which user may remove selected lines or add additional lines into the line list. Will the method suggested above improve the performance? If not, any other suggestion. Thanks.

Immediate mode should not be that bad.

In the case of a CAD program, generally users will add lines, but won’t remove them so much. So you can take a slightly different approach than k_szczech proposed (but remains quiete the same):

. allocate a quiete significant amount of memory in the graphic card (for VBO vertices only)
. keep a map of all lines created on cpu side
. each time a user add a line, then copy it into the vbo and alter the map in consequence
. each time the user delete a line, then delete it from the vbo and alter the map in consequence
. if no more memory is available, then allocate a second buffer
. …

for all adds/removes, check first your map. For all new vertices, add them to the map, for all deleted vertices, check if they aren’t used for other lines, if so delete them.

jide’s suggestion is good. I believe it would be for adding/removing lines (editing) - as you mentioned in your second post.
For just temporarily hiding lines modifying index array only should be more efficient (viewing) - that’s what you mentioned in first post.

That means our approaches are actually addressed towards different problems and can be used simlutaneously (jide’s concept layered on top of mine).

I have a few question here.

  1. allocate a quiete significant amount of memory in the graphic card (for VBO vertices only)
    Do you means to create an array of double data to
    store all the vertices of the lines?

  2. keep a map of all lines created on cpu side.
    What is “map” here? Is it a link list which store all the line objects?

For example, you can allocate a buffer that will be able to store let say 1000 vertices. Allocate with the type you use, but I suggest to use float instead of double. doubles are not optimized and often casted into float by the hardware.

If you use C++ as programming language, then you can use an std::map<int,float*> for example, where float* points to the vertex and int is the index of that vertex in your vertex array.
Depending on your needs you can try other structures like simple arrays, trees…

hope that helps

I got it. I think I know what you means. I am using C# (Tao framework) for development. No more powerfull pointer, too bad :frowning: . Anyway, thanks a lot.

Hi jide,

I have implemented the method that you have suggested. It really improve the performance tremendously, But I am facing one problem. If say we have 10 lines, some of them have differents thickness and stipple pattern. How do you render them with glDrawElements(…)? Any idea?

The best way is simply to group them by thickness and pattern. Say for example one VBO/map per such any kind of lines.