Slow engine. Have 6 fps displaying 300 triangles untextured

Started by
23 comments, last by CBT 18 years, 10 months ago
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?
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 ?
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                          
Looking for video game music? Check out some of my samples at http://www.youtube.c...ser/cminortunes            
                                                          
I'm currently looking to create music for a project, if you are interested e-mail me at cminortunes@gmail.com    
                                                          
Please only message me for hobby projects, I am not looking to create music for anything serious.
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).
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 );


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
How big are the triangles? You might have a fillrate bottleneck. Also, related to this, what graphics card do you have?

Niko Suni

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.
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
Are you using the debug device?
actualy, i mean the software device!!

This topic is closed to new replies.

Advertisement