Batching (custom) sprites

Started by
1 comment, last by Trillian 17 years, 9 months ago
Hello Gamedev! I'm developping a 2D engine and I'd like a way to batch my sprites so that my rendering is more efficient. Currently, I'm doing the following, which I am pretty sure is a very slow technique : - Hold a MyVertexStruct array of four vertices (simply MyVertexStruct v[4]) - When rendering a sprite, set the four vertices and call Device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,*,*,*); I still manage to show a couple of thousand of sprites/particles on screen but I'm sure there are better ways to do this. I've thought about using vertex buffers but I have two problems : 1- I cannot batch sprites with different textures in the same buffer and render them at once. 2- World matrices might have changed between each addition of sprites in the buffer. I've thought of using my first technique for sprites and have a special function StartBatch() to accumulate vertices which share the same texture and world matrix in a buffer (mostly for particle systems), and then call EndBatch() to draw them. Would that be the best way to do it?
Advertisement
Batching sprites isn't the easiest of challenges [smile]

Can you make use of shaders? There are a number of tricks you can play (based on instancing) that allow you to pack multiple transforms/textures into a single draw call.

I would highly recommend trying the accumulate method you suggest. It'll be fairly trivial to build a sys-mem array of 10/100/1000 sprites (note that you'll have to use triangle lists (6 verts) instead of strips) and despatch them as a single call. Simply reducing the number of API calls (especially drawing ones) should yield a nice speed-up.

Also note that you might be able to use D3DXVec4TransformArray() (or the Vec3 form) to do CPU transformations. That way you can group based on effect/texture rather than worry about transform.

Also consider any frame-coherancy... does each sprite change/move EVERY frame? Why do any more work than is necessary?

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Thanks a lot, I think I'll go with this method.

Transforming my buffered vertices with the current world matrix is a good idea. When I'll render the batched sprites, I'll simply need to set my world matix to the identity but keep the view/proj matrices, right?

As for the shaders, my engine supports them but I'd prefer not rely too much on them.

Anyways thanks for your confirmation

This topic is closed to new replies.

Advertisement