0

我們有一箇舊的應用程序uisng DirectDraw 8.它直接將像素逐像素寫入視頻內存,一切都很好。 現在我需要將它移植到Windows Store應用程序中。使用direct3D渲染視頻

Media Foundation似乎是渲染視頻的推薦路徑,並通過了「媒體引擎本機C++視頻播放示例(Windows 8.1)」 但即使Media Foundation也使用DirectDraw進行視頻渲染。

ComPtr<ID3D11Texture2D> backBuffer; 
    DX11SwapChain->GetBuffer(0, IID_PPV_ARGS(&backBuffer)); 

    m_spMediaEngine->TransferVideoFrame(backBuffer.Get(), nullptr, &m_rcTarget, &m_bkgColor); 

    DX11SwapChain->Present(1, 0); 

因此,通過Direct3D樣本,我能夠得到backBuffer。但所有的樣本似乎都在處理繪製線等 而沒有設置個別像素。

我該如何掌握像素?即設置BackBuffer [somepixel] = someRGBA

+0

Media Foundation不使用DirectDraw。即使是它的前身DirectShow,DirectDraw也只是一個選項。 Media Foundation通過EVR使用Direct3D。 –

+0

我很欣賞這個更正。如果您能指示我如何在Direct3D中寫入「backBuffer」(現在稱爲ID3D11Texture2D),就像我們在DirectDraw中所做的那樣,我將不勝感激。 –

回答

0

UpdateSubresource對我來說工作得很好。我可以得到約60 FPS這是相當不錯的。

// get a pointer directly to the back buffer 
    swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), &Backbuffer); 

    // Width and Height 
    swapchain->GetDesc1(&scd); 
    Width = scd.Width; 
    Height = scd.Height; 

    TextureData = new UINT32[Width * Height]; 


void CMyClass::Render() 
{ 
    UINT n, i; 
    UINT *psrc; 
    psrc = TextureData; 
    i = ScreenColourI & 255; 
    ScreenColourI += 1; 

    for (n=0; n<Width*Height; n++) 
    { 
     *psrc++ = (i<<16) | (i<<8) | i ; 
     i++; 
     i &= 255; 
    } 

    myID3D11DeviceContext->UpdateSubresource (Backbuffer.Get(), 0, NULL, TextureData, Width*4, 0); 

    // switch the back buffer and the front buffer 
    swapchain->Present(1, 0); 

}