现在的位置: 首页 > 综合 > 正文

view

2018年05月27日 ⁄ 综合 ⁄ 共 2205字 ⁄ 字号 评论关闭

ID3D11RenderTargetView* mRenderTargetView;

 ID3D11Texture2D* backBuffer;

 mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&backBuffer));

md3dDevice->CreateRenderTargetView(backBuffer, 0, &mRenderTargetView); 

ReleaseCOM(backBuffer);

the multisampling settings used for the depth/stencil buffer must match the settings used for the render target.

CPUAccessFlags: Specifies how the CPU will access the resource. 

If the CPU needs to write to the resource, specify D3D11_CPU_ACCESS_WRITE. A resource with write access must have usage D3D11_USAGE_DYNAMIC or D3D11_USAGE_STAGING.

 If the CPU needs to read from the buffer, specify D3D11_CPU_ACCESS_READ. A buffer with read access must have usage D3D11_USAGE_STAGING. 

For the depth/stencil buffer, only the GPU writes and reads to the depth/buffer; therefore, we can specify zero for this value, as the CPU will not be reading or writing to the depth/stencil buffer.

We commented that the usage flags D3D11_USAGE_DYNAMIC and D3D11_USAGE_STAGING should be avoided because there is a performance penalty. The common factor is that the CPU is involved with both of these flags. Going back and forth between CPU and GPU memory
incurs a performance hit. For maximum speed, graphics hardware works best when we create all of our resources and upload the data to the GPU, and the resources stay on the GPU where only the GPU reads and writes to the resources. However, for some applications,
these flags cannot beavoided and the CPU must get involved, but you should always try to minimize the usage of these flags.

The second parameter of CreateTexture2D is a pointer to initial data to fill the texture with. However, because this texture is to be used as the depth/stencil buffer, we do not need to fill it ourselves with any data. Direct3D will write to the depth/stencil
buffer directly when performing depth buffering and stencil operations. Thus, we specify null for the second parameter. 

The second parameter of CreateDepthStencilView is a pointer to a D3D11_DEPTH_STENCIL_VIEW_DESC. Among other things, this structure describes the data type (format) of the elements in the resource. If the resource was created with a typed format (i.e.,
not typeless), then this parameter can be null, which indicates to create a view to the first mipmap level of this resource (the depth/stencil buffer was created with only one mipmap level) with the format the resource was created with. (Mipmaps are discussed
in Chapter 8.) Because we specified the type of our depth/stencil buffer, we specify null for this parameter.

【上篇】
【下篇】

抱歉!评论已关闭.