Jump to content
  • Advertisement
Sign in to follow this  
Trillian

Batching (custom) sprites

This topic is 4340 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!