View Full Version : Vertex Arrays
04-10-2003, 11:08 AM
I'm beginning to implement vertex arrays into a simple application. What is the best method to do this?
I have some code to draw a sphere with divisions similar to latitude and longitude but made of tristrips (lets say approx 100 tris per strip with 50 strips). Should each slice be a separate array (50 changes of vertex pointer, color pointer, texcoord pointer, etc, and 50 calls to glDrawArrays for each sphere object)? Or should it all be combined into 1 large array? And if so, what is the best way to combine multi tri strips into a single array? If I overlap vertices within a tristrip (or even a quadstrip) to make a turn(?) what happens?
Thanks in advance
[This message has been edited by shinpaughp (edited 04-10-2003).]
I fear you cannot simply but everything in a single array since the strips are independant one from the another - I mean, the first three vertices of a strip belongs to a single triangle. If you just blend all the strips togheter you will get 3 triangles in the wrong place instead of the first (new strip's triangle) in the right place. Of curse the whole strip would be ruined up.
Tip1: Try to not use DrawArrays. DrawElements should be faster since you're got **lots** of shared vertices. DrawArrays can be used the first times though, so you don't have to build the indices but replace it as soon as possible.
Tip2: you may put everything in a single array (so you don't need pointer changes), but you need to issue multiple DrawArrays / DrawElements to begin/end strips correctly. You have to use a bit of care while drawing the strips togheter since some vertices are "special" (beginning of the strip).
Tip3 (applies to Tip2): EXT_multi_draw_arrays should allow you to draw multiple primitives with just a single call. I am not really sure however, I don't remember right now. You may also want to check out NV_primitive_restart but this is a young extension and so it is not really supported.
Hope this helps.
04-11-2003, 01:02 PM
Thanks Obli. http://www.opengl.org/discussion_boards/ubb/smile.gif
I'll take a look at the extensions you mentioned as well as using elements.
Basically, you sort your geometry by texture and then you render a group of polys that share the same texture. This way you don't have to set glBindTexture() state so often which yields faster performance. Nowdays, people sort by shader first then by texture or some other criteria because changing shaders is slower than changing textures. You should check out the new vertex buffer object docs. I think indexed triangle strips are the fastest following by indexed tri lists. Avoid quads and polys since driver has to triangulate them and that takes time. Better you do it beforehand. Just some thoughts http://www.opengl.org/discussion_boards/ubb/smile.gif
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.