当前位置: 首页 > 工具软件 > demo-scene > 使用案例 >

初始化DEMO相关

龙飞文
2023-12-01

整个初始化步骤:
1. Create the ID3D12Device using the D3D12CreateDevice function.
2. Create an ID3D12Fence object and query descriptor sizes.
3. Check 4X MSAA quality level support.
4. Create the command queue, command list allocator, and main command list.
5. Describe and create the swap chain.
6. Create the descriptor heaps the application requires.
7. Resize the back buffer and create a render target view to the back buffer.
8. Create the depth/stencil buffer and its associated depth/stencil view.
9. Set the viewport and scissor rectangles.

Describe and Create the Swap Chain
创建并初始化交换链中第一步是填充一个DXGI_SWAP_CHAIN_DESC结构体。他描述了我们要创建的交换链。

typedef struct DXGI_SWAP_CHAIN_DESC
{
    DXGI_MODE_DESC BufferDesc;
    DXGI_SAMPLE_DESC SampleDesc;
    DXGI_USAGE BufferUsage;
    UINT BufferCount;
    HWND OutputWindow;
    BOOL Windowed;
    DXGI_SWAP_EFFECT SwapEffect;
    UINT Flags;
} DXGI_SWAP_CHAIN_DESC;

其中的DXGI_MODE_DESC BufferDesc

typedef struct DXGI_MODE_DESC
{
UINT Width; // Buffer resolution width
UINT Height; // Buffer resolution height
DXGI_RATIONAL RefreshRate;
DXGI_FORMAT Format; // Buffer display format
DXGI_MODE_SCANLINE_ORDER ScanlineOrdering; //Progressive vs. interlaced
DXGI_MODE_SCALING Scaling; // How the image is stretched over the monitor.
} DXGI_MODE_DESC;
  1. BufferDesc:这个结构体描述了我们想创建的back buffer的特性。
  2. SampleDesc:这个结构在之前多重采样说到过,保存了多重采样的等级。
  3. BufferUsageDXGI_USAGE被定义为typedef UINT DXGI_USAGE;这个参数指定了DXGI_USAGE_RENDER_TARGET_OUTPUT输出。
  4. BufferCount:指定了多少个缓冲区,指定2个为双重缓冲。
  5. OutputWindow:A handle to the window we are rendering into.
  6. Windowed: Specify true to run in windowed mode or false for full-screen mode.
  7. SwapEffect: Specify DXGI_SWAP_EFFECT_FLIP_DISCARD.
  8. Flags:如果指定了DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH,那么当应用选择全屏模式时,他将选择最合适的显示模式匹配应用程序的窗口。否则他将使用用户桌面的显示参数。

在这里略过帧率和帧生产时间相关内容,以后再来补充。直接去看渲染部分。

 类似资料: