Sign in to follow this  
gangliu

poor fps

Recommended Posts

Hello all I load a bitmap(800*600) to an OffeScreenSurface. I get a poor fps(28) when copy the surface to back buffer in 32 bit color. My video card is Geforce2 Mx/mx400. I guess I have maked a mistake. This is my code :
bool 
CD3DImg::LoadImg(const std::string& sPath, int w, int h,  int nRow, int nCol)
{
    if ( !m_pD3DDevice )
    {
        return false ;
    }
    Clear() ;

    m_nRow = nRow ;
    m_nCol = nCol ;

    m_nImgWidth = w ;
    m_nImgHeight = h ;

    if ( FAILED(m_pD3DDevice->CreateOffscreenPlainSurface(
                                                w, h, 
                                                m_nD3DFmt, 
                                                D3DPOOL_SYSTEMMEM,
						 &m_pLocalImg, 
                                                NULL
                                                ) ))
    {
        return false ;
    }

    m_nTransClr = 0 ;

    if ( FAILED(D3DXLoadSurfaceFromFile(
                                m_pLocalImg, 
                                NULL, NULL, 
                                sPath.c_str(), 
                                NULL, 
                                D3DX_FILTER_NONE,
				m_nTransClr, 
                                NULL) ))
    {
        return false;
    }
    
    return true ;
}

bool
CD3DImg::Draw()
{
    IDirect3DSurface9* pBackBuffer ;
    
    //reference count ++
    if ( FAILED(m_pD3DDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer)) )
    {
        return false ;
    }
    
    FreeDxRes<IDirect3DSurface9> freeRes1(pBackBuffer) ;

    RECT rc;
    POINT pt ;
    HRESULT hr ;

    int nFrameW, nFrameH ;
    int nRow, nCol ;

    nRow = m_nCurFrame/m_nCol ;
    nCol = m_nCurFrame%m_nCol ;
    nCol = std::max<int>(nCol, 0)  ;

    ASSERT(m_nRow&&m_nCol) ;
    nFrameH = abs(m_nImgHeight)/m_nRow ;
    nFrameW = abs(m_nImgWidth)/m_nCol ;

    rc.top  = (float)nRow*nFrameH;
    rc.left = (float)nCol*nFrameW;
    rc.right  = rc.left+nFrameW ;
    rc.bottom = rc.top+nFrameH ;

    pt.x = m_Rect.left;
    pt.y = m_Rect.top ;

    hr = m_pD3DDevice->UpdateSurface(
                        m_pLocalImg, 
                        &rc,
                        pBackBuffer,
                        &pt
                        )  ;
    
    if ( FAILED(hr))
    {
        return false ;
    }

    return true ;
 }
 
Thanks for your any advice .

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this