Archived

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

Direct Graphics optimization problems

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

well, my scene only has around 50 textured polygons in it and is already slowing down... under 40fps. I''m running a fairly fast computer(i can run games like rogue spear at 50fps) so that isnt the problem. I think the main problem is i''m using g_pd3dvertexbuffer->lock(...) and unlock() every single time i draw a polygon. And each frame starts cleared, nothing is kept from the previous frame. Here''s a function i use to draw sidewalks, hopefully someone can pick out what im doing wrong: VOID DrawSidewalkl(FLOAT x, FLOAT z, INT count) { CUSTOMVERTEX sidewalk[] = { { x-10.0f, 1.0f, z+tz, 0x00444444, 0.0f, 30.0f }, { x-10.0f, 1.0f, z, 0x00444444, 0.0f, 0.0f }, { x, 1.0f, z+tz, 0x00444444, .9f, 30.0f }, { x, 1.0f, z, 0x00444444, .9f, 0.0f }, { x, 0.0f, z+tz, 0x00222222, 1.0f, 30.0f }, { x, 0.0f, z, 0x00222222, 1.0f, 0.0f }, }; g_pd3ddevice->CreateVertexBuffer(6*sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pvbsidewalkl[count]); VOID *pBuildingf; g_pvbsidewalkl[count]->Lock(0, sizeof(sidewalk), (BYTE**)&pBuildingf, 0); memcpy(pBuildingf, sidewalk, sizeof(sidewalk)); g_pvbsidewalkl[count]->Unlock(); g_pd3ddevice->SetTexture( 0, g_ptexsidewalkl); g_pd3ddevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); g_pd3ddevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); g_pd3ddevice->SetStreamSource(0, g_pvbsidewalkl[count], sizeof(CUSTOMVERTEX)); g_pd3ddevice->SetVertexShader(D3DFVF_CUSTOMVERTEX); g_pd3ddevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 4); } Thanks in advance.

Share this post


Link to post
Share on other sites
Why do you create a vertex buffer and fill it every frame? That's your primary problem (you are also changing state too much for this specific example, though that is less of a problem and may be required if other polys/vbs you add later have to have a different state).

Create the vertex buffer once and then draw it every frame. You don't have to keep creating it over and over. You do have to pay attention somewhat to events that might cause the vertex buffer to be flushed, especially if you aren't using D3DPOOL_MANAGED VBs or texture surfaces. See "Managing Resources" in the DirectX Docs for more details. Also, the fact that you aren't releasing the vertex buffer you are creating each frame probably causes additional problems, memory leak with a side effect of slowing the app down even further (particularly in a hardware T&L situation).



Edited by - gmcbay on June 28, 2001 12:11:29 AM

Share this post


Link to post
Share on other sites
Why in the world are you setting the vertex for the sidewalk every single time. Man locking and unlocking memory is really hurting you. You really didn''t give much info but I would say that you need to load in all your sidewalks at the beggining of the program in a function lets say LoadResourses(), and when you want to render just use:
void RenderSideWalk()
{
g_pd3ddevice->SetTexture( 0, g_ptexsidewalkl);
g_pd3ddevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
g_pd3ddevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
g_pd3ddevice->SetVertexShader(D3DFVF_CUSTOMVERTEX);
for(int i=0;i<3;i++)//lets say you have 3 sidewalks
{
g_pd3ddevice->SetStreamSource(0, g_pvbsidewalkl, sizeof(CUSTOMVERTEX));

g_pd3ddevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 4);
}

}

Man I hope that helps. If not e-mail me gavrhen@hotmail.com.

Share this post


Link to post
Share on other sites
made another newbie mistake. thanks for the advice, i fixed it and my performance has increased 100 fold. Im now running 70+fps, thanks again, and i''ll do my research next time before i post.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The lock/unlock per frame is expensive, but in some cases (not yours) necesary. For example, if doing skinning in SW.

However, that''s only responsible for a small percentage of your performance hit.

CreateVertexBuffer() is a dog, and should only be used at startup and device recreation.

K

Share this post


Link to post
Share on other sites