PDA

View Full Version : Sharing Vertices



Maunikar
01-25-2001, 11:41 AM
Ok, I've been told repeatedly that 'the only way to share vertices in OpenGL is to use vertex arrays.'

Can't for the life of me figure out how that would be.

I'm doing the landscape thing with the standard 2d array of heights. Currently, I'm using triangle strips to spit the landscape square onto the screen. Example:


.-.-.-.-.-.-.-.
|/|/|/|/|/|/|/|
.-.-.-.-.-.-.-.
|/|/|/|/|/|/|/|
.-.-.-.-.-.-.-.
|/|/|/|/|/|/|/|
.-.-.-.-.-.-.-.
Every . is a vertex, so the internal vertices get sent to the card twice (once for each triangle strip for which it is a part).

Is there some specific ordering & step combination that I can use to store these all in one vertex array, then process the array as a series of TRIANGLE_STRIPs?

Thanks in advance for any help!

Jason/Maunikar

Eric
01-25-2001, 11:23 PM
What people meant by 'the only way to share vertices in OpenGL is to use vertex arrays.' is that using vertex arrays, all vertices will be TRANSFORMED only once.

For this to work, you would specify your vertex array as being an array of all the vertices your mesh uses.

Now, you would build each triangle strip by using indices to the vertex array.

Let's try an ASCII example:




1-2-3-4
Strip 1: |\|\|\|
5-6-7-8
Strip 2: |\|\|\|
9-A-B-C


So, your vertex array will be:

[ 1 2 3 4 5 6 7 8 9 A B C]

Your first strip (using indices to this array) will be:

4 0 5 1 6 2 7 3 (i.e. the index is -1 compared to the vertex !)

The second will be:

8 4 9 5 10 6 11 7

Now, of course point 5 (index 4) is used twice but your OpenGL driver will transform it only ONCE !

Hope this will help you understand vertex arrays...

Regards.

Eric


[This message has been edited by Eric (edited 01-26-2001).]

Maunikar
01-26-2001, 06:11 AM
Ok, so it's not something special about the storage or anything, it's just some magic that goes on inside the driver...It can recognize that you're using the same exact point again, and not transform it.

The tradeoff, then, would be in storage. Since I'm using regular spacing and color dependent on the height, I'm not storing any of those values. Using the vertex array, I'd need to store x,y,z,r,b,g for each point.

Interesting. Thanks!
Jason/Maunikar

Eric
01-26-2001, 06:22 AM
Yep, in this case you would need a Color Array as well as the Vertex Array.

The Color Array is specified with glColorPointer (and guess what: it is glVertexPointer for the Vertex Array !).

Actually, if you were not storing the RGB values, it means that you somehow calculated them on the fly. Using a Color Array might speed things up here as well !

Of course, for you, the ideal solution would be to tell OpenGL to base the color upon the coordinates of the points. That is something you should be able to do using the GL_NV_vertex_program extension BUT:

1) This extension is not officially available yet.
2) It is likely that it will only be supported by nVidia's cards.
3) No current card will use hardware to accelerate this extension (which means it could actually be slower than what you are doing now !).

Anyway, that is a thought to keep in mind for the future !

Best regards.

Eric

j
01-26-2001, 06:55 AM
Ok, so it's not something special about the storage or anything, it's just some magic that goes on inside the driver...It can recognize that you're using the same exact point again, and not transform it.

Ideally, yes.

In a practical application, you can't expect the driver to catch all the redundant vertices. For example, a Geforce caches only the last 10-16 vertices you drew.

To keep your application as efficient as possible, try to keep vertices that you reuse as close to each other as possible in your index list.

j

Maunikar
01-26-2001, 07:24 AM
Originally posted by j:
In a practical application, you can't expect the driver to catch all the redundant vertices. For example, a Geforce caches only the last 10-16 vertices you drew.Ouch. Well, that'll work for my small landscape patches, but it'll probably be useless for anything nontrivial. Interesting...

I'll have to play around with it a bit and see. I have doubts that I'll see any real speed increase using them, but I'd definitely like to find out...

Jason/Maunikar