• Advertisement
Sign in to follow this  

Vertex Buffer Usage (easy..)

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

Hi all, I want to be sure I have the common vertex buffer rendering procedure right. Say I wanted to render every triangle in my scene, where some are hills, some are char meshes, etc. (i.e. more than one local coordinate system) I would put all the local coordinates of each object into the vertex buffer. Then it would just be a series of translations/rotations, and then continue to draw from the buffer, etc (alternating these 2 essentially): pD3DDevice->SetTransform( D3DTS_WORLD, &RotMatrix ); pD3DDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2 ); ...Is it faster however to not interrupt the DrawIndexedPrimitive() call with many SetTransform() calls? That is, transform the vertices to world coordinates every frame and load them into the vertex buffer every frame. Then just call DrawIndexedPrimitive() once. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by discman1028
I want to be sure I have the common vertex buffer rendering procedure right.
Do you really need such a thing? Yes, there's plenty of reason to use such things - but it's not necessarily a "one size fits all" approach that is always A Good Thing™ [smile]

Quote:
Original post by discman1028
Say I wanted to render every triangle in my scene, where some are hills, some are char meshes, etc. (i.e. more than one local coordinate system)
Are you also changing the materials (textures, shaders, render states, blending etc..) between these meshes?

Quote:
Original post by discman1028
...Is it faster however to not interrupt the DrawIndexedPrimitive() call with many SetTransform() calls?
It's difficult to say for sure. The problem you're likely to get is pipeline stalling. That is, your application is going to keep incurring the context switch for many Draw**() calls as well as potentially filling up the command queue in the driver/GPU. One of the main ideas behind making less calls to Direct3D is to maximize (potential) concurrency by not having the CPU or GPU unnecessarily waiting on each other.

It shouldn't take too much effort to write up some code to test both possibilities and then run it through PIX. Remember that PIX is your best friend in this sort of situation - it has all the information (especially if you get the appropriate IHV plugins).

Quote:
Original post by discman1028
transform the vertices to world coordinates every frame and load them into the vertex buffer every frame. Then just call DrawIndexedPrimitive() once.
This sounds very nasty - don't do it [grin]

GPU's are designed specifically to be monsters at vector/matrix mathematics - CPU's are good, but even with SSE/SSE2 a GPU will run circles around a CPU doing this sort of work. Then you've got the overhead of uploading fresh data each frame. I'd be amazed if you could get any improvement out of this strategy.

I would recommend looking into "Geometry Instancing" if you want to encode multiple objects with seperate transforms into a single draw call.

hth
Jack

Share this post


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

  • Advertisement