简体   繁体   English

Direct2D如何打开共享纹理

[英]Direct2D how to open shared texture

I have a code, which uses Direct9Ex like:我有一个代码,它使用 Direct9Ex,例如:

res = Device->CreateTexture(1920, 1080, 1, 1, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &Texture, &texture_shared_handle);

How can i open that texture for read in Direct2D using this texture_shared_handle ?如何使用此texture_shared_handle打开该纹理以在 Direct2D 中读取?

I found function ID2D1RenderTarget::CreateSharedBitmap , but can't find any working code that can open shared DXGI resources.我找到了 function ID2D1RenderTarget::CreateSharedBitmap ,但找不到任何可以打开共享 DXGI 资源的工作代码。 Also, texture is valid for sharing, it has only one level and A8R8G8B8 mode.另外,贴图是共享有效的,只有一层,A8R8G8B8模式。 Also, i forced to use direct9ex for texture creation此外,我被迫使用 direct9ex 进行纹理创建

Another solution i thinking of is to create Direct9Ex surface on same device as above(which creates texture ) with shared handle, like this:我想到的另一个解决方案是在与上述相同的设备上创建 Direct9Ex 表面(创建纹理)并使用共享句柄,如下所示:

res = Device->CreateOffscreenPlainSurface(1920, 1080, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &MagSurface2, &Surface2_shared_handle);
res = Texture->GetSurfaceLevel(0, &MagSurface1);

...
// copying data from texture level surface to shared surface
res = Device->GetRenderTargetData(MagSurface1, MagSurface2);

But then, how to pass this Surface2_shared_handle to Direct2D?但是,如何将这个Surface2_shared_handle传递给 Direct2D?

I also tried to get IDXGISurface to then pass it to Direct2D, but, i always fails:我还尝试让 IDXGISurface 然后将其传递给 Direct2D,但是,我总是失败:

// Direct9Ex texture
IDXGISurface* pDxgiSurface = NULL;
            res = Texture->QueryInterface(__uuidof(IDXGISurface), (void**)&pDxgiSurface);
res is always E_NOINTERFACE!

Thanks谢谢

In order to obtain an IDXGISurface, you need to open the shared texture with your DirectX 11 device (the one you used to initialize Direct2D) using this function .为了获得 IDXGISurface,您需要使用此 function与您的 DirectX 11 设备(用于初始化 Direct2D 的设备)打开共享纹理。 You can call it to get an IDXGIResource which you can QueryInterface for IDXGISurface and use it in your Direct2D.您可以调用它来获取 IDXGIResource,您可以为 IDXGISurface 查询接口并在 Direct2D 中使用它。 You may also need to implement some synchronization such as the one explained here .您可能还需要实现一些同步,例如此处解释的同步。

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

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