Jump to content
  • Advertisement
Sign in to follow this  

Slow engine. Have 6 fps displaying 300 triangles untextured

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

Seems to have a major problem with my direct3d (directx 9) engine. Have implemented a very basic engine and have tried to display a number of triangles to see how fast it could run. Ony triangle runs with approximate 130 fps. Adding two triangles more, placing them somewhat behind the previous ones, I get 100 fps. When drawing 300 triangles, I get 6 fps. I have enabled the Z buffer. some code: // Filling up my vertex buffer with 300 triangles Vertex vertex[2000]; for(int j=0; j<300;j++) { z+=0.01; initVertex(vertex, i++, -4.0f, -3.0f, z, D3DCOLOR_XRGB(255,0,0)); initVertex(vertex, i++, 3.0f, 1.0f, z, D3DCOLOR_XRGB(255,0,0)); initVertex(vertex, i++, 3.0f, -3.0f, z, D3DCOLOR_XRGB(255,0,0)); } dxDev->CreateVertexBuffer(nrVertices*sizeof(Vertex), D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT, &dxVB, NULL); VOID* pVertices = NULL; dxVB->Lock(0, sizeof(vertex), (void**)&pVertices, 0); memcpy(pVertices, vertex, sizeof(Vertex)*nrVertices); dxVB->Unlock(); This is done only once ( in the start of main) Then in the main loop I just call drawPrimitive with 300 triangles. Z buffer is enabled. viewmat, projmat, worldmat is initialized. How many triangles should a basic engine be able to handle?

Share this post


Link to post
Share on other sites
Advertisement
Is that in your game loop?

I don't think your supposed to initialize the vertex every iteration...

I don't know what you're doing with z, but it looks like your trying to achieve maybe transformations of some sort (i have no clue), and you really should use matrix transformations for transformations of any type instead of just rendering the vertex in the transformed spot.

Maybe you can post more code ?

Share this post


Link to post
Share on other sites
it sounds like you're calling a 'for' loop with a DrawPrimitive inside it. If so, then that's really bad unless you must draw one triangle at a time. You should batch as many in as few DrawPrimitive calls as possible because it's an expensive (but necessary) function. Any standard engine should handle at least 100,000 triangles at 60 fps on today's hardware (if not using too much fancy stuff).

Share this post


Link to post
Share on other sites
This for loop is for batching the vertexbuffer with 300 triangles. This for loop is done once only in the beginning of main. The render loop looks like this:

directx.dxDev->Clear(0, NULL, D3DCLEAR_TARGET| D3DCLEAR_ZBUFFER , 0x00FFFFFF, 1.0f, 0 );

directx.dxDev->BeginScene();

dxDev->SetFVF(D3DFVF_CUSTOMVERTEX);
dxDev->SetStreamSource(0, dxVB, 0, sizeof(Vertex));
dxDev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 300);

font.drawFPS();

directx.dxDev->EndScene();
directx.dxDev->Present(NULL, NULL, NULL, NULL );


Share this post


Link to post
Share on other sites
Does someone have code to display a couple of thousands of polygon. Can't figure out what the problem is... Would be nice be nice to download sourcecode for such a basic engine/program

Share this post


Link to post
Share on other sites
How big are the triangles? You might have a fillrate bottleneck. Also, related to this, what graphics card do you have?

Share this post


Link to post
Share on other sites
Set your PresentationInterval in the present parameters to D3DPRESENT_INTERVAL_IMMEDIATE. If it should still be running higher, i would think it is an initialization error with some params to dx.

Share this post


Link to post
Share on other sites
It may be a fillrate bottleneck. I have thought about this. Because it seems to be really slow when drawing large triangles ( filling the screen), with small triangles it gets much faster. But it i still very slow I think. How do you handle fillerate bottlenecks?

I have also ran the program in NVIDIAS NVPerfhud which is a program to test possible bottlenecks in your engine. And I get quite strange results there. It says that the gpu is constantly idle..

graphic card is NVIDIA GeForce 3

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Are you using the debug device?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
actualy, i mean the software device!!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!