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.

Platform and language agnostically, how is sprite batching defined? It seems as though there are many different techniques for lessening the amount of work when drawing, and that they are often lumped with "batching". It occurs to me that there may not be a real answer, but perhaps someone here has found something I have not.

share|improve this question
add comment

3 Answers

up vote 8 down vote accepted

Technically, "batching" is putting multiple actions and their data into one data structure so it all can be executed at once rather than individually.

The biggest bottleneck of modern GPUs is not their working power, but the communication between your game running on the CPU and the GPU. Each package of data sent to the GPU has an overhead, but the overhead of a small package is just as big as that of a big package, so it's a big gain when you send one big package rather then a hundred smaller ones. And that's what batching is; making one big package out of all those smaller ones.

Batching is particularly useful for sprites because of the ridiculously small amount of data per sprite; four vertices and four tex coords. So the overhead of the small package is proportionally big.

share|improve this answer
    
+1 for mentioning the latency problem; this is the very same principle as also applies to network traffic and disk I/O - in the general case, very few big batches trumps lots of small batches. –  Jimmy Shelter Jul 24 '12 at 19:07
add comment

It's not a tightly-defined technical term. Batching is basically any system where you perform multiple operations as a set rather than individually, and often this is done because it's more efficient to do so. The efficiency gains usually come from being able to re-use some or all of the context that the operation requires.

So, sprite batching is just any system that lets you draw multiple sprites at once and hopefully gain some efficiency from it. Usually the benefit is that your sprite batch is all using the same texture, so you can draw all the sprites in the batch without changing texture, which is a relatively slow operation.

share|improve this answer
add comment

Sprite batching is the method of submitting multiple sprites to the GPU with a single draw call.

Neither of the other answers point out the real point of doing this: minimizing state changes and GPU command submissions. If you have 100 sprites I draw, each with their own texture, the hardware can only process one sprite at a time. The dozens or even thousands of shader cores end up barely being utilized, and the GPU spends far too much time configuring its render state for texture switches.

If you put all your sprite images into an atlas, you can minimize the state changes needed to draw. The driver may even be able to automatically combine sprite draw requests into a single batch so that the hardware can be fully utilized, but this is not guaranteed or likely.

If you use a sprite atlas and then create a single VBO with all your sprites quads filled into it, an make a single draw request with that data, you are guaranteed that the hardware is fully utilized and all of your sprites are rendered in parallel.

Sprite batching then is doing that very thing: putting as many of your sprites as possible into a single VBO using a single atlas that is submitted to the GPU with a single draw call, maximizing GPU usage.

There are other ways to do sprite batching (like hardware instancing, using geometry shaders, etc), and other benefits to doing so, but the gist of it is that batching means drawing multiple objects per draw call.

share|improve this answer
    
-1: Minimizing the state changes isn't "the point" of the batching. It's just a requirement comming from the way OpenGL is structured. (It is the point of texture atlases, but those weren't asked for.) The question specifially asks for a "Platform and language agnostically" definition. –  Mr. Beast Jul 24 '12 at 20:17
    
So the method of drawing everything to a backbuffer first solves this problem how? Isn't the data still being manipulated one at a time to a single image in memory, and then pushed to the front buffer? I think my understanding must be a bit flawed. –  Bloodyaugust Jul 25 '12 at 15:06
1  
Mr. Beast: it has nothing to do with OpenGL or any platform or language. It's how the very hardware itself actually works, on all platforms and all graphics APIs using any language. –  Sean Middleditch Jul 26 '12 at 1:13
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.