Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm currently working on a Worms game which involves terrain deformation. I used to do it with .GetData(), modifying the color array, then using .SetData(), but I looked into changing it to make the work done on the GPU instead (using RenderTargets).

All is going well with that, but I have come into another problem. My whole collision detection against the terrain was based on a Color array representing the terrain, but I do not have that color array anymore. I could use .GetData() every time I modify the terrain to update my Color array, but that would defeat the purpose of my initial changes.

What I would be okay with is using .GetData() once at the beginning, and then modifying that array based on the changes I make to the terrain later on by some other means. I do not know how I would do this though, can anyone help?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

I've done a bit of research, and I have yet to find a solution to getting rid of any GetData calls every time my terrain is modified, but I have found ways to "optimize" it, or at least reduce the GetData calls as much as possible.

  • Crater drawing is batched, meaning that rather than draw each one as it’s created, I add them to a list and draw all of them every few frames. This reduces the number of GetData calls – one per batch of craters rather than one per crater.

  • After drawing craters to the render target, I wait a few frames before calling GetData to make sure the GPU has processed all of the drawing commands. This minimizes pipeline stalls.

  • If I have a pending GetData call to make and more craters come in, the craters will stay batched until the GetData call is complete. In other words, the drawing and getting are synchronized so that a GetData call always happens several frames after drawing a batch of craters, and any new crater draw requests wait until after a pending GetData.

If anyone else has any other suggestions I would still be glad to hear them.

share|improve this answer
    
I was wondering: if the game is turn-based, can't you just do one GetData() call at the start of each turn? –  Jonathan Connell Jun 1 '11 at 9:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.