SlimDX与DX10共享资源

时间:2010-07-07 18:00:46

标签: directx direct3d slimdx direct3d10

我正在尝试DX10的共享资源功能,因为我需要这个功能用于我的一个项目。但我找不到很多样本或代码,特别是使用SlimDX。根据DX10文档,我只需要将资源指定为Shared,然后我可以使用另一个应用程序中的OpenSharedResource()打开它。通过SlimDX中的简单测试应用程序,我做了以下

        Texture2D tex = new Texture2D(device, new Texture2DDescription()
        {
            ArraySize = 1,
            BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
            CpuAccessFlags = CpuAccessFlags.None,
            Format = Format.B8G8R8A8_UNorm,
            Height = 128,
            Width = 128,
            MipLevels = 1,
            OptionFlags = ResourceOptionFlags.Shared,
            SampleDescription = new SampleDescription(1, 0),
            Usage = ResourceUsage.Default,
        });

        Texture2D tex2 = device.OpenSharedResource<Texture2D>(tex.ComPointer);

但我一直收到这个错误

 E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809)

我似乎无法弄清楚出了什么问题,因为tex.ComPointer可能不是OpenSharedResource的正确指针,或者不支持Texture2D(没有明确提到它不在文档中)

通过指定要传递给CreateTexture函数的pHandle的另一种选择在SlimDX中不可用,或者我不知道它。

有没有人成功试过这个?一些帮助将不胜感激。

由于

1 个答案:

答案 0 :(得分:4)

我发现我的代码存在问题。我需要使用DXGI来检索共享句柄(而不是指针)。以下代码完美无缺

SlimDX.DXGI.Resource r = new Resource(tex);

Texture2D tex2 = device.OpenSharedResource<Texture2D>(r.SharedHandle);