本文介绍了从ID3D11Texture2D到ID2D1Bitmap,可以吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个游戏的扩展程序,该游戏仅打开HDC,供插件开发人员使用.

I am working on a extension to a game which only opens a HDC for addon developers to draw on.

但是,我已经用尽了GDI +/Direct2D绘图功能,该功能对于我想要实现的速度已经足够快了-图像效果(添加剂,混合,乘法混合等).

However, I have exhausted GDI+/Direct2D drawing possibilities that is fast enough for what I want to accomplish - image effects(Additive, Blend, Multiply Blend etc).

我很清楚Direct2D提供了一个效果工具包,但是它需要平台更新(对于Windows 7),并且根本不理想.

I am well aware that Direct2D offers a effects toolkit however, that requires a platform update (for Windows 7) and that is not ideal at all.

因此,我只剩下Direct3D. MSDN/Google搜索提供了许多方法来执行D2D-> D3D,但是ZERO显示了如何执行D3D-> D2D.我知道有一种方法可以转换D3D-> D2D,并且可以映射和复制像素数据,但是效率很低,因为(如果我是对的话)它是从GPU VRAM-> CPU/RAM-> GPU VRAM传输的.我可能只会将其用作最后的选择....

Hence I am left with only Direct3D. MSDN/Google Search offers lots of ways to do D2D -> D3D, but ZERO shows how to do D3D -> D2D. I know there is a method to convert D3D - > D2D and that is to map and copy pixel data, but that is highly inefficient as (if I am right) it transfers from GPU VRAM -> CPU/RAM -> GPU VRAM. I will probably only use that as a last alternative....

或者,如果有人对如何从D3D11中的RenderTarget抓取HDC有任何想法,以便可以使用BitBlt,也可能有用.

Alternatively, it might also work if someone has any idea on how to grab a HDC from RenderTarget in D3D11 so that I can BitBlt.

如果有人可以帮助我,我将不胜感激.

I would be grateful if anyone can help with this.

推荐答案

好,我知道了.可能不是最有效的,但是可以完成工作.没有memcpy,bitblt(尽管在内存中的CreateBitmap内部可能具有这些功能).避免所有DXGI版本的废话.

ok I figured it out. Probably not the most efficient, but does the job.No memcpy,bitblt (although inside the CreateBitmap from memory might have those functions inside). Avoids all the DXGI version crap too.

    D3D11_TEXTURE2D_DESC td;
    m_backBufferTexture->GetDesc(&td);
    td.Usage = D3D11_USAGE_STAGING;
    td.BindFlags = 0;
    td.CPUAccessFlags = D3D11_CPU_ACCESS_READ;

    m_pDevice->CreateTexture2D( &td, NULL, &(m_pNewTexture) );
    m_pContext->CopyResource(m_pNewTexture, m_backBufferTexture);
    m_pNewTexture->QueryInterface(__uuidof(IDXGISurface), (void**)&m_NewTextDXGI);

    DXGI_MAPPED_RECT bitmap2Dmap;
    m_NewTextDXGI->Map(&bitmap2Dmap,DXGI_MAP_READ);

    D2D1_PIXEL_FORMAT desc2d;
    D2D1_BITMAP_PROPERTIES bmpprops;

    desc2d.format = DXGI_FORMAT_B8G8R8A8_UNORM;
    desc2d.alphaMode = D2D1_ALPHA_MODE_IGNORE; // Adapt to your needs.

    bmpprops.dpiX = 96.0f;
    bmpprops.dpiY = 96.0f;
    bmpprops.pixelFormat = desc2d;


    D2D1_SIZE_U size = D2D1::SizeU(
    dim.x,
    dim.y
    ); // Adapt to your own size.

    pRT->CreateBitmap(size,(void*)bitmap2Dmap.pBits,bitmap2Dmap.Pitch,bmpprops,&m_pD2DBitmap);
    m_NewTextDXGI->Unmap();

这篇关于从ID3D11Texture2D到ID2D1Bitmap,可以吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 23:08