Archived

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

Dark Metamorphosis

optimization under directx 9.0

Recommended Posts

hi every one, I hope my post belongs to the right place. so I am trying to optimize my game. I am currently using c++ and directx, and I am implementing an octree. but here is the probleme: (based on a static scene) 1/should I create one index buffer and one vertex buffer, load them with the data once and release them at exit time. and for the rendering make the octree childs store the primitives that have to be drawn (using for each child an array of ints that would store the indices), and so use a for loop on DrawIndexedPrimitive(). OR SHOULD I 2/store the vertices and indices in the octree, and for each frame (about 33ms) initialize a vertex and index buffer with the data of the seen octree childs,(by using the lock, memcpy, unlock), render and then release the buffers. Please I do really need help in this, because I don''t know which methode is faster, I think the first one is great if the scene is static, and nothing would require the change of the buffers, but again calling DrawIndexedPrimitive() for each face is a bit scary. And would the size of the buffers affect the speed of the game ? (since the buffers are going to exist all along the game). please, if you have any clue, tell me. Thanks to every one.

Share this post


Link to post
Share on other sites
Agony    3452
It sounds like what you want are dynamic buffers. You mentioned creating/releasing buffers every frame. This is a no-no. If you create your buffers with a usage of D3DUSAGE_DYNAMIC, then here''s how you use them: At the beginning of a frame, you call Lock(...) on the buffers. You then use your octree to fill in all the information. You call Unlock() on the buffers. You then call DrawIndexedPrimitive(...). You never have to create or release the buffers, except at the beginning and end of your program.

The Lock() call can still take some time, though, depending on the flags you use. In this case, you''ll probably want to use the flag D3DLOCK_DISCARD. This tells DirectX that you don''t care what data was previously in the buffer; you simply want to write new data. This allows it to keep the old data elsewhere, while letting you enter new data. Thus, if the GPU is currently rendering the previous frame, and is using your buffers, the Lock() won''t stall the card, because it can go on merrily rendering the old data, while you write new data to the buffer.

Note that you''ll have to create your buffers with D3DPOOL_DEFAULT, which means that you''ll have to manage releasing them and recreating them, in case of a Reset() call.

Share this post


Link to post
Share on other sites
so Agony, you mean I just create one index and vertex buffers and let them carry all the scene, and make the octree hold the indices/faces that have to be passed to DrawIndexedPrimitive().
and if so, would it mind if I call the DrawIndexedPrimitive() as many times as the faces I am going to draw? (since I am going to use an array of ints in the octree in wich each int is a face ID.)

Share this post


Link to post
Share on other sites