Ejemplo n.º 1
0
ref_ptr<PrimitiveSet> VTXReader::processStrip(unsigned short * indexArray,
        std::istream * str,
        int offset)
{
    VTXStrip                strip;
    DrawElementsUShort *    drawElements;
    ref_ptr<PrimitiveSet>   primSet;
    unsigned short *        start;
    unsigned short *        end;

    // Seek to the strip
    str->seekg(offset);

    // Read it.  We have to do this in a kind of screwy way because of the
    // weird byte packing.  Valve uses pragma pack, but we can't do that
    // because it's non-portable.  Of course, I'm assuming a 4-byte alignment
    // here, which might also be non-portable...
    str->read((char *) &strip, VTX_STRIP_SIZE - 8);
    str->read((char *) &strip.num_bone_state_changes, 8);

    // Get the range of indices in question from the strip
    start = &indexArray[strip.index_offset];
    end = &indexArray[strip.index_offset + strip.num_indices];

    // Create the primitive set (based on the flag)
    if (strip.strip_flags & STRIP_IS_TRI_LIST)
        drawElements =
            new DrawElementsUShort(PrimitiveSet::TRIANGLES, start, end);
    else
        drawElements =
            new DrawElementsUShort(PrimitiveSet::TRIANGLE_STRIP, start, end);

    // Flip the indices to get the front faces correct
    std::reverse(drawElements->begin(), drawElements->end());

    // Return the primitive set
    primSet = drawElements;
    return primSet;
}