本文整理汇总了C++中IDXGISwapChain::QueryInterface方法的典型用法代码示例。如果您正苦于以下问题:C++ IDXGISwapChain::QueryInterface方法的具体用法?C++ IDXGISwapChain::QueryInterface怎么用?C++ IDXGISwapChain::QueryInterface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDXGISwapChain
的用法示例。
在下文中一共展示了IDXGISwapChain::QueryInterface方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateEventEx
//--------------------------------------------------------------------------
void D3D12RenderWindow::Init(D3D12Renderer& kRenderer) noexcept
{
if ((!m_kNode.is_attach()) && m_spTargetWindow)
{
D3D12_COMMAND_QUEUE_DESC kQueueDesc = {};
kQueueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
kQueueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
VE_ASSERT_GE(kRenderer.m_pkDevice->CreateCommandQueue(&kQueueDesc, IID_PPV_ARGS(&m_pkCommandQueue)), S_OK);
DXGI_SWAP_CHAIN_DESC kSwapChainDesc = {};
kSwapChainDesc.BufferCount = D3D12Renderer::FRAME_COUNT;
kSwapChainDesc.BufferDesc.Width = m_spTargetWindow->GetWidth();
kSwapChainDesc.BufferDesc.Height = m_spTargetWindow->GetHeight();
kSwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R10G10B10A2_UNORM;
kSwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
kSwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
kSwapChainDesc.OutputWindow = (HWND)(m_spTargetWindow->GetNativeHandle());
kSwapChainDesc.SampleDesc.Count = 1;
kSwapChainDesc.Windowed = TRUE;
IDXGISwapChain* pkSwapChain;
VE_ASSERT_GE(kRenderer.m_pkDXGIFactory->CreateSwapChain(m_pkCommandQueue, &kSwapChainDesc, &pkSwapChain), S_OK);
VE_ASSERT_GE(pkSwapChain->QueryInterface(IID_PPV_ARGS(&m_pkSwapChain)), S_OK);
VE_SAFE_RELEASE(pkSwapChain);
VE_ASSERT(m_pkCommandQueue && m_pkSwapChain);
for (uint32_t i(0); i < D3D12Renderer::FRAME_COUNT; ++i)
{
FrameCache& kFrame = m_akFrameCache[i];
VE_ASSERT_GE(m_pkSwapChain->GetBuffer(i, IID_PPV_ARGS(&kFrame.m_pkBufferResource)), S_OK);
kFrame.m_hHandle.ptr = kRenderer.m_kRTVHeap.GetCPUStart().ptr + kRenderer.m_kRTVHeap.Alloc();
kRenderer.m_pkDevice->CreateRenderTargetView(
kFrame.m_pkBufferResource, nullptr, kFrame.m_hHandle);
VE_ASSERT_GE(kRenderer.m_pkDevice->CreateCommandAllocator(
D3D12_COMMAND_LIST_TYPE_DIRECT,
IID_PPV_ARGS(&kFrame.m_pkDirectAllocator)), S_OK);
VE_ASSERT_GE(kRenderer.m_pkDevice->CreateCommandAllocator(
D3D12_COMMAND_LIST_TYPE_BUNDLE,
IID_PPV_ARGS(&kFrame.m_pkBundleAllocator)), S_OK);
kFrame.m_u64FenceValue = 0;
VE_ASSERT_GE(kRenderer.m_pkDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT,
kFrame.m_pkDirectAllocator, nullptr, IID_PPV_ARGS(&kFrame.m_pkTestList)), S_OK);
VE_ASSERT_GE(kFrame.m_pkTestList->Close(), S_OK);
}
m_u64FenceValue = 0;
VE_ASSERT_GE(kRenderer.m_pkDevice->CreateFence(m_u64FenceValue++,
D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&m_pkFence)), S_OK);
m_kFenceEvent = CreateEventEx(nullptr, FALSE, FALSE, EVENT_ALL_ACCESS);
VE_ASSERT(m_kFenceEvent);
const uint64_t u64FenceToWaitFor = m_u64FenceValue++;
VE_ASSERT_GE(m_pkCommandQueue->Signal(m_pkFence, u64FenceToWaitFor), S_OK);
VE_ASSERT_GE(m_pkFence->SetEventOnCompletion(u64FenceToWaitFor, m_kFenceEvent), S_OK);
WaitForSingleObject(m_kFenceEvent, INFINITE);
m_u32FramePtr = m_pkSwapChain->GetCurrentBackBufferIndex();
m_u64FrameIndex = 0;
m_spTargetWindow->Show();
kRenderer.m_kRenderWindowList.attach_back(m_kNode);
}
}
示例2: CreateSwapChain
std::shared_ptr<IDXGISwapChain3> CreateSwapChain( ID3D12Device * device, ID3D12CommandQueue * commandQueue, const HWND* hWnd, DXGI_SWAP_CHAIN_DESC* swapChainDesc)
{
IDXGISwapChain* swapChain;
IDXGISwapChain3* swapChain3;
DXGI_SWAP_CHAIN_DESC defaultDesc = {};
if (!swapChainDesc)
{
defaultDesc.BufferCount = 2;
defaultDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
defaultDesc.BufferDesc.Width = 1200;
defaultDesc.BufferDesc.Height = 900;
defaultDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
defaultDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
defaultDesc.OutputWindow = *hWnd;
defaultDesc.SampleDesc.Count = 1;
defaultDesc.Windowed = TRUE;
swapChainDesc = &defaultDesc;
}
DirectX::ThrowIfFailed(CreateFactory()->CreateSwapChain(
commandQueue,
swapChainDesc,
&swapChain
));
swapChain->QueryInterface(IID_PPV_ARGS(&swapChain3));
swapChain->Release();
return std::shared_ptr<IDXGISwapChain3>(swapChain3, ReleaseIUnknown);
}
示例3: Initialize
void SwapChain::Initialize(HWND outputWindow)
{
Shutdown();
// We'll just use the first output for fullscreen
DX12::Adapter->EnumOutputs(0, &output);
if(format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB)
noSRGBFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
else if(format == DXGI_FORMAT_B8G8R8A8_UNORM_SRGB)
noSRGBFormat = DXGI_FORMAT_B8G8R8A8_UNORM;
else
noSRGBFormat = format;
DXGI_SWAP_CHAIN_DESC swapChainDesc = {};
swapChainDesc.BufferCount = uint32(NumBackBuffers);
swapChainDesc.BufferDesc.Width = width;
swapChainDesc.BufferDesc.Height = height;
swapChainDesc.BufferDesc.Format = noSRGBFormat;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
swapChainDesc.OutputWindow = outputWindow;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.Windowed = TRUE;
swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH |
DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING |
DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT;
IDXGISwapChain* tempSwapChain = nullptr;
DXCall(DX12::Factory->CreateSwapChain(DX12::GfxQueue, &swapChainDesc, &tempSwapChain));
DXCall(tempSwapChain->QueryInterface(IID_PPV_ARGS(&swapChain)));
DX12::Release(tempSwapChain);
backBufferIdx = swapChain->GetCurrentBackBufferIndex();
waitableObject = swapChain->GetFrameLatencyWaitableObject();
AfterReset();
}
示例4: QueryInterface
HRESULT STDMETHODCALLTYPE CDXGISwapChainDWM::QueryInterface(REFIID riid, void **ppvObj)
{
return m_pSwapChain->QueryInterface(riid, ppvObj);
}
示例5: CreateSwapChain
HRESULT DXManager::CreateSwapChain()
{
HRESULT hr = S_FALSE;
DXGI_SWAP_CHAIN_DESC swapChainDesc;
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
// Set the swap chain to use double buffering.
swapChainDesc.BufferCount = 2;
// Set the height and width of the back buffers in the swap chain.
swapChainDesc.BufferDesc.Height = m_WindowHeight;
swapChainDesc.BufferDesc.Width = m_WindowWidth;
// Set a regular 32-bit surface for the back buffers.
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
// Set the usage of the back buffers to be render target outputs.
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
// Set the swap effect to discard the previous buffer contents after swapping.
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
// Set the handle for the window to render to.
swapChainDesc.OutputWindow = m_hWnd;
// Set to full screen or windowed mode.
if (m_FullScreen)
swapChainDesc.Windowed = false;
else
swapChainDesc.Windowed = true;
// Set the refresh rate of the back buffer.
if (m_VSYNC)
{
swapChainDesc.BufferDesc.RefreshRate.Numerator = m_Numerator;
swapChainDesc.BufferDesc.RefreshRate.Denominator = m_Denominator;
}
else
{
swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
}
// Turn multisampling off.
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
// Set the scan line ordering and scaling to unspecified.
swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
// Don't set the advanced flags.
swapChainDesc.Flags = 0;
IDXGISwapChain* swapChain;
ZeroMemory(&swapChain, sizeof(IDXGISwapChain));
hr = m_Factory->CreateSwapChain(m_CommandQueue, &swapChainDesc, &swapChain);
if (FAILED(hr))
return hr;
hr = swapChain->QueryInterface(__uuidof(IDXGISwapChain3), (void**)&m_SwapChain);
if (FAILED(hr))
return hr;
D3D12_DESCRIPTOR_HEAP_DESC renderTargetViewHeapDesc;
ZeroMemory(&renderTargetViewHeapDesc, sizeof(D3D12_DESCRIPTOR_HEAP_DESC));
renderTargetViewHeapDesc.NumDescriptors = 2;
renderTargetViewHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
renderTargetViewHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
hr = m_Device->CreateDescriptorHeap(&renderTargetViewHeapDesc, __uuidof(ID3D12DescriptorHeap), (void**)&m_RenderTargetViewHeap);
if (FAILED(hr))
return hr;
D3D12_CPU_DESCRIPTOR_HANDLE renderTargetViewHandle;
ZeroMemory(&renderTargetViewHandle, sizeof(D3D12_CPU_DESCRIPTOR_HANDLE));
renderTargetViewHandle = m_RenderTargetViewHeap->GetCPUDescriptorHandleForHeapStart();
unsigned int renderTargetViewDescriptorSize = 0;
renderTargetViewDescriptorSize = m_Device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
hr = m_SwapChain->GetBuffer(0, __uuidof(ID3D12Resource), (void**)&m_BackBufferRenderTarget[0]);
if (FAILED(hr))
return hr;
m_Device->CreateRenderTargetView(m_BackBufferRenderTarget[0], NULL, renderTargetViewHandle);
renderTargetViewHandle.ptr += renderTargetViewDescriptorSize;
hr = m_SwapChain->GetBuffer(1, __uuidof(ID3D12Resource), (void**)&m_BackBufferRenderTarget[1]);
if (FAILED(hr))
return hr;
m_Device->CreateRenderTargetView(m_BackBufferRenderTarget[1], NULL, renderTargetViewHandle);
m_BufferIndex = m_SwapChain->GetCurrentBackBufferIndex();
swapChain->Release();
return hr;
}
示例6: Init
void GraphicsDevice::Init(u32 screenWidth, u32 screenHeight)
{
#define GRAPHICSINIT_ON_FAILED(failCondition, errorMessage, ...) \
do { \
if(failCondition) \
{ \
Assertf(false, errorMessage, __VA_ARGS__); \
return; \
} \
} while(0)
HRESULT hr;
#if RECON_DEBUG
ID3D12Debug* debugInterface;
hr = D3D12GetDebugInterface(__uuidof(ID3D12Debug), (void**)&debugInterface);
if(Verifyf(SUCCEEDED(hr), "Failed To Create Graphics Debug Interface! Error Code: '%d'", hr))
{
debugInterface->EnableDebugLayer();
}
#endif // RECON_DEBUG
hr = D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, __uuidof(ID3D12Device), (void**)&m_pDevice);
GRAPHICSINIT_ON_FAILED(FAILED(hr), "Failed To Create D3D12 Device! Error Code: '%d'", hr);
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
hr = m_pDevice->CreateCommandQueue(&queueDesc, __uuidof(ID3D12CommandQueue), (void**)&m_pCommandQueue);
GRAPHICSINIT_ON_FAILED(FAILED(hr), "Failed To Create D3D12 Command Queue! Error Code: '%d'", hr);
// NOTE: rasterTek does a bunch of extra stuff here before creating the swap chain
// to potentially help performance? But the Directx 12 Samples don't do this.
// may want to investigate in the future
IDXGIFactory4* pFactory = nullptr;
hr = CreateDXGIFactory1(__uuidof(IDXGIFactory4), (void**)&pFactory);
GRAPHICSINIT_ON_FAILED(FAILED(hr), "Failed To Create DXGI Factory! Error Code: '%d'", hr);
HWND hWnd = ((AppWindow_Windows*)AppEntryPoint::GetWindow())->GetWindowHandle();
DXGI_SWAP_CHAIN_DESC swapChainDesc = {};
swapChainDesc.BufferCount = ms_FrameCount;
swapChainDesc.BufferDesc.Width = screenWidth;
swapChainDesc.BufferDesc.Height = screenHeight;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
swapChainDesc.OutputWindow = hWnd;
swapChainDesc.Windowed = TRUE;
// Multisampling
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
// Flags
swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT;
IDXGISwapChain* pSwapChain = nullptr;
hr = pFactory->CreateSwapChain(m_pCommandQueue, &swapChainDesc, &pSwapChain);
GRAPHICSINIT_ON_FAILED(FAILED(hr), "Failed To Create Swap Chain! Error Code: '%d'", hr);
hr = pSwapChain->QueryInterface(__uuidof(IDXGISwapChain3), (void**)&m_pSwapChain);
GRAPHICSINIT_ON_FAILED(FAILED(hr), "Failed To Create Swap Chain 3! Error Code: '%d'", hr);
// We're done with the factory
pFactory->Release();
pFactory = nullptr;
m_FrameIndex = m_pSwapChain->GetCurrentBackBufferIndex();
D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc = {};
rtvHeapDesc.NumDescriptors = ms_FrameCount;
rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
hr = m_pDevice->CreateDescriptorHeap(&rtvHeapDesc, __uuidof(ID3D12DescriptorHeap), (void**)&m_pRTVHeap);
GRAPHICSINIT_ON_FAILED(FAILED(hr), "Failed To Create RTV Descriptor Heap! Error Code: '%d'", hr);
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = m_pRTVHeap->GetCPUDescriptorHandleForHeapStart();
u32 rtvHeapIncSize = m_pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
for(int i = 0; i < ms_FrameCount; ++i)
{
hr = m_pSwapChain->GetBuffer(i, __uuidof(ID3D12Resource), (void**)&m_pRenderTargets[i]);
GRAPHICSINIT_ON_FAILED(FAILED(hr), "Failed To Get RTV (%d) From Swap Chain! Error Code: '%d'", i, hr);
m_pDevice->CreateRenderTargetView(m_pRenderTargets[i], nullptr, rtvHandle);
rtvHandle.ptr += rtvHeapIncSize;
hr = m_pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, __uuidof(ID3D12CommandAllocator), (void**)&m_pCommandAllocators[i]);
GRAPHICSINIT_ON_FAILED(FAILED(hr), "Failed To Create GPU Command Allocator! Error Code: '%d'", i, hr);
}
// Will want to move this to another class once multithreaded rendering is supported
hr = m_pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_pCommandAllocators[0], nullptr, __uuidof(ID3D12GraphicsCommandList), (void**)&m_pGraphicsCommandList);
GRAPHICSINIT_ON_FAILED(FAILED(hr), "Failed To Create GPU Command Allocator! Error Code: '%d'", hr);
hr = m_pGraphicsCommandList->Close();
//.........这里部分代码省略.........
示例7: readRange
//.........这里部分代码省略.........
swapChainDesc.OutputWindow = hwnd;
// Set to full screen or windowed mode.
swapChainDesc.Windowed = !fullscreen;
// Set the refresh rate of the back buffer.
if (m_vsync_enabled)
{
swapChainDesc.BufferDesc.RefreshRate.Numerator = numerator;
swapChainDesc.BufferDesc.RefreshRate.Denominator = denominator;
}
else
{
swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
}
// Turn multisampling off.
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
// Set the scan line ordering and scaling to unspecified.
swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
// Don't set the advanced flags.
swapChainDesc.Flags = 0;
// Finally create the swap chain using the swap chain description.
factory->CreateSwapChain(m_commandQueue, &swapChainDesc, &swapChain);
// Next upgrade the IDXGISwapChain to a IDXGISwapChain3 interface and store it in a private member variable named m_swapChain.
// This will allow us to use the newer functionality such as getting the current back buffer index.
swapChain->QueryInterface(__uuidof(IDXGISwapChain3), (void**)&m_swapChain);
// Clear pointer to original swap chain interface since we are using version 3 instead (m_swapChain).
swapChain = nullptr;
// Release the factory now that the swap chain has been created.
factory->Release();
factory = nullptr;
// Initialize the render target view heap description for the two back buffers.
ZeroMemory(&renderTargetViewHeapDesc, sizeof(renderTargetViewHeapDesc));
// Set the number of descriptors to two for our two back buffers. Also set the heap tyupe to render target views.
renderTargetViewHeapDesc.NumDescriptors = 2;
renderTargetViewHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
renderTargetViewHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
// Create the render target view heap for the back buffers.
m_device->CreateDescriptorHeap(&renderTargetViewHeapDesc, __uuidof(ID3D12DescriptorHeap), (void**)&m_renderTargetViewHeap);
// Get a handle to the starting memory location in the render target view heap to identify where the render target views will be located for the two back buffers.
renderTargetViewHandle = m_renderTargetViewHeap->GetCPUDescriptorHandleForHeapStart();
// Get the size of the memory location for the render target view descriptors.
renderTargetViewDescriptorSize = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
// Get a pointer to the first back buffer from the swap chain.
m_swapChain->GetBuffer(0, __uuidof(ID3D12Resource), (void**)&m_backBufferRenderTarget[0]);
// Create a render target view for the first back buffer.
m_device->CreateRenderTargetView(m_backBufferRenderTarget[0], NULL, renderTargetViewHandle);
// Increment the view handle to the next descriptor location in the render target view heap.
示例8: CreateEventEx
//--------------------------------------------------------------------------
void VeRenderWindowD3D12::Init(VeRendererD3D12& kRenderer) noexcept
{
if ((!m_kNode.is_attach()) && m_spTargetWindow)
{
D3D12_COMMAND_QUEUE_DESC kQueueDesc = {};
kQueueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
kQueueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
if (FAILED(kRenderer.m_pkDevice->CreateCommandQueue(&kQueueDesc,
IID_PPV_ARGS(&m_pkCommandQueue))))
{
VE_SAFE_RELEASE(m_pkCommandQueue);
VE_SAFE_RELEASE(m_pkSwapChain);
return;
}
DXGI_SWAP_CHAIN_DESC kSwapChainDesc = {};
kSwapChainDesc.BufferCount = VeRendererD3D12::FRAME_COUNT;
kSwapChainDesc.BufferDesc.Width = m_spTargetWindow->GetWidth();
kSwapChainDesc.BufferDesc.Height = m_spTargetWindow->GetHeight();
kSwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R10G10B10A2_UNORM;
kSwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
kSwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
kSwapChainDesc.OutputWindow = m_spTargetWindow->GetWMInfo().win.window;
kSwapChainDesc.SampleDesc.Count = 1;
kSwapChainDesc.Windowed = TRUE;
IDXGISwapChain* pkSwapChain;
if (FAILED(kRenderer.m_pkDXGIFactory->CreateSwapChain(m_pkCommandQueue,
&kSwapChainDesc, &pkSwapChain)))
{
VE_SAFE_RELEASE(m_pkCommandQueue);
VE_SAFE_RELEASE(pkSwapChain);
return;
}
if (FAILED(pkSwapChain->QueryInterface(IID_PPV_ARGS(&m_pkSwapChain))))
{
VE_SAFE_RELEASE(m_pkCommandQueue);
VE_SAFE_RELEASE(pkSwapChain);
VE_SAFE_RELEASE(m_pkSwapChain);
return;
}
else
{
VE_SAFE_RELEASE(pkSwapChain);
}
VE_ASSERT(m_pkCommandQueue && m_pkSwapChain);
for (VeInt32 i(0); i < VeRendererD3D12::FRAME_COUNT; ++i)
{
FrameCache& kFrame = m_akFrameCache[i];
VE_ASSERT_GE(m_pkSwapChain->GetBuffer(i, IID_PPV_ARGS(&kFrame.m_pkBufferResource)), S_OK);
kFrame.m_hHandle.ptr = kRenderer.m_kRTVHeap.GetCPUStart().ptr + kRenderer.m_kRTVHeap.Alloc();
kRenderer.m_pkDevice->CreateRenderTargetView(
kFrame.m_pkBufferResource, nullptr, kFrame.m_hHandle);
VE_ASSERT_GE(kRenderer.m_pkDevice->CreateCommandAllocator(
D3D12_COMMAND_LIST_TYPE_DIRECT,
IID_PPV_ARGS(&kFrame.m_pkDirectAllocator)), S_OK);
VE_ASSERT_GE(kRenderer.m_pkDevice->CreateCommandAllocator(
D3D12_COMMAND_LIST_TYPE_BUNDLE,
IID_PPV_ARGS(&kFrame.m_pkBundleAllocator)), S_OK);
kFrame.m_u64FenceValue = 0;
}
m_u64FenceValue = 0;
VE_ASSERT_GE(kRenderer.m_pkDevice->CreateFence(m_u64FenceValue++,
D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&m_pkFence)), S_OK);
m_kFenceEvent = CreateEventEx(nullptr, FALSE, FALSE, EVENT_ALL_ACCESS);
VE_ASSERT(m_kFenceEvent);
const VeUInt64 u64FenceToWaitFor = m_u64FenceValue++;
VE_ASSERT_GE(m_pkCommandQueue->Signal(m_pkFence, u64FenceToWaitFor), S_OK);
VE_ASSERT_GE(m_pkFence->SetEventOnCompletion(u64FenceToWaitFor, m_kFenceEvent), S_OK);
WaitForSingleObject(m_kFenceEvent, INFINITE);
m_u32FrameIndex = m_pkSwapChain->GetCurrentBackBufferIndex();
kRenderer.m_kRenderWindowList.attach_back(m_kNode);
}
m_kViewport.TopLeftX = 0;
m_kViewport.TopLeftY = 0;
m_kViewport.Width = m_spTargetWindow->GetWidth();
m_kViewport.Height = m_spTargetWindow->GetHeight();
m_kViewport.MinDepth = 0.0f;
m_kViewport.MaxDepth = 1.0f;
m_kScissorRect.left = 0;
m_kScissorRect.right = m_spTargetWindow->GetWidth();
m_kScissorRect.top = 0;
m_kScissorRect.bottom = m_spTargetWindow->GetHeight();
{
m_vertexBufferView.BufferLocation = kRenderer.m_kRenderBufferList.get_tail_node()->m_Content->m_pkResource->GetGPUVirtualAddress();
m_vertexBufferView.StrideInBytes = sizeof(VE_FLOAT3);
m_vertexBufferView.SizeInBytes = kRenderer.m_kRenderBufferList.get_head_node()->m_Content->GetSize();
}
}