入职作业总结(3.1)D3D11初始化

文中提到的书,如无特殊标注,都指经典的directx编程指南:《Introduction to 3D Game Programming with Directx 11》

D3D初始化主要根据以下步骤:

  1. Create the ID3D11Device and ID3D11DeviceContext interfaces using the D3D11CreateDevice function.
  2. Check 4X MSAA quality level support using the ID3D11Device::CheckMultisampleQualityLevels method.
  3. Describe the characteristics of the swap chain we are going to create by filling out an instance of the DXGI_SWAP_CHAIN_DESC structure.
  4. Query the IDXGIFactory instance that was used to create the device, and create an IDXGISwapChain instance.
  5. Create a render target view to the swap chain’s back buffer.
  6. Create the depth/stencil buffer and its associated depth/stencil view.
  7. Bind the render target view and depth/stencil view to the output merger stage of the rendering pipeline so that they can be used by Direct3D.
  8. Set the viewport.

1.创建 ID3D11DeviceID3D11DeviceContext

两者的作用如下:

  1. The ID3D11Device interface is used to check feature support, and allocate resources.
  2. The ID3D11DeviceContext interface is used to set render states, bind resources to the graphics pipeline, and issue rendering commands.
    补充一下:DeviceContext分immediate contextdeferred context两类。一般主线程内都设置为immediate context

ID3D11Device的创建可用如下函数:

HRESULT D3D11CreateDevice(
IDXGIAdapter *pAdapter,
D3D_DRIVER_TYPE DriverType,
HMODULE Software,
UINT Flags,
CONST D3D_FEATURE_LEVEL *pFeatureLevels,
UINT FeatureLevels,
UINT SDKVersion,
ID3D11Device **ppDevice,
D3D_FEATURE_LEVEL *pFeatureLevel,
ID3D11DeviceContext **ppImmediateContext
);
  1. pAdapter指明了要使用的设备(个人理解为显卡),设为nullptr表示当前采用的主设备。
  2. DriverType一般使用D3D_DRIVER_TYPE_HARDWARE。只有当硬件设备无法支持时考虑其他选项(效果一般较差)。其他可选的有:D3D_DRIVER_TYPE_REFERENCE(非常慢的软件模拟设备)、D3D_DRIVER_TYPE_WARP(D3D10版本提供的软件模拟设备,不被D3D11支持)、D3D_DRIVER_TYPE_SOFTWARE(软件设备总称,用于选择其他第三方软件模拟设备)。
  3. Software:在第二项使用D3D_DRIVER_TYPE_SOFTWARE,在这个参数里提供相应的软件设备。在使用硬件设备时一般置空
  4. Flags:标志位,有两个常见的标志位(可以通过|,即“位或”相结合):D3D11_CREATE_DEVICE_DEBUG(这个标志位开启时,D3D会把调试信息发送到VC++ output window)、D3D11_CREATE_DEVICE_SINGLETHREADED(如果能保证D3D仅在单线程下被调用,则可以提供效率——此处我理解是仅针对该进程内部,如果没有多线程即可)。
  5. pFeatureLevels:可选的D3D_FEATURE_LEVEL数组列表。函数会依次测试数组中各项,直到遇到一个可用的D3D_FEATURE_LEVEL置为nullptr表示选用可用的最高级D3D_FEATURE_LEVEL
  6. FeatureLevels:第5个参数中数组元素的个数。如果第5个参数为nullptr,这里用0填充。
  7. SDKVersion:用D3D11_SDK_VERSION
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值