Preserving PVAs During Tessellation

In addition to just the coordinate data, we often want to preserve per-vertex information like texture coordinates, colors, and anything else relevant to a given application. As stated elsewhere, the tessellation algorithm uses the coordinates passed in the second parameter to gluTessVertex, however the pointer it returns to your callback is the third parameter to gluTessVertex. Given that, we can preserve per-vertex attributes using a strategy like:

struct PerVertexAttributes
{
    // Per-vertex Attributes to be preserved with the coordinates, e.g.:
    float texCoords[2];
    // an arbitrary number of other attributes of any type can be added here.

    // Actual coordinates for tessellator:
    double xyz[3];
};

// DURING Step 3.b.ii:
void defineAContour(GLUtesselator* tObj, PerVertexAttributes contour[], int nPointsInContour)
{
    for (int i=0 ; i<nPointsInContour ; i++)
        gluTessVertex(tObj, contour[i].xyz, &contour[i]);
}
    

Then in your GLU_TESS_VERTEX callback, you would typically do something like the following:

void tessVertexCB(void* pvaAsVoid)
{
    PerVertexAttributes* pva = reinterpret_cast<PerVertexAttributes*> (pvaAsVoid);

    // Instead of one "coordinate buffer" as we initially saw, you would have one buffer for each PVA
    // declared in PerVertexAttributes, and they would all later get sent to the GPU using glGenBuffers, et al.
	
    …
}