XNA VertexBuffer.SetData performance suggestions
- by CodeSpeaker
I have a 3d world in a grid layout where each grid cell contains its separate vertex and index buffer for the mesh/terrain of that cell.
When the player moves outside the boundaries of his cell, i dynamically load more cells in his walking direction based on his viewing distance. This triggers x number of vertex and indexbuffer initializations depending on how many cells that needs to be generated and causes the framerate to drop annoyingly during this time.
The generation of terrain data is handled in a separate thread and runs smoothly.
The vertex and index buffers are added during the update cycle of the game loop.
I´ve tried batching the number of cells to be processed to avoid sending too much data at once into the buffers, which worked ok at a shorter viewing distance (about 9 cells to process), but not as well at greater distances with around 30 cells to process.
Any idea how i can optimize this?