# What's efficient way to draw a lot of textured cubes in XNA4?

Title says it all.

What's efficient way to draw a lot of textured cubes in XNA4?

• This seems very broad. Have you tried anything yet? Did you try to do it yourself and it's working too slowly? Aug 5, 2011 at 2:23
• How many is "a lot"? A thousand and a million are both "a lot" to draw. Expanding on what Drackir said, what is your current approach and what is wrong with it? Aug 5, 2011 at 3:12
• This question is probably a good place to start. Aug 5, 2011 at 6:09
• The answer will always boil down to the same thing : Instancing. Whether that's hardware instancing, or shader instancing, or transforming everything on the cpu and cramming it into a big vertex buffer, it'll still be : Instancing. Aug 5, 2011 at 12:38

I guess it is for another minecraft-inspired game, so "a lot" means several million cubes :) Well, be it minecraft, warcraft, XNA, OGL or whatever else, the task of drawing "a lot of anything" consists of two parts:

• Reducing the size of the task.
• Making the actual drawing efficient.

It's possible to write an entire book about these problem facets, so let's keep it simple.

How to reduce the amount of the cubes you need to worry about? Use octrees and perform frustum culling for visibility determination.

How to optimize the draw method for lots of cubes? Large number of cubes (maybe even all of them depending on your approach) will share the same material, so it will be easy to utilize instancing.

Then again, depending on how much "a lot" actually is, you may want to stop caring about rendering optimizations at all. With the modern hardware you can draw like ten million of textured cubes easily with almost no hassle: just divide them into large chunks and draw with basic batching and a simple index buffer.

Have a look at this SunBurn instancing example: http://indiefreaks.com/2011/01/27/hardware-instancing-with-igf-sunburn-rd-part-1/ and then part 2 http://indiefreaks.com/2011/01/28/hardware-instancing-with-igf-sunburn-rd-part-2/ It handles massive amounts of instanced objects.