c++ - DirectX 11 从全屏切换 -> 窗口问题

标签 c++ directx directx-10 directx-11

我一直在浏览各种网站,寻找管理切换的正确方法。

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

我可以使用 alt-enter 切换到全屏,一切都很好,切换回来要么留下一个空白窗口,要么正确渲染,但永远不会继续渲染任何更新。

即它基本上会渲染一帧并且任何输入都会被注册但在您切换到全屏之前在屏幕上不可见。

很明显,我可能在交换链或设备上下文中遗漏了一些东西,因为我注意到使用 Flush() 会强制它工作,但我意识到这显然不是解决方案。

渲染函数片段

    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);

从 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;

我一直在用 D3D11_CREATE_DEVICE_DEBUG 测试这个,没有错误/警告/泄漏,欢迎任何评论或输入。

最佳答案

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

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

任何人在未来阅读本文并偶然发现其他修复方法时请告诉我。

关于c++ - DirectX 11 从全屏切换 -> 窗口问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5030945/

相关文章:

screenshot - 如何在DirectX 10中将后缓冲保存到文件中?

c# - Windows 7/8、Direct3D9、10 和 11 - 效果/着色器

c++ - 我可以将 Visual C++ Redistributable 2010 和/或 DirectX 10 安装到特定文件夹吗?

windows - 在 Windows 中截取屏幕截图的最快方法是什么?

c++ - 实现复杂的基于旋转的相机

c++ - 可以使资源无效的RAII

C++ 字符串 != 字符串

c++ - 我如何将我的类模板专门化为更少的参数

c++ - 比较两个 CString vector 的最佳方法是什么

c++ - 废除 C++ 中的包含文件