Archived

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

cecelski

Directx9 Rendering speed.

Recommended Posts

I am having a problem with the speed at which my program is running. I've cut execution of everything but the rendering function, and I am still getting a constant 40 fps. I am using a vertex buffer that at the most is rendering 450 triangles per cycle and another buffer that is used to render at most 64 lines along with it. The following is my rendering code:
  
void ktg_Render() {
    void *gcVB;
    HRESULT hr;
    int numvert;
    RECT drawrect;
    unsigned int currenttime = GetTickCount();
    static char fps[20];
    static count = 0;

    count++;
    if( (currenttime-fpstimer) >= 1000 ) {
        fprintf( kt_output, "%i fps\n", count );
        count = 0;
        fpstimer = currenttime;
    }
   
    numvert = NUM_VERTICES / 3;

    hr = KTGD3D_DEVICE->TestCooperativeLevel();

    if( WINDOW_RESIZE ) {
        if( FAILED( Re_Create_ktg() ) )
            return;
    }
    else if( hr != D3D_OK ) {
        if( SUCCEEDED( KTGD3D_DEVICE->Reset( &D3Dpp ) ) ) {
            if( KTGVBUFFER != NULL)
                KTGVBUFFER->Release();

            if( KTGNXTPCBUFF != NULL)
                KTGNXTPCBUFF->Release();
            
            if( FAILED( ktg_InitVbuffers() ) )
                return;
            
            if( FAILED( KTGVBUFFER->Lock( 0, ( NUM_VERTICES * sizeof( ktgVertex ) ), (void**)&gcVB, D3DLOCK_DISCARD ) ) ) 
                return;
            
            memcpy( gcVB, CURR_VERT, ( NUM_VERTICES * sizeof( ktgVertex ) ) );
            KTGVBUFFER->Unlock();

            Set_NextPiece( nextPc_added, next_pc_ornt );
            
        }
        else {
            if( FAILED( Re_Create_ktg() ) )
                return;
        }
    }
    KTGD3D_DEVICE->Clear( 0, NULL, D3DCLEAR_TARGET, 0xFF000000, 0.0f, 0 );

    KTGD3D_DEVICE->Clear( 3, GAMEWINDOWS, D3DCLEAR_TARGET, 0xFF000033, 1.0f, 0);

    /* Begin the scene */
    hr = KTGD3D_DEVICE->BeginScene();
    
    KTGD3D_DEVICE->SetStreamSource( 0, KTGVBUFFER, 0, sizeof(ktgVertex) );
    KTGD3D_DEVICE->SetFVF( D3DFVF_ktgVertex );
    KTGD3D_DEVICE->DrawPrimitive( D3DPT_TRIANGLELIST, 0, numvert);

    KTGD3D_DEVICE->SetStreamSource( 0, KTGNXTPCBUFF, 0, sizeof(ktgVertex) );
    KTGD3D_DEVICE->SetFVF( D3DFVF_ktgVertex );
    KTGD3D_DEVICE->DrawPrimitive( D3DPT_TRIANGLELIST, 0, NUM_FILLED_NXTPC_VERTS / 3);

    if( GRIDON ) {
        KTGD3D_DEVICE->SetStreamSource( 0, KTGGRIDBUFF, 0, sizeof(ktgVertex) );
        KTGD3D_DEVICE->SetFVF( D3DFVF_ktgVertex );
        KTGD3D_DEVICE->DrawPrimitive( D3DPT_LINELIST, 0, NUM_GRID_VERTICES/2 );
    }

    hr = KTGD3D_DEVICE->EndScene();

    hr = KTGD3D_DEVICE->Present( NULL, NULL, NULL, NULL);
}
  
Is there another approach I should be taking when I render the scene. Thanks for any help! [edited by - cecelski on May 2, 2003 2:47:54 PM]

Share this post


Link to post
Share on other sites