## Polygon Mesh Optimization

IDLgrPolygon objects consist of a set of vertices and, optionally, a connectivity array describing how those vertices are to be connected to form one or more polygons. Internally, IDL can identify three special types of polygonal meshes that may be represented very efficiently and therefore displayed substantially faster than individually described polygons. These special mesh types are characterized by repetitive patterns in the connectivity of the vertices. In performance terms, it is to the user's advantage to utilize this optimization whenever possible by appropriately preparing the connectivity list according to the rules described for the corresponding type of mesh. The special mesh types are as follows:

A quad strip is a connected set of four-sided polygons (see Polygon Mesh Optimization). To take advantage of accelerated quad strips, the connectivity should be set up so that the first and last vertex for one quad are the same as the second and third of the previous quad.

For example, to use a quad strip optimization for the polygons in the figure above, the connectivity for the vertices should be as follows:

```verts = [v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10 ,v11]
oPoly = OBJ_NEW('IDLgrPolygon', verts, \$
POLYGON=[4, 0, 1, 5, 4, \$
4, 1, 2 ,6, 5, \$
4, 2, 3, 7, 6, \$
4, 4, 5, 9, 8, \$
4, 5, 6, 10, 9, \$
4, 6, 7, 11, 10])
```

### Triangle Fans

A triangle fan mesh is a set of connected triangles that all share a common vertex. To take advantage of accelerated triangle fans, the connectivity should be set up so that the first vertex in every triangle is the common vertex, and the second vertex is the same as the last vertex of the previous triangle.

For example, to use a triangle fan optimization for the polygons in the left-hand figure below, the connectivity for the vertices should be as follows:

```verts = [v0, v1, v2, v3, v4, v5]
oPoly = OBJ_NEW('IDLgrPolygon', verts, \$
POLYGON=[3, 0, 1, 2, \$
3, 0, 2, 3, \$
3, 0, 3, 4, \$
3, 0, 4, 5]) ```
```
```

### Triangle Strips

A triangle strip mesh is a set of connected triangles, each of which share two vertices with the previous triangle. To take advantage of accelerated triangle strips, the connectivity should be set up so that the first two vertices in every triangle must have been in the previous triangle and ordered in the same direction (counter-clockwise or clockwise) and the final vertex must be new.

For example, to use the triangle strip optimization for the polygons in the right-hand figure above, the connectivity for the vertices should be as follows:

```verts = [v0, v1, v2, v3, v4, v5]
oPoly = OBJ_NEW('IDLgrPolygon', verts, \$
POLYGON=[3, 0, 1, 2, \$
3, 2, 1, 3, \$
3, 2, 3, 4, \$
3, 4, 3, 5])
```

No limits are imposed on the number of meshes or types of meshes within any given polygon object. A single POLYGON keyword value might contain any combination of quad strips, triangle strips, triangle fans, or non-specialized polygons.

As the length of the strips or fans grows, and as the percentage of vertex connections that are optimized by the rules described above increases, the performance upgrade becomes more perceptible. The optimizations are a result of minimizing the time required to perform vertex transforms. If the drawing of the polygons are otherwise limited by fill-rate (as might occur on some systems if texture-mapping is being applied, for instance), these optimizations may not be of significant benefit. In any case, performance will not be hindered in any way by utilizing these specialized meshes, so it is suggested that they be applied whenever possible.

 Note
The IDLgrSurface object always takes advantage of the quad mesh optimization automatically without programmer intervention.