I’m making a game for PC that involves a large terrain with forests, so there are many trees, rocks etc. to be rendered. Instanced rendering fits well for low-poly meshes that
appear in large quantities, but maybe not so well for high poly objects.
I’m planning on making a renderer that supports both instanced rendering and traditional one, but I’m not sure how to store/prepare the object data.
I’ve implemented instancing before by using glUniform* to load an array of transformation matrices. The problem I’m trying to figure out is if I should
(1) first pack all object transformations into a single contiguous array and then call glUniform* once per instance group, or
(2) call glUniform* for each object transformation matrix separately before instanced draw call?
If I always had a contigous array of transformations, the obvious choice would be (1), but in practice they are not, because not all objects are visible
at the same time. So making a contiguous array for use in (1) would cost some CPU time each frame (and also some additional memory). Copying a 1000 matrices
into a single contiguous array every frame seems like a lot of work for the CPU, but is it still better than option (2)?
I could also arrange my objects into batches according to, e.g., quadtree leaves and then in those batches maintain a contiguous array of transformations.
The problem is that the granularity of those batches may not be optimal for all objects. This is also a big design desicion.