Archived

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

Milos

Vertex Lock Vs DrawPrimitiveUP

Recommended Posts

Would it be faster if I substited per frame vertex buffer locks and rendering with DrawPrimitive with DrawPrimitiveUP call to render from the array itself ??

Share this post


Link to post
Share on other sites
I very much doubt it. As long as you''re not doing something stupid like locking and unlocking the vertex buffer many times per frame with only a few vertices filled in each time (if you are doing this, then you should be collecting the vertices during the frame and then doing a single lock, fill, unlock per vertex buffer, preferably with only one or two vertex buffers).

DrawPrimitiveUP does the same or more work as you''re doing with your own buffer, it locks and fills an internally created vertex buffer and then draws from it. So basically, you should only use DrawPrimitiveUP if you really don''t care about speed (like when you''re just testing something). Otherwise, although it may work well enough, you run the risk of getting bad performance simply because you''re not controlling the pipeline yourself, and therefore haven''t optimised it for your application.

Hope that helps,

John B

Share this post


Link to post
Share on other sites
Hey there,

Basically, You NEVER want to use drawPrimitiveUP. It is one of the slowest methods out there (not to mention sloppy). If you properly create and lock your vertex buffers, you will not have that much of an issue with speed.

¬_¬

Share this post


Link to post
Share on other sites
Thanks. I am using transformed vertices for lens flares, mouse and one more thingy in the engine. And these vertex buffers are locked only when update is needed. I guess that there is no significant drawback then?

Share this post


Link to post
Share on other sites
When i created my 2d game engine i had it so every sprite called a function called place_Sprite().

place_Sprite() created a standard 2d square on the screen using a temp array full of the data passed to the function, set the texture of the sprite, and displayed it using DrawPrimativeUP. This function was called to display all my sprites, which were in a linked list. Basically:


while(enemyList->prev != NULL) {
place_Sprite(enemyList->x, enemyList->y, enemyList->width,enemyList->height, &enemyList->data.tex);
enemyList=enemyList->prev;
}


And:


void place_Sprite(FLOAT x, FLOAT y, FLOAT width, FLOAT height, LPDIRECT3DTEXTURE8* g_pTexture) {

temp[0].x=x;
temp[0].y=y;
...fill rest of temp with passed data

g_pd3dDevice->SetTexture( 0, *g_pTexture);
g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
g_pd3dDevice->SetVertexShader(D3DFVF_CUSTOMVERTEX);
g_pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP , 2 , temp , sizeof ( MASTERSTRUCT ) ) ;
}


So each call of the function would have had to Lock/Unlock the buffer each time, so i used DrawPrimativeUP() and passed it an array full of the data passed to the function.

Speed wise it worked ok on all the machines i tested it on (ranging from a 400mhz -70fps). Not sure if i will use this in my 3d game. I'd be happy to hear from anyone suggesting an alternative to this approach :-)

Hope this helps you in some way :-)
Aaron

[edited by - Weeks on November 6, 2002 9:57:11 PM]

Share this post


Link to post
Share on other sites
I have never tried to use dynamic vertex buffers. What is the main idea behind it? I think I got a picture that it''s a buffet that I will be appending, is this correct?

-Milos

Share this post


Link to post
Share on other sites
Basically, normal vertex buffers are designed to be written to once, and never locked again. If you lock it again, you will suffer a performance hit. If you are planning on writing to a buffer more than once, you should make it dynamic. When you make a vertex buffer dynamic, you make write to it as many times as you want. Each write still takes some time, but it *considerably* less than a static vertex buffer.

Note that with any buffer, it is best to write a lot of data to it all at once, and have fewer larger buffers than many small buffers.

This is at least how I have learned it. Niyaw has written a very good article on vertex buffers here (note that it is still in "production"):

http://niyaw.cjb.net/articles/d3d_resources.html

Hope this helps!

fuzztrek

¬_¬

Share this post


Link to post
Share on other sites