wadesworld
wadesworld

Reputation: 13753

Managing OpenGL VBO's and color

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?

Upvotes: 0

Views: 2071

Answers (1)

Bahbar
Bahbar

Reputation: 18015

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.

Upvotes: 1

Related Questions