tags:

views:

436

answers:

1

I'm creating an app that uses VBO's for drawing. The app draws line segments of multiple colors. Therefore, I'm creating a vertex and index array for each color, and sorting the segments into the appropriate array by color.

However, I'd like the user to be able to set the color of any line segment. Therefore, my potential number of colors is virtually unlimited (obviously not really, but it might as well be). I'm guessing that generating say 2,000 VBO's to hold 1,000 vertex and index arrays to support 1,000 colors would not be a good thing.

Obviously one could generate a limited number of VBO's and copy new data in each time it was time to draw a new color's vertex array, but that seems incredibly inefficient.

Any suggestions for handling this situation?

+1  A: 

Well, considering you're not saying what's in the vbo exactly (position? color?) or how you end up drawing (fixed function? program?) it's not exactly trivial to help.

Anyways, here are some facts you want to keep in mind:

  • you don't have to create many vbos. VBO (just like IBO) is for storage, it can store any arbitrary number of data sets. This is helped by the "firstIndex/firstVertex" parameters of the various Draw functions and other offsets of the gl*Pointer
  • your color does not have to be specified per-vertex. If you store it inside the VBO, get it out, and use constant colors (how to do that depends on your drawing method. For programs, specify color through a uniform rather than an atribute)

There, I hope that's enough for you to start.

Bahbar
Currently the VBO's are just vertex and index data. But I see your point about just using a few and storing the color data inside.
Wade Williams
hum, color _can be_ vertex data. Don't confuse vertex data and position data (if that's what you meant). and my point is to get the color _out of_ the VBO.
Bahbar
Whoops - forgot to answer the "how" question - drawing is done via glDrawElements.
Wade Williams
my question on how was more about shader or not shader. The world is very different in those 2 cases.
Bahbar