私は、切り替えを管理する正しい方法を探して、さまざまなサイトをトロールしてきました。
ひびが入ったと思っていましたが、描画呼び出し用に頂点シェーダーとピクセルシェーダーを設定しているときに、奇妙な問題に気づきました。
alt-enterを使用して全画面に切り替えることができ、すべてが正常です。空白のウィンドウを残すか、正しくレンダリングしますが、更新のレンダリングを続行しないで元に戻します。
つまり、基本的に1つのフレームがレンダリングされ、入力は登録されますが、全画面に切り替えるまで画面に表示されません。
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でテストしており、エラー/警告/リークはなく、コメントや入力を歓迎します。