1

あるDirect3D112Dテクスチャの任意のポリゴン領域を別のテクスチャにコピーするにはどうすればよいですか?ID3D11DeviceContext :: CopySubresourceRegionメソッドを使用してみましたが、長方形の部分のみがコピーされます。VisualC++を使用しています。

pKeyedMutex11->AcquireSync(1, INFINITE);
pImmediateContext->CopySubresourceRegion( pBackBuffer11, 0, max(size.width-turned,0.0f), 0, 0, pSharedTexture11, 0, &sourceRegion );            
pKeyedMutex11->ReleaseSync(0);

pKeyedMutex11_2->AcquireSync(1, INFINITE);
pImmediateContext->CopySubresourceRegion( pBackBuffer11, 0, max(size_1.width - 2*turned,0.0f) , 0, 0, pSharedTexture11_2, 0, &sourceRegion_2 );         
pKeyedMutex11_2->ReleaseSync(0);

pKeyedMutex11_1->AcquireSync(1, INFINITE);
        // Copy the content from the shared texture to the back-buffer          
pImmediateContext->CopySubresourceRegion( pBackBuffer11, 0, 0, 0, 0, pSharedTexture11_1, 0, &sourceRegion_1 );
pKeyedMutex11_1->ReleaseSync(0);

編集:コードスニペットを追加しました。

4

1 に答える 1

1

多角形の領域を直接コピーする方法があるかどうかはわかりません。ただし、ステンシルバッファを使用できます。任意のポリゴンをステンシルバッファに描画します。そして、ステンシルを適用して、テクスチャ全体を別のテクスチャにコピーします。同じ効果が得られます。

編集::引用を追加

このチュートリアルをご覧ください。 http://www.rastertek.com/dx11tut03.html

次に、深度ステンシルの説明を設定する必要があります。これにより、Direct3Dが各ピクセルに対して実行する深度テストのタイプを制御できます。

// Initialize the description of the stencil state.
ZeroMemory(&depthStencilDesc, sizeof(depthStencilDesc));

// Set up the description of the stencil state.
depthStencilDesc.DepthEnable = true;
depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;

depthStencilDesc.StencilEnable = true;
depthStencilDesc.StencilReadMask = 0xFF;
depthStencilDesc.StencilWriteMask = 0xFF;

// Stencil operations if pixel is front-facing.
depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

// Stencil operations if pixel is back-facing.
depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

説明を入力すると、深度ステンシル状態を作成できます。

// Create the depth stencil state.
result = m_device->CreateDepthStencilState(&depthStencilDesc, &m_depthStencilState);
if(FAILED(result))
{
    return false;
}

作成された深度ステンシル状態を使用して、有効になるように設定できます。デバイスコンテキストを使用して設定していることに注意してください。

// Set the depth stencil state.
m_deviceContext->OMSetDepthStencilState(m_depthStencilState, 1);

次に作成する必要があるのは、デプスステンシルバッファのビューの説明です。これは、Direct3Dが深度バッファーを深度ステンシルテクスチャとして使用することを認識できるようにするためです。説明を入力した後、関数CreateDepthStencilViewを呼び出して作成します。

// Initailze the depth stencil view.
ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc));

// Set up the depth stencil view description.
depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
depthStencilViewDesc.Texture2D.MipSlice = 0;

// Create the depth stencil view.
result = m_device->CreateDepthStencilView(m_depthStencilBuffer, &depthStencilViewDesc, &m_depthStencilView);
if(FAILED(result))
{
    return false;
}

これが作成されたら、OMSetRenderTargetsを呼び出すことができます。これにより、レンダーターゲットビューと深度ステンシルバッファーが出力レンダーパイプラインにバインドされます。このようにして、パイプラインがレンダリングするグラフィックは、以前に作成したバックバッファーに描画されます。グラフィックがバックバッファに書き込まれると、それをフロントに交換して、ユーザーの画面にグラフィックを表示できます。

// Bind the render target view and depth stencil buffer to the output render pipeline.
m_deviceContext->OMSetRenderTargets(1, &m_renderTargetView, m_depthStencilView);
于 2011-05-23T05:23:55.117 に答える