So I’m trying to build a very simple decal system. Just drawing a load of quads. Where the number of quads can change on a frame-to-frame basis.
This should be trivial - I want to be able to pre-allocate a buffer of, say, a maximum limit of MAX_DECALS*4 vertices. And on any given frame, I’ll update the first N vertices in the buffer, then render them - using the first N indices in a pre-allocated index buffer (big enough for MAX_DECALS)
But Unity doesn’t appear to allow this…
Whenever the number of verts in a mesh changes, I’ve got to provide positions/normals/UVs/colours in arrays of the exact size. You can’t say ‘take this range from this array’. And I’ve got to do the same with indices. Truckloads of garbage incoming!..
I can’t see any decent workarounds. I suppose I can avoid re-allocating the vertices, and only do the indices - but then Unity will still be copying the full-length buffer around internally, even if I’m only drawing a quad.
And there’s uglier solutions involving drawing degenerate polygons rather than reallocating - drawing the whole buffer every frame, but putting all the unused verts at the same position. But that’s not a great solution either, especially on mobile.
I’ve not missed any nicer solutions have I?..
It’d be really nice to see some improvements to this interface, to make this sort of use-case more efficient. As my case (decals) really isn’t a one-off. It’s an issue faced by custom UI systems, sprite systems, particle-like-effects, and so on.