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 am building a game that is tile-based (filled with glowy vector squares). Right now, I am considering using instancing for drawing these, but I would like to know if there is a faster approach.

The squares are all of the same size. They should be rendered in a rectangular grid, and I know exactly how many of them I should render. The squares are also made with linelists (so 8 vertices for a single rectangle).

Knowing all this, is instancing still the best approach? Or can I utilize the GPU more here? (in my game, I only utilize 1% of the GPU, but 100% of the CPU).

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

You are probably hitting 100% CPU because you are at the batch limit. You get a few thousand* batches per frame. A batch is basically equivalent to a call to one of the GraphicsDevice.Draw* functions.

You probably want to read this answer.

While you can reduce the number of batches with instancing, because your geometry is so simple you are probably better off using DynamicVertexBuffer or DrawUserPrimatives to put all your geometry into a single batch. (This is the technique that SpriteBatch uses.)

For such a small amount of geometry, the cost of calculating and sending the vertex data to the GPU will be comparable to, and quite possibly better than, the cost of transmitting the instancing data.

Additionally, if your data doesn't change every frame, you should use DynamicVertexBuffer and instead of refreshing it every frame, add a ContentLost handler and then only refresh it when you need to or if the device is lost.

Obviously, if your data never changes at all you should simply build it into a single, static VertexBuffer. If what you are drawing is terrain, and it is not deformable, just have one (or more) huge (thousands of vertices) vertex buffer that you can scroll around, and let the GPU handle culling for you.

share|improve this answer
add comment

You can use geometry shader and send just one point and normal for each rectangle. In geometry shader produce for example triangle strip. But if you need texture coordinates, it could be problem.

// Deleted some Opengl info (now I have taken note that you are talking about XNA :) )

share|improve this answer
Nice answer. Also i dont think that using geometry shaders in a way you say will have problems with tex coords ;) –  Notabene Apr 21 '11 at 9:14
So where can I find more information about these shader types? –  Mathias Lykkegaard Lorenzen Apr 21 '11 at 11:13
@Mathias Don't care about it. By using XNA you are stucked with shader model 3.0 which hase only vertex and pixel shader... –  Notabene Apr 21 '11 at 21:06
add comment

Your Answer


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.