Esempio n. 1
0
//-----------------------------------------------------------------------------
// Name : ResetDisplay ()
// Desc : Reset the display device, and optionally the window etc.
//-----------------------------------------------------------------------------
HRESULT CD3DInitialize::ResetDisplay( LPDIRECT3DDEVICE9 pD3DDevice, CD3DSettings& D3DSettings, HWND hWnd )
{   
    D3DPRESENT_PARAMETERS d3dpp = BuildPresentParameters( D3DSettings );
    CD3DSettings::Settings *pSettings   = D3DSettings.GetSettings();

    if ( hWnd )
    {
        // Setup styles based on windowed / fullscreen mode
        if ( !D3DSettings.Windowed )
        {
            SetMenu( hWnd, NULL );
            SetWindowLong( hWnd, GWL_STYLE, WS_VISIBLE | WS_POPUP );
            SetWindowPos( hWnd, NULL, 0, 0, pSettings->DisplayMode.Width, pSettings->DisplayMode.Height, SWP_NOZORDER );
        
        } // End if Fullscreen
        else
        {
            SetWindowLong( hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW );
            SetWindowPos( hWnd, HWND_NOTOPMOST, 50, 50, 800, 600, SWP_NOACTIVATE | SWP_SHOWWINDOW );

        } // End if Windowed

    } // End if

    // Reset the device
    HRESULT hRet = pD3DDevice->Reset( &d3dpp );
    if ( FAILED( hRet ) ) return hRet;

    // Success
    return S_OK;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Summary: Resets the device
Returns: TRUE on success. FALSE on failure
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
BOOL CGraphics::Reset()
{
    if ( m_pDevice )
    {
        if ( !BuildPresentParameters() )
        {
            return FALSE;
        }
        m_pDevice->Reset( &m_pp );
    }

    return TRUE;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Summary: Initializes Direct3D.
Parameters:
[in] hWnd - Handle to the window
[in] windowed - TRUE for windowed mode, FALSE for fullscreen mode
Returns: TRUE on success. FALSE on failure
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
BOOL CGraphics::Initialize( HWND hWnd, BOOL windowed )
{
    Windowed = windowed;
    m_hWnd = hWnd;
    SAFE_RELEASE( m_pD3D9 );
    SAFE_RELEASE( m_pDevice );
    m_pD3D9 = Direct3DCreate9( D3D_SDK_VERSION );
    if ( !m_pD3D9 )
    {
        SHOWERROR( "Direct3DCreate9() - Failed", __FILE__, __LINE__ );
        return FALSE;
    }

    m_pD3D9->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &m_displayMode );
    m_pD3D9->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &m_caps );

    // Check for hardware T&L
    DWORD vertexProcessing = 0;
    if ( m_caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
    {
        vertexProcessing = D3DCREATE_HARDWARE_VERTEXPROCESSING;
		// Check for pure device
		if ( m_caps.DevCaps & D3DDEVCAPS_PUREDEVICE )
		{
			vertexProcessing |= D3DCREATE_PUREDEVICE;
		}
    }
    else
    {
        vertexProcessing = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
    }

    if ( !BuildPresentParameters() )
	{
        SAFE_RELEASE( m_pD3D9 );
        return FALSE;
	}

    HRESULT hresult = 0;
    // Create the device
    hresult = m_pD3D9->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWnd, vertexProcessing, &m_pp, &m_pDevice );
    if ( FAILED( hresult ) )
    {
        SAFE_RELEASE( m_pD3D9 );
        SHOWERROR( "CreateDevice() - Failed", __FILE__, __LINE__ );
        return FALSE;
    }
    return TRUE;
}
Esempio n. 4
0
//-----------------------------------------------------------------------------
// Name : CreateDisplay ()
// Desc : Creates the display devices ready for rendering.
//-----------------------------------------------------------------------------
HRESULT CD3DInitialize::CreateDisplay( CD3DSettings& D3DSettings, ULONG Flags, HWND hWnd, WNDPROC pWndProc, LPCTSTR Title, ULONG Width, ULONG Height, LPVOID lParam )
{
    ULONG                   CreateFlags = 0;
    CD3DSettings::Settings *pSettings   = D3DSettings.GetSettings();
    
    if ( !hWnd )
    {
        // Register the new windows window class.
        WNDCLASS			wc;	
	    wc.style			= CS_BYTEALIGNCLIENT | CS_HREDRAW | CS_VREDRAW;
	    wc.lpfnWndProc		= pWndProc;
	    wc.cbClsExtra		= 0;
	    wc.cbWndExtra		= 0;
	    wc.hInstance		= (HINSTANCE)GetModuleHandle(NULL);
        wc.hIcon			= NULL;
	    wc.hCursor			= LoadCursor(NULL, IDC_ARROW);
	    wc.hbrBackground	= (HBRUSH )GetStockObject(WHITE_BRUSH);
	    wc.lpszMenuName		= NULL;
	    wc.lpszClassName	= Title;
	    RegisterClass(&wc);

        ULONG Left  = CW_USEDEFAULT, Top = CW_USEDEFAULT;
        ULONG Style = WS_OVERLAPPEDWINDOW;

        // Create the rendering window
        if ( !D3DSettings.Windowed )
        {
            Left   = 0; Top = 0;
            Width  = pSettings->DisplayMode.Width;
            Height = pSettings->DisplayMode.Height;
            Style  = WS_VISIBLE | WS_POPUP;
	        
        } // End if Fullscreen

        // Create the window
        m_hWnd = CreateWindow( Title, Title, Style, Left, Top, Width, Height, NULL, NULL, wc.hInstance, lParam );

        // Bail on error
        if (!m_hWnd) return E_FAIL;

    } // End if no Window Passed
    else
    {
        // Store HWND
        m_hWnd = hWnd;
        
        // Setup styles based on windowed / fullscreen mode
        if ( !D3DSettings.Windowed )
        {
            SetMenu( m_hWnd, NULL );
            SetWindowLong( m_hWnd, GWL_STYLE, WS_VISIBLE | WS_POPUP );
            SetWindowPos( m_hWnd, NULL, 0, 0, pSettings->DisplayMode.Width, pSettings->DisplayMode.Height, SWP_NOZORDER );
        
        } // End if Fullscreen
        else
        {
            RECT rc;

            // Get the windows client rectangle
            GetWindowRect( hWnd, &rc );

            // Setup the window properties
            SetWindowLong( m_hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW );
            SetWindowPos( hWnd, HWND_NOTOPMOST, rc.left, rc.top, (rc.right - rc.left), (rc.bottom - rc.top), SWP_NOACTIVATE | SWP_SHOWWINDOW );

        } // End if Windowed
    
    } // End if window passed

    // Build our present parameters
    D3DPRESENT_PARAMETERS d3dpp = BuildPresentParameters( D3DSettings );
    
    // Build our creation flags
    CreateFlags = Flags;
    if ( pSettings->VertexProcessingType == PURE_HARDWARE_VP )
        CreateFlags |= D3DCREATE_PUREDEVICE | D3DCREATE_HARDWARE_VERTEXPROCESSING;
    else if ( pSettings->VertexProcessingType == HARDWARE_VP )
        CreateFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
    else if ( pSettings->VertexProcessingType == MIXED_VP )
        CreateFlags |= D3DCREATE_MIXED_VERTEXPROCESSING;
    else if ( pSettings->VertexProcessingType == SOFTWARE_VP )
        CreateFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;

    // Find any PerfHUD adapter
    for ( UINT Adapter = 0; Adapter < m_pD3D->GetAdapterCount(); Adapter++ ) 
    { 
        D3DADAPTER_IDENTIFIER9 Identifier; 
        HRESULT Res; 
        Res = m_pD3D->GetAdapterIdentifier( Adapter, 0, &Identifier ); 
        if ( strstr( Identifier.Description, "PerfHUD" ) != 0 )
        {
            pSettings->AdapterOrdinal = Adapter; 
            pSettings->DeviceType     = D3DDEVTYPE_REF; 
            printf( "PerfHUD adapter = %i\n", Adapter );
            break; 

        } // End if PerfHUD

    } // Next Adapter

    // Create the device
    m_pD3DDevice = NULL;
    HRESULT hRet = m_pD3D->CreateDevice( pSettings->AdapterOrdinal, pSettings->DeviceType,
                                         m_hWnd, CreateFlags, &d3dpp, &m_pD3DDevice );
    // Did the creation fail ?
    if ( FAILED( hRet ) ) 
    {
        if ( m_pD3DDevice ) m_pD3DDevice->Release();
        m_pD3DDevice = NULL;
        return hRet;
    } // End if failed

    // Success
    return S_OK;
}