Exemplo n.º 1
0
void D3DWin8_Init()
{
    // Wait for video init before we do anything
    WaitForSingleObjectEx( g_WaitingForVideoEvent, INFINITE, FALSE );

    assert(g_Window);

    // Now go ahead :)
    QD3D11Device* device = InitDevice();

    IDXGIFactory2* dxgiFactory = nullptr;
    HRESULT hr = QD3D::GetDxgiFactory( device, &dxgiFactory );
    if ( FAILED( hr ) )
    {
        ri.Error( ERR_FATAL, "Failed to get DXGI Factory: 0x%08x.\n", hr );
        return;
    }

    // Prepare the swap chain
	DXGI_SWAP_CHAIN_DESC1 swapChainDesc;
    ZeroMemory( &swapChainDesc, sizeof(swapChainDesc) );

    GetSwapChainDescFromConfig( &swapChainDesc );

    // Set up win8 params. Force disable multisampling.
    swapChainDesc.Width = (UINT) g_WindowWidth;
    swapChainDesc.Height = (UINT) g_WindowHeight;
	swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // All Windows Store apps must use this SwapEffect.
    swapChainDesc.SampleDesc.Count = 1;
    swapChainDesc.SampleDesc.Quality = 0;

    IDXGISwapChain1* swapChain = nullptr;
    hr = dxgiFactory->CreateSwapChainForCoreWindow(
        device, 
        g_Window,
        &swapChainDesc, 
        nullptr, 
        &swapChain);

    if (FAILED(hr))
    {
        ri.Error( ERR_FATAL, "Failed to create Direct3D 11 swapchain: 0x%08x.\n", hr );
        return;
    }

    QDXGIDevice* dxgiDevice = nullptr;
    hr = QD3D::GetDxgiDevice( device, &dxgiDevice );
    if ( SUCCEEDED( hr ) )
    {
		// Ensure that DXGI does not queue more than one frame at a time. This both reduces latency and
		// ensures that the application will only render after each VSync, minimizing power consumption.
        dxgiDevice->SetMaximumFrameLatency(1);
    }

    InitSwapChain( swapChain );

    SAFE_RELEASE( swapChain );
    SAFE_RELEASE( device );

    // release the main thread
    SetEvent( g_WaitingForVideoFinishedEvent );
}
Exemplo n.º 2
0
//----------------------------------------------------------------------------
// Creates a window, initializes the driver and sets up Direct3D state.
//----------------------------------------------------------------------------
D3D_PUBLIC void D3DWnd_Init( void )
{
	ri.Printf( PRINT_ALL, "Initializing D3D11 subsystem\n" );

    if ( !RegisterWindowClass() )
    {
        //ri.Error( ERR_FATAL, "Failed to register D3D11 window class.\n" );
        //return;
    }


    // @pjb: todo: fullscreen stuff
    bool fullscreen = r_fullscreen->integer != 0;

    cvar_t* vid_xpos = ri.Cvar_Get ("vid_xpos", "", 0);
    cvar_t* vid_ypos = ri.Cvar_Get ("vid_ypos", "", 0);

    g_hWnd = CreateGameWindow( 
        vid_xpos->integer,
        vid_ypos->integer,
        vdConfig.vidWidth, 
        vdConfig.vidHeight,
        fullscreen);
    if ( !g_hWnd )
    {
        ri.Error( ERR_FATAL, "Failed to create Direct3D 11 window.\n" );
        return;
    }

	QD3D11Device* device = InitDevice();

    // @pjb: todo: do these based on cvars (or if not set, pick the best one)
    DXGI_SWAP_CHAIN_DESC1 scDesc;
	ZeroMemory( &scDesc, sizeof(scDesc) );
    scDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
    
    GetSwapChainDescFromConfig( &scDesc );

    // @pjb: todo: set fullscreen based off config
    DXGI_SWAP_CHAIN_FULLSCREEN_DESC fsd;
    ZeroMemory( &fsd, sizeof(fsd) );
    fsd.Windowed = TRUE;

    IDXGISwapChain1* swapChain = nullptr;
    HRESULT hr = QD3D::CreateSwapChain(device, g_hWnd, &scDesc, &fsd, &swapChain);
    if (FAILED(hr))
    {
        // @pjb: todo: if swapchain desc is too fancy, fall back
        ri.Error( ERR_FATAL, "Failed to create Direct3D 11 swapchain: 0x%08x.\n", hr );
        return;
    }

    InitSwapChain( swapChain );

    SAFE_RELEASE( swapChain );
    SAFE_RELEASE( device );

    ::ShowWindow( g_hWnd, SW_SHOW );
    ::UpdateWindow( g_hWnd );
	::SetForegroundWindow( g_hWnd );
	::SetFocus( g_hWnd );
}