Sign in to follow this  
pim

Batching and transformation

Recommended Posts

Hi! I'm trying to create a 3d engine in d3d and I've come to the part where I'm coding a class to make batching of polygons easier, but I've run into a problem. The class puts vertices/indices into one index and one vertex buffer until I change the type of shape or the vertex format. Then the class flush the polys to the screen and another batch starts. The problem arises when I'm using lots of small objects (for instance 100 polys) which needs to be transformed. When using SetTransform to translate/rotate the different objects, I need to flush the buffers for EVERY shape which will result in one DrawIndexedPrimitive call for each of them. How should I solve this problem? Any suggestions? Thanks!

Share this post


Link to post
Share on other sites
Are you filling/refilling a VB/IB on every single frame? That doesn't sound healthy [oh]

Is each shape the same? that is, you're only changing the transform on a per-render basis? If so there are a few tricks...

There is a page in the SDK you might want to have a read of: Efficiently Drawing Multiple Instances of Geometry and there's also the Instancing Sample to check out.

hth
Jack

Share this post


Link to post
Share on other sites
Yes.. I'm refilling every frame.. this is because most of at least the vertex buffer data is/might be changing. I'm planning on using the class for RAD - so I don't have to set up vertex buffers and index buffers just to test some different things - but also for dynamic data. Let's say I'll have alot of splines moving around the screen for instance... when I think about it this really breaks down into a couple of different questions:

1: Let's say I've got lots of different models (like different objects/scenery in a game like warcraft 3) with different transformations. How should I render this for maximum speed? (I guess your links help here :))

2: What's the best way to render completely dynamic data? Let's say I've got a scene with 20 different rotating objects that are also deformed on a per frame basis (not in a vertex shader).

3: How would you create a class with the same functionality as opengl immediate mode? I've seen a couple of different examples but none of them take the world matrix into account..

Share this post


Link to post
Share on other sites
If you don't have to use dynamic buffers try creating static buffers for ur objects, and if you have same kind of shapes a lot, render them in a row, this way you will only have to transform and call dp for every object (and maybe to change material, if they have different). Something like this :



SetIndexBuffer
SetVertexBuffer
SetMaterial (textures, shaders, etc.)

for (int i=0; i<num_spheres; i++)
{
Transform(SphereTable[i])
DrawPrimitive
}


Also if you have totally static objects (positions doesn't change), you might want to create buffers only for materials and add those objects to them, so there would be obly 1 index & vertex buffer for each material, but watchout, don't create too big buffers.

Share this post


Link to post
Share on other sites
hmm... I guess in a game I would do something like this:

-One large v/i buffer for static terrain data
-Multiple v/i buffers for different static items and items animated on the gpu w/some sort of instancing
-One dynamic v/i buffer for dynamic data that gets filled and flushed on the run

does this sound righ or have I completely missed the point? :P

Share this post


Link to post
Share on other sites
Quote:
Original post by pim
does this sound righ or have I completely missed the point? :P

It doesn't sound unreasonable.

It's very difficult to say for definite that a particular arrangement will be "correct" for what you're wanting to do, as *good* data storage is very dependent on the types of algorithms use to manipulate it and then the algorithms used to finally display it.

For terrain, unless it's realtime-deformable, a large (or several large) static buffers is a good idea. I've always liked duplicating index data for easy quadtree usage myself, but the raw vertex data should be created as a static resource that never changes.

hth
Jack

Share this post


Link to post
Share on other sites

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