• Advertisement


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


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

Ok I setup everything and then break it down into .h/.cpp files. So now I have a lot of classes and structs etc. But now everything runs VERY slow.. here is my D3DInit Function, DrawScene, and window functions: Why are they so slow? bool Direct3DInit() { Direct3D.Create(&Window); // Now create the world here so it is setup with all the values TheWorld.Create(0.0f,0.0f,0.0f); // WorldLight.CreateLight(D3DXVECTOR3(0,0,-8), 255, 255, 255, 1000.0f, D3DLIGHT_POINT, Direct3D.pDevice); // Make it so that it''ll draw triangles facing either towards or away from the camera d3dResult=Direct3D.pDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW ); if (FAILED(d3dResult)) CErr.write_errorex("SetRenderState( D3DRS_CULLMODE..Failed.", d3dResult); d3dResult=Direct3D.pDevice->SetRenderState( D3DRS_LIGHTING, FALSE); if (FAILED(d3dResult)) CErr.write_errorex("SetRenderState( Disable lighting Failed.", d3dResult); //Enable the ZBuffer d3dResult=Direct3D.pDevice->SetRenderState( D3DRS_ZENABLE, TRUE ); if (FAILED(d3dResult)) CErr.write_errorex("SetRenderState( D3DRS_ZENABLE Failed.", d3dResult); //Perspective Matrix D3DXMATRIX persMatrix; D3DXMatrixPerspectiveFovLH(&persMatrix, D3DX_PI/6, 640/480, 1.0, 100.0); Direct3D.pDevice->SetTransform(D3DTS_PROJECTION, &(D3DXMATRIX)persMatrix); // View Matrix ViewCam.vMatrix = CreateCam(0, 0, 40, ViewCam, CAM_START, Direct3D.pDevice); //World Matrix // D3DXMatrixIdentity(&TheWorld.matWorld); // //Set our World Matrix // Direct3D.pDevice->SetTransform(D3DTS_WORLD,&TheWorld.matWorld ); D3DXMatrixRotationY( &TheWorld.matWorld, D3DX_PI/180); Direct3D.pDevice->SetTransform( D3DTS_WORLD, &TheWorld.matWorld ); ////////////////////////////////// ////////////// XModel.SetupModel(Direct3D.pDevice, "seafloor.x"); //////////////////////////// /////////////////////////// return true; } void UpdateScene( void ) { } void DrawScene() { Direct3D.Clear(D3DCOLOR_XRGB(0, 0, 0)); Direct3D.BeginScene(); D3DXMATRIX matWorld; D3DXMatrixRotationY( &matWorld, timeGetTime()/1000.0f ); Direct3D.pDevice->SetTransform( D3DTS_WORLD, &matWorld ); XModel.DrawModel(Direct3D.pDevice); Direct3D.EndScene(); Direct3D.Present(); } void Direct3DRelease() { Direct3D.Release(); } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { bool bFullScreen; // Ask the user whether or not they want to run in fullscreen if (MessageBox(NULL, "Run Fullscreen?", "Izzy Q?", MB_YESNO)==IDYES) bFullScreen=true; else bFullScreen=false; Window.MakeWindow(hInstance, "Izzy3D Game Programing Library: Beta .1", "Izzy", 100, 100, 300, 300, bFullScreen); // 0, 0, 640, 480, Direct3DInit(); while(1) { if (Window.CheckMessages()==-1) break; // Quit if the users presses escape if (GetAsyncKeyState(VK_ESCAPE)) PostQuitMessage(0); // Update the scene each frame UpdateScene(); // Draw the scene each frame DrawScene(); } // Release Direct3D Direct3DRelease(); return 0; } Thanks, chris

Share this post

Link to post
Share on other sites
Its very unlikely to be anything in the code you posted (we have an engine with far more going on in its frame performing just fine.)

Go to the DirectX control panel applet and select the debug runtime. Also bump the slider up to halfway or greater.

Run the app again in debug mode or with a debug viewer attached, after its finished running look at the debug output window. Thats the first thing to when looking for clues - if you''re mistreating the API it will give you warnings there - if you''re doing something really silly it''ll tell you.

Assuming you''re not expecting miracles (eg. "why doesn''t the API render this 2 billion poly model at 60fps on my S3 ViRGE"), there are a few places you may be doing something bad:

* Device creation - check that vertex processing type carefully. [silly thought - you have created a HAL device havent you ?]

* Buffer creation - index and vertex buffers. Use Default memory type. If you''re on a software VP device, make sure you have software vertex processing set, and vice versa. If you''re going to update the contents of the buffer (ie. lock it, fiddle with stuff, unlock it) every frame make sure you have it set to DYNAMIC, if you aren''t make sure it isn''t.

* Buffer locks - if you''re locking a buffer (VB or IB) every frame - it should be dynamic, preferably write only, and you ***MUST*** use the lock flags in the correct way (check out the DirectX SDK FAQ (at msdn.microsoft.com/directx) or other replies I''ve written here) - don''t just DISCARD or NOOVERWRITE every frame because it''ll do bad things and SLOOOWW things.
If the buffer isn''t created as dynamic - DON''T use those flags on it... ever.

* Texture creation - use managed - D3D and the driver end up doing the right thing for the hardware. If you have a valid reason not to use auto managed, use Default.

* Clear - particularly on nVidia H/W - if you have a stencil buffer set, ALWAYS clear it at the same time you clear the Z buffer and vice versa - otherwise the clear takes about 3 times longer (they share memory, it has to read, mask, write).

* Texture minification - if a texture is shrunk when rasterised onto a polygon (ie. the texture is much bigger than it is shown on screen), it can be a performance hit - use mipmaps - voila no hit.

* Don''t expect miracles - more textures than VRAM per frame, massive vertex shaders in software (may run a slower than H/W T&L...), a billion screen sized polygons all alpha blended (bye bye fillrate).

Theres plenty of other little things too... you treat the API badly, it then treats the driver badly in return which treats the hardware badly which then sulks and performs dog slow......

Simon O''''Connor
Creative Asylum Ltd

Share this post

Link to post
Share on other sites
Man am I a fool. Awhile ago I was checking out how my REF would do instead of HAL.. Just thought I''d check when you mentioned it but man I saw this line:

d3dErr=pDirect3D->CreateDevice( D3DADAPTER_DEFAULT, /*D3DDEVTYPE_HAL*/D3DDEVTYPE_REF, pWindow->hWnd,
&presentParameters, &pDevice );

So thanks a lot for your help.. thanks,

Share this post

Link to post
Share on other sites

  • Advertisement