Direct3D11:翻转ID3D11Texture2D [英] Direct3D11: Flipping ID3D11Texture2D

查看:596
本文介绍了Direct3D11:翻转ID3D11Texture2D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我执行Direct3D后台缓冲区的捕获.下载像素时,图像框架沿其垂直轴翻转.复制资源或创建目标ID3D11Texture2D时是否可以告诉" D3D翻转框架?

I perform a capture of Direct3D back buffer. When I download the pixels the image frame is flipped along its vertical axis.Is it possible to "tell" D3D to flip the frame when copying resource,or when creating target ID3D11Texture2D ?

这是我的方法:

将帧缓冲区复制到的纹理是这样创建的:

The texture into which I copy the frame buffer is created like this:

    D3D11_TEXTURE2D_DESC description =
    {
        desc.BufferDesc.Width, desc.BufferDesc.Height, 1, 1,
        DXGI_FORMAT_R8G8B8A8_UNORM,
        { 1, 0 }, // DXGI_SAMPLE_DESC
        D3D11_USAGE_STAGING,//transder from GPU to CPU
        0, D3D11_CPU_ACCESS_READ, 0
    };
    D3D11_SUBRESOURCE_DATA data = { buffer, desc.BufferDesc.Width * PIXEL_SIZE, 0 };
     device->CreateTexture2D(&description, &data, &pNewTexture);

然后在每一帧上做

     pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast< void** >(&pSurface));
     pContext->CopyResource(pNewTexture, pSurface);
     D3D11_MAPPED_SUBRESOURCE resource; 
     pContext->Map(pNewTexture, 0, D3D11_MAP_READ , 0, &resource);
     //reading from resource.pData
     //...

PS:我无法控制渲染管道.我用此代码钩住了一个外部应用程序. 另外,我不想弄乱CPU上的像素缓冲区,例如循环中的反向复制等.复制的低延迟是高优先级.

PS: I don't have a control of the rendering pipeline. I hook an external app with this code. Also,I don't want to mess with the pixel buffer on the CPU, like reverse copy in a loop etc.. The low latency of the copy is high priority.

更新:

我也尝试过:

    D3D11_BOX box;
    box.left = 0;
    box.right = desc.BufferDesc.Width;
    box.top = desc.BufferDesc.Height;
    box.bottom = 0;
    box.front = 0;
    box.back = 1;
    pContext->CopySubresourceRegion(pNewTexture, 0, 0, 0, 0, pSurface, 0, &box);

这会导致框架内容空白.

Which causes the frame to be empty from its content.

推荐答案

使用D3D11_USAGE_DEAFULT,CPUAccessFlags = 0和BindFlags = D3D11_BIND_SHADER_RESOURCE创建纹理. CopyResource交换链的后缓冲区给它.使用D3D11_BIND_RENDER_TARGET创建另一个纹理.将其设置为渲染目标,设置像素着色器,并使用第一个纹理绘制翻转的四边形.现在,您应该能够将第二个纹理CopyResource复制到您现在使用的临时纹理中.这应该比使用CPU复制翻转的图像数据更快.但是,此解决方案将在GPU上占用更多资源,并且可能很难设置.

Create a texture with D3D11_USAGE_DEAFULT, with CPUAccessFlags=0 and BindFlags=D3D11_BIND_SHADER_RESOURCE. CopyResource the swapchain's backbuffer to it. Create another texture with D3D11_BIND_RENDER_TARGET. Set it as a render target, set a pixel shader and draw a flipped quad using the first texture. Now you should be able to CopyResource the second texture to the staging texture that you use now. This should be faster than copying a flipped image data using the CPU. However, this solution would take more resources on the GPU and might be hard to setup in a hook.

这篇关于Direct3D11:翻转ID3D11Texture2D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆