示例#1
0
//////////////////////////////////////////////////////////////////////////////////////////
//
// CSettingsSA::OnSelectDevice
//
// return 0 for single adapter
// return 1 for multi adapter hide dialog
// return 2 for multi adapter show dialog
//
//////////////////////////////////////////////////////////////////////////////////////////
int CSettingsSA::OnSelectDevice( void )
{
    if ( GetNumAdapters() > 1 && g_pCore->GetDeviceSelectionEnabled() )
    {
        // Show device selection
        return 1;
    }

    SetValidVideoMode();

    if ( GetNumAdapters() > 1 )
    {
        // Hide device selection
        return 2;
    }
    else
    {
        return 0;
    }
}
示例#2
0
//////////////////////////////////////////////////////////////////////////////////////////
//
// CSettingsSA::SetValidVideoMode
//
// Set/validate the required video mode
//
//////////////////////////////////////////////////////////////////////////////////////////
void CSettingsSA::SetValidVideoMode( void )
{
    bool bValid = false;
    int iWidth, iHeight, iColorBits, iAdapterIndex;
    bool bAllowUnsafeResolutions = false;

    // First, try to get MTA saved info
    if ( !bValid )
    {
        bValid = g_pCore->GetRequiredDisplayResolution( iWidth, iHeight, iColorBits, iAdapterIndex, bAllowUnsafeResolutions );
    }

    // Otherwise deduce from GTA saved video mode
    if ( !bValid )
    {
        SetAdapter( 0 );
        uint numVidModes = GetNumVideoModes();
        if ( VAR_SavedVideoMode > 0 && VAR_SavedVideoMode < numVidModes )
        {
            VideoMode modeInfo;
            if ( GetVideoModeInfo( &modeInfo, VAR_SavedVideoMode ) )
            {
                iWidth = modeInfo.width;
                iHeight = modeInfo.height;
                iColorBits = modeInfo.depth;
                iAdapterIndex = 0;
                bValid = true;        
            }
        }
    }

    // Finally use default
    if ( !bValid )
    {
        bValid = true;
        iWidth = 800;
        iHeight = 600;
        iColorBits = 32;
        iAdapterIndex = 0;
    }

    // Set adapter
    if ( (uint)iAdapterIndex >= GetNumAdapters() )
        iAdapterIndex = 0;
    SetAdapter( iAdapterIndex );

    // Save desktop resolution
    {
        m_iDesktopWidth = 800;
        m_iDesktopHeight = 600;

        VideoMode currentModeInfo;
        if ( GetVideoModeInfo( &currentModeInfo, GetCurrentVideoMode() ) )
        {
            m_iDesktopWidth = currentModeInfo.width;
            m_iDesktopHeight = currentModeInfo.height;
        }
    }

    // Handle 'unsafe' resolution stuff
    if ( IsUnsafeResolution( iWidth, iHeight ) )
    {
        if ( bAllowUnsafeResolutions )
        {
            // Confirm that res should be used
            SString strMessage = _("Are you sure you want to use this screen resolution?" );
            strMessage += SString( "\n\n%d x %d", iWidth, iHeight );
            if ( MessageBoxUTF8( NULL, strMessage, _("MTA: San Andreas"), MB_YESNO | MB_TOPMOST | MB_ICONQUESTION ) == IDNO )
                bAllowUnsafeResolutions = false;
        }

        if ( !bAllowUnsafeResolutions )
        {
            // Force down to desktop res if required
            iWidth = m_iDesktopWidth;
            iHeight = m_iDesktopHeight;
        }
    }

    // Ensure res is no smaller than 640 x 480
    iWidth = Max( 640, iWidth );
    iHeight = Max( 480, iHeight );

    // Find mode number which best matches required settings
    uint uiUseVideoMode = FindVideoMode( iWidth, iHeight, iColorBits );

    // Set for GTA to use
    VAR_CurVideoMode = uiUseVideoMode;
    VAR_SavedVideoMode = uiUseVideoMode;
    VAR_CurAdapter = iAdapterIndex;
}
示例#3
0
// Set required graphics adapter for output
bool spoutDirectX::SetAdapter(int index)
{
	char adaptername[128];
	IDXGIAdapter* pAdapter = nullptr;

	g_AdapterIndex = D3DADAPTER_DEFAULT; // DX9
	g_pAdapterDX11 = nullptr; // DX11

	// Reset
	if(index == -1) {
		return true;
	}

	// printf("spoutDirectX::SetAdapter(%d)\n", index);

	// Is the requested adapter available
	if(index > GetNumAdapters()-1) {
		// printf("Index greater than number of adapters\n");
		return false;
	}

	if(!GetAdapterName(index, adaptername, 128)) {
		// printf("Incompatible adapter\n");
		return false;
	}

	// Set the global adapter pointer for DX11
	pAdapter = GetAdapterPointer(index);
	if(pAdapter == nullptr) {
		// printf("Could not get pointer for adapter %d\n", index);
		return false;
	}

	// Set the global adapter pointer for DX11
	g_pAdapterDX11 = pAdapter;
	// Set the global adapter index for DX9
	g_AdapterIndex = index;

	// LJ DEBUG - in case of incompatibility - test everything here

	// 2.005 what is the directX mode ?
	DWORD dwDX9 = 0;
	ReadDwordFromRegistry(&dwDX9, "Software\\Leading Edge\\Spout", "DX9");

	if(dwDX9 == 1) {

		// Try to create a DX9 object and device
		IDirect3D9Ex* pD3D; // DX9 object
		IDirect3DDevice9Ex* pDevice;     // DX9 device
		pD3D = CreateDX9object(); 
		if(pD3D == NULL) {
			// printf("SetAdapter - could not create DX9 object\n");
			g_AdapterIndex = D3DADAPTER_DEFAULT; // DX9
			g_pAdapterDX11 = nullptr; // DX11
			return false;
		}
		pDevice = CreateDX9device(pD3D, NULL); 
		if(pDevice == NULL) {
			// printf("SetAdapter - could not create DX9 device\n");
			pD3D->Release();
			g_AdapterIndex = D3DADAPTER_DEFAULT; // DX9
			g_pAdapterDX11 = nullptr; // DX11
			return false;
		}
		pD3D->Release();
		pDevice->Release();
		// printf("SetAdapter - created DX9 device OK\n");
	}
	else {
		// Try to create a DirectX 11 device
		ID3D11Device* pd3dDevice;
		pd3dDevice = CreateDX11device();
		if(pd3dDevice == NULL) {
			// printf("SetAdapter - could not create DX11 device\n");
			// Close it because not initialized yet and is just a test
			pd3dDevice->Release();
			g_AdapterIndex = D3DADAPTER_DEFAULT; // DX9
			g_pAdapterDX11 = nullptr; // DX11
			return false;
		}
		// printf("SetAdapter - created DX11 device OK\n");
	}


	return true;

}