Originally posted by Guardian:
3) Would it be better if I had fixed size arrays ? I should fill those arrays and then flush them. The main avantage I see by doing this is that you don’t have to change arrays’ pointers. The main drawback is that you consume CPU time filling.
Well, after my early suggestion that was to say the least, completely wrong , I started implementing my rendering engine based on vertex arrays.
I came up with the following idea: put everything (all the objects) in a unique huge vertex array which size is defined at the start of the application.
I see several avantages in doing that.
1)I won’t have to change the pointers any time.
2)It doesn’t matter that the array is huge since I only render a max of say 1k vertices (as DFrey suggested) for each call to glDrawElements (and you have to store the data somewhere anyway, so why not in the vertex array in the first place).
3)I don’t have to copy the data from one array to another every time I render a new object.
There are obviously some complications.
If I put all my objects in the vertex array (actually the arrays since there can be texture coord, colors…) at the initialisation of the program, that’s ok, I can put their data in successive blocks of memory in the array(s).
What if I want to dynamically remove or add an object?
For that I’ve got a VertexMemoryManager class that keeps track of all the allocated chunks of memory in the vertex array via a linked list of references (pointers) to these chunks.
Then when I want to remove an object, I simply remove the reference from the list.
If I want to add an object, I look for two non-contiguous chunks in the vertex array and allocate the free memory between them to my new object until all its data has a place in the array. then I copy its data to the array and remap its indices.
This makes the loading of an object a bit slower but I think that the fact that I don’t have to either change the pointers or copy the data every frame is a more important
I’ve not tested it completely, but until now it seems viable. I was just wondering what you would think of that solution.