简体   繁体   English

的DirectX。 如何将纹理从一种像素格式转换为另一种格式(RGBA - > BGRA)?

[英]DirectX. How to convert a texture from one pixel format to another (RGBA -> BGRA)?

Good afternoon! 下午好!

In DirectX I'm a beginner, I do not know many things. 在DirectX中我是初学者,我不知道很多东西。

I have a texture in the memory of the video card in RGBA format (DXGI_FORMAT_R8G8B8A8_UNORM). 我在RGBA格式的视频卡内存中有一个纹理(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). 在将其内容复制到计算机内存之前,我需要以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 我不明白这个解决方案: DX11转换像素格式BGRA到RGBA它是不完整的

On the GPU, the simple solution is to just render the texture to another render target as a 'full-screen quad'. 在GPU上,简单的解决方案是将纹理渲染到另一个渲染目标,作为“全屏四边形”。 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 . 如果您需要适用于所有Direct3D硬件功能级别的解决方案,请参阅DirectX工具包中的 SpriteBatch ,特别是本教程 If you can require D3D_FEATURE_LEVEL_10_0 or later, then see PostProcess which is optimized for the fact that you are always drawing the quad to the entire render target. 如果您需要D3D_FEATURE_LEVEL_10_0或更高版本,请参阅PostProcess ,它针对您始终将四边形绘制到整个渲染目标的事实进行了优化。

If you want a CPU solution, see DirectXTex . 如果需要CPU解决方案,请参阅DirectXTex

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM