DirectX 11 commutation de plein écran -> Problème fenêtré
-
14-11-2019 - |
Question
Je suis chalutant divers sites à la recherche de la bonne façon de gérer la commutation.
Je pensais que je l'avais craqué mais j'ai remarqué un problème bizarre maintenant que je définis le sommet et les pixels shaders pour un appel de tirage.
Je peux échanger en plein écran à l'aide d'Alt-Entrée et tout va bien, ce qui permet de laisser une fenêtre vierge ou de rendu correctement mais ne continue jamais de rendre des mises à jour.
I.E Il s'agira essentiellement d'une trame et de toute entrée est enregistrée mais non visible à l'écran jusqu'à ce que vous échangiez en plein écran.
Son clair Je manque probablement quelque chose avec le swapchain ou Devicecontext, comme je l'ai remarqué à l'aide de Flush (), cela vous obligerait à fonctionner, mais je réalise que ce n'est clairement pas la solution.
Snippet de fonction de rendu
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);
Fonction de redimensionnement qui obtient une hauteur / largeur passée de WM_SIZE CASE
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 );
SETURE SWAP Chain avec ceci
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;
J'ai testé cela avec d3d11_create_device_debug et aucune erreur / avertissements / fuites, tout commentaire ou accueil de saisie.
La solution
The latest nvidia drivers have resolved this issue (drivers 275.33) for the gtx460 and gtx570 tested on.
There obviously is a software explanation and answer to this problem but its working now and that is what I wanted.
Anyone reading this in the future and stumble upon the other fix please let me know.
Autres conseils
After porting from D3D10 to 11 my I ran into the same issues with my app. Everything blank when switching from fullscreen to windowed mode. Installing the latest GeForce drives resolved the issue (without any code changes).