Archived

This topic is now archived and is closed to further replies.

Trajar

D3D optimization (Please Read)

Recommended Posts

Trajar    122
OK.. I have hit a wall with the 3D pipeline for my next game. I use TLVertexes and I need to find the most efficient (aka Speedy) way to render them. I thought about using DPIVB, but I can''t find a good example (Microsoft''s SDK is gibberish) and I have heard that to use a VB with TLVertex means that I have to clip the poly''s by hand. That''s no fun. So then, assuming I''m right, what would be the next best way? DPI? DPS? Thanks in advance...

Share this post


Link to post
Share on other sites
WitchLord    4678
I can''t confirm wether D3D clips transformed vertices or not (I need to check this once I get the time) but I do know that if it doesn''t clip them in a vertex buffer then it wont clip them using regular vertex arrays either. So if you are correct you will need to do the clipping yourself.

- WitchLord

Share this post


Link to post
Share on other sites
MrFlibble    312
If I remember correctly with TL vertices the only clipping
that will be done is if they lie inside the guard band.
Other wise you may cause a crash if they are not clipped.

VB''s can have the clipping turned on/off but this is
only done at creation time so you should choose wether
you want it or not. The clipping is done either when
you use the ProcessVertices call to transform vertices
to TL vertices or through the Draw*Prim calls. But only
_IF_ clipping is turned on in the renderstates (always
remember that).

This is all going from memory so don''t quote me on wether
it''s right =)

--
Code..reboot..code..reboot..sigh!

Share this post


Link to post
Share on other sites
Trajar    122
Well maybe I should look back at VBs... Anyone have a code snippet/tutorial I can use?

Witchlord - I looked through your particle system demo and couldn''t make much sense. Are you dicarding/creating a new buffer every frame? How efficient is that?

Thanks

Share this post


Link to post
Share on other sites
WitchLord    4678


Well, the vertex buffer it self isn''t re-created each frame. But with the flag DISCARD_CONTENTS (or something like that ) I let Direct3D decide if it is faster to give me a pointer to new memory or to the old memory. By doing it this way I am actually increasing the performance if the is a rendering going on from the vertex buffer as I try to lock it, because now D3D can just give me some other memory instead of waiting for the rendering to finish.

It''s the same reason for the NO_OVERWRITE flag. I tell D3D that I will not change the previous contents so it doesn''t have to wait for the rendering to complete before returning from the Lock() function.

These two flags are the reason why Vertex Buffers are faster than regular vertex arrays, plus the fact that D3D copies vertex arrays to internal vertex buffers before rendering them so that it can add clipping information and the likes.



- WitchLord

Share this post


Link to post
Share on other sites
Trajar    122
How do you access them individually? I have seen the formula with the SDK examples/tutorials and it didn''t really click.

Also I have other questions..

1) Do they have to be the same texture state

2) You pass vectors into the buffer, I assume you can pass in the whole vertex (as I use TL''s)

3) Does the order of the vertexes define the order in which they are rendered?

There are more.. but I''ll stop there.

Thanks in advace,
Trajar

Share this post


Link to post
Share on other sites
WitchLord    4678
1) No you can change texture stage states between calls to DrawPrimitiveVB() or DrawIndexedPrimitiveVB()

2) Yes, you can pass in whole vertices. When you create the vertex buffer you tell D3D what format the vertices should have with the Flexible Vertex Format flags.

3) The order of the vertices only define the order they are rendered if you use DrawPrimitiveVB(). With DrawIndexedPrimitiveVB() you also give a list of indices that define the order the vertices should be rendered. Although even with indexed primitive you should try to sort the vertices (as good as possible) in the order they will be used to increase the performance even more.

The vertex buffers work just as your ordinary vertex arrays does. Once you have locked the buffer to receive a pointer to the buffer memory you set the vertices just as you would with the vertex arrays.

- WitchLord

Share this post


Link to post
Share on other sites