SkeletonComponent is nice and tricky eh? Avoiding allocation with Unity is a huge bitch. 🙁
1) Look at how indexes are calculated:
for (int i = 0; i < indexCount; i += 6, vertexIndex += 4) {
indexes[i] = vertexIndex;
indexes[i + 1] = vertexIndex + 2;
indexes[i + 2] = vertexIndex + 1;
indexes[i + 3] = vertexIndex + 2;
indexes[i + 4] = vertexIndex + 3;
indexes[i + 5] = vertexIndex + 1;
}
For regions which are quads, it is always the same order, but it is based on the vertex. If the first vertex in the index list is already for the vertex we need it to be, there is no reason to compute all the indexes again
they are already as we need.
2) The number of triangles can change, but only for the last submesh. This is because we can write zeros so we have degenerate triangles which should be skipped by the GPU. The idea is that this is cheaper than allocating a new array.
Computing indexes isn't really a big deal, though if it is cheap to avoid it, why not. Uploading triangle indexes to the GPU is wasteful if they don't need to be updated. It probably makes the most sense to have multiple renderers:
1) For drawing from a single material, no submesh nonsense. The indexes are computed when the vertices array is allocated and then never changed. In normal OpenGL land the indexes can be uploaded to the GPU and never changed, ideally this can be done in Unity. The code gets a lot simpler, like it used to be.
2) For drawing from multiple materials, basically the submesh stuff we have now. Indexes are updated every frame. No way around it, this is the same thing PolygonSpriteBatch in libgdx does. Maybe the existing optimizations can be kept, eg by flagging a submesh as containing a mesh attachment. If it doesn't, assume the indices are in order and can be reused for region attachments. Maybe this isn't worth it.