3
\$\begingroup\$

I've come to a point where optimizing my game is very much needed.My update() routine takes 0-2ms. My draw() routine takes about 100ms when drawing 3.5M triangles (Not the amount I really have to draw, but it's easier to debug.) I've noticed that reducing draw calls is more effective than reducing triangles per draw call (and keeping the amount of draw calls the same), and would primarily like to know how to do that.

I've tried creating an array, adding items to that array every frame until it has about 65535 primitives in it (the maximum xna allows per draw call) and only drawing it then, but resizing the array is a terribly slow thing to do (drawing only 250k triangles takes about 500ms)

So long story short: In XNA, how do I properly optimize the drawing methods that use DrawUserIndexedPrimitives? Or primarily, how do I properly reduce draw calls?

\$\endgroup\$
4
\$\begingroup\$

There are few simple rulrs that allways help me:

  1. cull not visible meshes using frustrum based on camera view

  2. minimize textures count: use tile maps, draw meshes with same textures in one line etc.

  3. dont create anithing in Draw method and dont create anithing you can keep and use again, like static meshes, render targets etc.

  4. if it not help use Stopwatch to see what is wrong

\$\endgroup\$
  • 1
    \$\begingroup\$ Thanks for the tips. Unfortunately, I'm already doing all of that. \$\endgroup\$ – Peethor Dec 10 '15 at 9:56
  • 1
    \$\begingroup\$ try rebuild your array parallel to game loop, use thread or coroutine for it \$\endgroup\$ – user62425 Dec 10 '15 at 10:01
  • \$\begingroup\$ Since I already had a thread running that loads the map chunks, I edited it so it also creates one big array of vertices from the chunks. My main thread then checks in "Update()" if the other thread is busy with that array. If not, It'll copy the array and draw everything using that array. This has definitely sped things up quite a bit. Thanks so much! \$\endgroup\$ – Peethor Dec 10 '15 at 13:56
  • \$\begingroup\$ Glad to help. Does "chunks" mean you created some minecraft-like engine? If so and if it's open project i'll be happy if you share a link :) Thanks. \$\endgroup\$ – user62425 Dec 10 '15 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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