创建 Direct3D9 设备的最少代码

发布于 2024-10-13 08:10:39 字数 1201 浏览 4 评论 0原文

这不适用于稳定的发布代码,我只需要从我的开发 PC 上的 HWND 获取在 C++ 应用程序中创建的窗口化 D3D9 设备来测试某些内容...它可以默认加载选项。

我试图从我拥有的旧 D3D8 类中将其组合在一起,但我收到了 D3DERR_INVALIDCALL。

基本上我现在有这个:

    HWND mHWnd = ...;
    LPDIRECT3D9 mpD3D = Direct3DCreate9(D3D_SDK_VERSION);

    D3DPRESENT_PARAMETERS md3dpp;
    ZeroMemory( &md3dpp, sizeof(D3DPRESENT_PARAMETERS) );
    md3dpp.Windowed                 = true;
    md3dpp.SwapEffect               = D3DSWAPEFFECT_DISCARD;
    md3dpp.BackBufferCount          = 1;
    md3dpp.EnableAutoDepthStencil   = 0;
    md3dpp.hDeviceWindow            = mHWnd;
    md3dpp.BackBufferWidth          = 0;
    md3dpp.BackBufferHeight         = 0;
    md3dpp.FullScreen_RefreshRateInHz = 0;
    md3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
    md3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    md3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
    md3dpp.MultiSampleQuality = 0;

    LPDIRECT3DDEVICE9 mpD3DDevice=0;
    HRESULT hr = mpD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,mHWnd,0,&md3dpp,&mpD3DDevice);

我认为一些 D3DPRESENT_PARAMETERS 选项可能是罪魁祸首 - 我不关心 z 缓冲区或模板或 AA 的后缓冲区,任何旧的普通设备都可以。

我是否将一些不兼容的标志复制粘贴在一起?

This isn't for stable release code, I just need to get a windowed D3D9 device created in a C++ app from a HWND on my dev PC for testing something... it can default on loads of options.

I was trying to hack it together from an old D3D8 class I had but I'm getting D3DERR_INVALIDCALL.

Basically I have this now:

    HWND mHWnd = ...;
    LPDIRECT3D9 mpD3D = Direct3DCreate9(D3D_SDK_VERSION);

    D3DPRESENT_PARAMETERS md3dpp;
    ZeroMemory( &md3dpp, sizeof(D3DPRESENT_PARAMETERS) );
    md3dpp.Windowed                 = true;
    md3dpp.SwapEffect               = D3DSWAPEFFECT_DISCARD;
    md3dpp.BackBufferCount          = 1;
    md3dpp.EnableAutoDepthStencil   = 0;
    md3dpp.hDeviceWindow            = mHWnd;
    md3dpp.BackBufferWidth          = 0;
    md3dpp.BackBufferHeight         = 0;
    md3dpp.FullScreen_RefreshRateInHz = 0;
    md3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
    md3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    md3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
    md3dpp.MultiSampleQuality = 0;

    LPDIRECT3DDEVICE9 mpD3DDevice=0;
    HRESULT hr = mpD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,mHWnd,0,&md3dpp,&mpD3DDevice);

I figure some D3DPRESENT_PARAMETERS options might be to blame - I don't care about back-buffers of z-buffers or stencils or AA, any old plain device is fine.

Have I copy-pasted together some incompatible flags?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别念他 2024-10-20 08:10:39

第一个问题是您需要设置一些行为标志。

来自 CreateDevice. 上的文档:

行为标志[in]
双字
控制设备创建的一个或多个选项的组合。有关详细信息,请参阅 D3DCREATE。

并来自 D3DCREATE 文档:

D3DCREATE_HARDWARE_VERTEXPROCESSING、D3DCREATE_MIXED_VERTEXPROCESSING 和 D3DCREATE_SOFTWARE_VERTEXPROCESSING 是互斥标志。调用 CreateDevice 时,必须至少指定一个这些顶点处理标志。

尝试:

HRESULT hr = mpD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,mHWnd,D3DCREATE_MIXED_VERTEXPROCESSING,&md3dpp,&mpD3DDevice);

1 problem is that you need to set some Behaviour flags.

From the docs on CreateDevice.:

BehaviorFlags [in]
DWORD
Combination of one or more options that control device creation. For more information, see D3DCREATE.

And from the D3DCREATE docs:

D3DCREATE_HARDWARE_VERTEXPROCESSING, D3DCREATE_MIXED_VERTEXPROCESSING, and D3DCREATE_SOFTWARE_VERTEXPROCESSING are mutually exclusive flags. At least one of these vertex processing flags must be specified when calling CreateDevice.

Try:

HRESULT hr = mpD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,mHWnd,D3DCREATE_MIXED_VERTEXPROCESSING,&md3dpp,&mpD3DDevice);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文