Jump to content
  • Advertisement
Sign in to follow this  
whitde

Avoiding excessive batching - D3DMATRIX

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

I have a Tokamak physics demo that renders about 20 cubes and a few planes, spheres and capsules. I store the vertex data for each in system memory and when an object is rendered I just copy the data to a global vertex array and use DrawPrimitive to render. I have a function that sets the world rotation matrix before hand to put the object at the correct location. iWorld::Set(&dxTrans); i3DPrim::Render(primCube); // Cube The problem with this approach is no batching occurs as each object will be in a different place, rotation, etc. 100 objects = 100 batches. What I want to do is pass the rotation matrix to the render function which will then apply the matrix to the vertices as they're copied to the final vertex buffer. This way I'm hoping to get multiple objects rendered. I know I have to use the matrix passed in to translate the x, y and z coordinates of the vertices but forget how :( Does anyone know off hand the correct code to do this?

Share this post


Link to post
Share on other sites
Advertisement
In this case, would think it'd be faster to have all the primitives in a single VB to begin with, then set the transform and render sections of the VB with IB s and DrawIndexedPrimitive. What you're basically describing is software vertex processing, which will all but eliminate any gains you achieve by drawing all the objects in a single DrawPrimitive call. Besides, how many polys are you rendering? I doubt it'll be much of a performance hit to draw the objects separately, just as long as they're all in the same VB.

Share this post


Link to post
Share on other sites
Actually.... the other bottleneck might be the fact I'm changing the vertex format all the time.


The engine is 2D by default and has no normals in the FVF.

However when I render a 3D primitive I change the format...render the primitive and than change the format back.

Each primitive changes the vertex format twice.

I think I have to make the vertex format swapping a bit better so it only swaps the format if needed.

Also...seeing the caching of the 3D primitives is flawed... I will store them in hardware vertex buffers which will eliminate the copying from sys memory to hardware every time.

Share this post


Link to post
Share on other sites
Managed DirectX has Vector.TransformCoordinate(Matrix). I imagine there's a similar method for CVector2 / CVector3.

Share this post


Link to post
Share on other sites
Whitde - I don't mean to sound condescending, but why are you going about drawing your objects this way? Wouldn't it be easier to just loop through all your objects, drawing each one as you go? I doubt you'll have to worry too much about batching and such at such an early stage in development. You seem to want to take the hard way of doing all this.

Additionally, there's no need to set the FVF twice for each object. Set it once to the 3D vertex format, draw all your 3D objects, then set it once to the 2D format, and draw all your sprites.

Share this post


Link to post
Share on other sites
I made an option in the class to "MoveToHardware()" that transfers the vertex buffers to a hardware vertex buffer.

Testing on the program I had...just this change incrased the framerate from ~338 to around 480 and as high as 550 which in my opinion is quite significant.

My poor little primitives don't use indexes as I have normals which I didn't want 6 triangles to share.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!