Копирование части 2D-текстуры в другой Direct3D11 - PullRequest
0 голосов
/ 17 мая 2011

Как скопировать произвольную многоугольную область одной 2D-текстуры Direct3D 11 в другую?Я пытался использовать метод ID3D11DeviceContext :: CopySubresourceRegion, но он копирует только прямоугольные части.Я использую Visual C ++.

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

edit: Добавлен фрагмент кода.

1 Ответ

1 голос
/ 23 мая 2011

Я не знаю, существует ли прямой метод для копирования полигональной области.Но вы можете использовать трафаретный буфер.Нарисуйте произвольный многоугольник в буфере трафарета.И скопируйте всю текстуру в другую, применив трафарет.Вы получите тот же эффект.

EDIT :: Citation Added

Вы можете посмотреть этот урок.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);
...