Reputation: 159
Good afternoon!
In DirectX I'm a beginner, I do not know many things.
I have a texture in the memory of the video card in RGBA format (DXGI_FORMAT_R8G8B8A8_UNORM). This is an intercepted game buffer. Before copying its contents into the computer's memory, I need to do a transformation of this texture in the format BGRA (DXGI_FORMAT_B8G8R8A8_UNORM). How to convert a texture from one pixel format to another means of video card?
// DXGI_FORMAT_R8G8B8A8_UNORM
ID3D11Texture2D *pTexture1;
// DXGI_FORMAT_B8G8R8A8_UNORM
ID3D11Texture2D *pTexture2;
D3D11_TEXTURE2D_DESC desc2 = {};
desc2.Width = swapChainDesc.BufferDesc.Width;
desc2.Height = swapChainDesc.BufferDesc.Height;
desc2.MipLevels = 1;
desc2.ArraySize = 1;
desc2.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
desc2.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
desc2.SampleDesc.Count = 1;
desc2.Usage = D3D11_USAGE_DEFAULT;
desc2.MiscFlags = 0;
void pixelConvert(ID3D11Texture2D *pTexture1, ID3D11Texture2D *pTexture2)
{
//
// Code....
//
}
I do not understand this solution: DX11 convert pixel format BGRA to RGBA It is not complete
Upvotes: 4
Views: 3005
Reputation: 41087
On the GPU, the simple solution is to just render the texture to another render target as a 'full-screen quad'. There's no need for any specialized shader, it's just simple rendering. When you load the texture, it gets 'swizzled' if needed to the standard Red, Green, and Blue channels and when you write to the render target the same thing happens depending on the format.
See
SpriteBatch
in DirectX Tool Kit, and this tutorial in particular if you need a solution that works on all Direct3D Hardware Feature Levels. If you can requireD3D_FEATURE_LEVEL_10_0
or later, then seePostProcess
which is optimized for the fact that you are always drawing the quad to the entire render target.If you want a CPU solution, see DirectXTex.
Upvotes: 1