Archived

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

Incredibly slow drawprimitive?

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

I am trying to rotate a simple triangle, and it works quite well. Then, just to see how much it can handle, I put a simple for loop around the drawprimitive, like so: //^ initialize vertex[3] before ^ d3dvb->Lock(0,sizeof(CUSTOMVERTEX)*3,&pBuffer,0); memcpy(pBuffer,vert,sizeof(CUSTOMVERTEX)*3); d3dvb->Unlock(); for(int i=0; i<500; i++) {  d3ddev->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 ); } This sticks my framerate to below 2fps on an ATI Radeon VE (32mb ddr) I am sure my card can handle more than 1000 triangles/sec, so what gives?

Share this post


Link to post
Share on other sites
i think you are getting slow frame rate because everytime you enter your drawing loop, you are drawing it 500 times. You should apply your rotation outside of the drawing loop and draw the triangle once for each added rotation. I may be wrong, i am just assuming from that piece of code. later-

what we do in life... echoes in eternity...

Share this post


Link to post
Share on other sites
Well, yeah, the code works fine without that 500 loop. What I was trying to simulate was a case where I have a much more complicated scene, with (in this case) 500 triangles. The actual number will probably be closer to 1000 or above, so I really need a faster way of doing this. I''ll post my entire rendering code, just for kicks:

(please excuse the indentation, but I don''t know how to format text in these forums, and I''m not going to put nbsp''s everywhere)

//////////////////////////////////////////////////////////////////////////////
//MAIN GAME LOOP
//////////////////////////////////////////////////////////////////////////////
void Prog_Loop()
{
BYTE* pBuffer;

d3ddev->Clear(0,NULL,D3DCLEAR_TARGET,0,1.0,0);
d3ddev->SetStreamSource(0,d3dvb,sizeof(CUSTOMVERTEX));

//start the scene
d3ddev->BeginScene();
//set up the vertex positions
vert[0].x=cos(angle)*240.0+320.0-60;
vert[0].y=sin(angle)*240.0+240.0;
vert[1].x=cos(angle+2*PI/3)*240.0+320.0-60;
vert[1].y=sin(angle+2*PI/3)*240.0+240.0;
vert[2].x=cos(angle-2*PI/3)*240.0+320.0-60;
vert[2].y=sin(angle-2*PI/3)*240.0+240.0;
d3dvb->Lock(0,sizeof(CUSTOMVERTEX)*3,&pBuffer,0);
memcpy(pBuffer,vert,sizeof(CUSTOMVERTEX)*3);
d3dvb->Unlock();

//I realize that this for loop is completely useless.
//I have it in here only to simulate a more complex scene.
for(int i=0; i<500; i++) {
d3ddev->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 );
}

//end the scene
d3ddev->EndScene();

//add to the angle for next time
angle+=(PI/180);//180;
if(angle>=2*PI) angle=angle-2*PI;
d3ddev->Present(NULL, NULL, NULL, NULL);

}//End Prog_Loop

Share this post


Link to post
Share on other sites

You are not making the best use of the DrawPrimitive call in this case (or so it would appear). It looks like your buffer is only large enough for a single triangle at a time and, as a result, your DrawPrimitive call is only rendering one triangle at a time. I would suggest creating a larger vertex buffer (in this case create a buffer large enough to hold 500 triangles) and copy all your vertex data into it. Then call the DrawPrimitive function with the parameters DrawPrimitive(D3DPT_TRIANGLELIST,0,500). This will render all 500 triangles in one chunk rather than rendering one at a time.

Share this post


Link to post
Share on other sites