Sign in to follow this  

Batching in Direct3D (for 2D)

This topic is 3586 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

Right now I'm calling DrawPrimitive() for every sprite every frame, which of course created a bottleneck. Frames are drawn with a DrawFrame() function. What I was thinking of doing is when DrawFrame() is called the drawing data goes into a stl vector, one for each texture, and using z buffering. Then everything is drawn at once which means calling SetTexture(), and DrawPrimitive() once per texture per frame. The only problem is how to use translation matrices for this, because right now each frame is in a single vertex buffer, but each frame could be drawn many times per frame in different locations. The only way I can think of is creating a vertex buffer every frame. But it's my understanding that messing with VBs during rendering is bad. Is there a quicker way? I've tried d3dxsprite but I didn't notice a speed increase

Share this post


Link to post
Share on other sites
I'm not sure, is there way to check for that?

Here are the fps I get:
256 sprites, 60-80 fps
512 sprites, 60-70 fps
1024 sprites, 34 fps
2048 sprites, 23 fps

Maybe 1000+ sprites is ridiculous but drawing a frame of animation or a particle require a call to DrawPrimitive in my system and particels can add up. 1024 calls to DrawPrimitive per frame seems incredibly inefficent to me.

I have a intel 1.4 ghz with a 32mb GeForce2 MX 100/200

Share this post


Link to post
Share on other sites
Yeah 1000 DrawPrimitive calls is pretty significant, and sounds like something you want to avoid regardless. As for determining whether your app is CPU-bound or GPU-bound, I suggest looking through the techniques demonstrated in this presentation from Gamefest 2007.

As for properly instancing your particles, there's a few ways to to do that. And you're generally right that manipulating a vertex buffer is a bad idea, unless you're careful to avoid scenarios that will cause the GPU to stall while it waits for the CPU to modify the contents of the vertex buffer. I suggest having a look at Humus's excellent instancing sample, which demonstrates a few of the common techniques used for rendering large batches of particles. Of course if you're using D3D10 you can go even further than this, with its support for texture arrays, as shown in the SDK sample.

Share this post


Link to post
Share on other sites

This topic is 3586 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this