多角形の領域を直接コピーする方法があるかどうかはわかりません。ただし、ステンシルバッファを使用できます。任意のポリゴンをステンシルバッファに描画します。そして、ステンシルを適用して、テクスチャ全体を別のテクスチャにコピーします。同じ効果が得られます。
編集::引用を追加
このチュートリアルをご覧ください。
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);