2011-02-17 107 views
1

我一直在搜寻各种网站,寻找正确的方式来管理切换。DirectX 11从全屏切换 - >窗口问题

我以为我已经破解了它,但现在我已经注意到了一个奇怪的问题,那就是我正在为绘制调用设置顶点和像素着色器。

我可以使用alt-enter切换到全屏模式,一切正常,可以退出空白窗口或正确渲染,但不会继续渲染任何更新。

即,它将基本上呈现一帧,并且任何输入都被注册但屏幕上不可见,直到您切换到全屏。

它清楚我可能会丢失swapchain或devicecontext的东西,因为我注意到使用Flush()它会强制它工作,但我意识到这显然不是解决方案。

渲染函数片断,它被传递的高度/宽度从WM_SIZE情况下

if(FAILED(swapChain_->GetFullscreenState(&fullScreen, nullptr))) 
     OutputDebugStringA("Failed to get fullscreen state.\n"); 

    swapChain_->GetDesc(&swapChainDesc); 
    swapChainDesc.Windowed = !fullScreen; 
    swapChainDesc.Flags = 0; 
    if(fullScreen) 
     swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; 
    //Release renderTarget, depth stencil, depth stencil view, etc 

    depthStencilView_->Release(); 
    depthStencil_->Release(); 
    renderTarget_->Release(); 

    if(FAILED(swapChain_->ResizeBuffers(swapChainDesc.BufferCount,width,height, swapChainDesc.BufferDesc.Format ,swapChainDesc.Flags))) 
    { 
     MessageBox(NULL, "Failed to resize buffers.", "Error", MB_OK); 
     return false; 
    } 

    //recreate everything that was released 
    if(!createRenderTarget()) 
     return false; 
    if(!createDepthStencils(width,height)) 
     return false; 


    context_->OMSetRenderTargets(1, &renderTarget_, depthStencilView_); 
    D3D11_VIEWPORT vp; //Should be a member of dx! 
    vp.Width = (float)width; 
    vp.Height = (float)height; 
    vp.MinDepth = 0.0f; 
    vp.MaxDepth = 1.0f; 
    vp.TopLeftX = 0; 
    vp.TopLeftY = 0; 
    context_->RSSetViewports(1, &vp); 

交换链设置与此

DXGI_SWAP_CHAIN_DESC swapChainDesc; 
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc)); 
swapChainDesc.BufferCount = 1; 
swapChainDesc.BufferDesc.Width = width; 
swapChainDesc.BufferDesc.Height = height; 
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 
swapChainDesc.BufferDesc.RefreshRate.Numerator = 0; //auto =0, originally 60 
swapChainDesc.BufferDesc.RefreshRate.Denominator = 0; 
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; 
swapChainDesc.OutputWindow = hWnd; 
swapChainDesc.SampleDesc.Count = 1; 
swapChainDesc.SampleDesc.Quality = 0; 
swapChainDesc.Windowed = TRUE; 

我一直在测试这个

cube_.setToContext(context); 
    context->VSSetConstantBuffers(0, 1, &cb_NeverChanges_); 
    context->VSSetConstantBuffers(1, 1, &cb_ResizeChanges_); 
    context->VSSetConstantBuffers(2, 1, &cb_FrameChanges_); 

    context->PSSetConstantBuffers(0, 1, &cb_NeverChanges_); 
    context->PSSetConstantBuffers(1, 1, &cb_ResizeChanges_); 
    context->PSSetConstantBuffers(2, 1, &cb_FrameChanges_); 

    context->VSSetShader(vertexShader_, nullptr, 0); 
    context->PSSetShader(pixelShader_, nullptr, 0); 
    context->Draw(cube_.getVertexTotal(), 0); 

    dx_.getSwapChain()->Present(0,0); 

大小功能与D3D11_CREATE_DEVICE_DEBUG和没有错误/警告/泄漏,任何评论或输入欢迎。

+0

出于好奇,我添加了D3D10_CREATE_DEVICE_SINGLETHREADED标志以及调试标志,这些似乎解决了这个问题。 我猜我需要检查以确保另一个线程交换时不活动? – wookey 2011-02-18 15:17:36

回答

1

最新的NVIDIA驱动程序已经解决了这个问题(驱动程序275.33)的gtx460和gtx570测试。

显然有一个软件的解释和回答这个问题,但它的工作现在,这就是我想要的。

任何人在将来阅读本文并偶然发现其他修复请让我知道。

1

从D3D10移植到11后,我遇到了与我的应用程序相同的问题。从全屏模式切换到窗口模式时,所有内容都是空白的。安装最新的GeForce硬盘解决了这个问题(没有任何代码改变)。