c++ - 共享纹理应该在 D3DPOOL_DEFAULT 还是 D3DPOOL_MANAGED?

标签 c++ directx

我正在尝试在两个进程之间共享一个 direct3d 表面。他们都在 Windows 7 上使用 D3D9Ex。 MSDN documentation状态:

To be shared, you need to designate a resource for sharing at the time of creation, and locate the resource in the default pool (D3DPOOL_DEFAULT).

还有:

To create a shared resource, call any resource creation API (see below) with an uninitialized handle (the pointer itself is not NULL (pSharedHandle != NULL), but the pointer points to a NULL value (*pSharedHandle == NULL)). The API will generate a shared resource and return a valid handle.

所以这是我调用 CreateTexture 来创建共享纹理:

IDirect3DTexture9* texture;
HANDLE sharedHandle = nullptr;

d3dDevice9Ex->CreateTexture(width, height, 1,
            D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture, &sharedHandle);

这失败了; DgbView.exe 中的输出是:

[8788] Direct3D9: (ERROR) :Failure trying to create a texture
[8788] 
[8788] Direct3D9: (ERROR) :Source of shared texture must be in D3DPOOL_SYSTEMMEM. CreateTexture fails.

我不明白。似乎文档指出表面必须在 D3DPOOL_DEFAULT 中,但来自 Direct3D 的错误消息是表面必须在 D3DPOOL_SYSTEMME 中。是哪一个,或者我调用这个方法的方式有什么问题吗?

请注意,当我将参数更改为 D3DPOOL_SYSTEMMEM 时,错误消息变为:

[10068] Direct3D9: (ERROR) :Failure trying to create a texture
[10068] 
[10068] Direct3D9: (ERROR) :*pSharedHandle must be a valid pointer to create such D3DPOOL_SYSTEMMEM texture. CreateTexture fails.

最佳答案

聚会有点晚了,但我在处理一些遗留代码时遇到了同样的问题。

进入 CreateTexture 方法反汇编后,我发现代码中似乎存在错误(或至少是未记录的“功能”)。

当使用 pSharedHandle 创建共享 GPU 纹理时,必须将 *ppTexture 初始化为 NULL

如果不这样做,代码将落入尝试使用系统位图作为纹理的路径。

所以在上面的代码中,改变

IDirect3DTexture9* texture;

进入

IDirect3DTexture9* texture = nullptr;

会解决问题。

希望这可以节省我浪费在这上面的几个小时。

关于c++ - 共享纹理应该在 D3DPOOL_DEFAULT 还是 D3DPOOL_MANAGED?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16796404/

相关文章:

c++ - 将我的 C++ 演示放到 iPhone 上有多容易?

c++ - 在远程桌面中创建 DirectX 设备失败

c++ - 如何对用户定义类型使用 BOOST_CHECK_CLOSE

C++ const_iterator 没有匹配的构造函数

c++ - 在 Visual C++ 2008 中生成访问器

c++ - 为什么我在将 tolower() 的结果流式传输到 std::cout 时得到一个数字,但在我使用 putchar() 时却没有?

c - 重新映射 Direct3D 游戏上的按键

c++ - SPOJ 中的运行时错误

c++ - Directx C++ - 绘制 DNA 形状

c++ - 为什么常量缓冲区在 Directx 11 中部分更新