2019-03-09 13:31:36 +00:00
|
|
|
// Copyright 2019 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2019-03-09 13:31:36 +00:00
|
|
|
|
2020-09-15 12:50:34 +00:00
|
|
|
#include "VideoBackends/D3D/D3DSwapChain.h"
|
2021-12-10 02:22:16 +00:00
|
|
|
|
2019-03-09 13:31:36 +00:00
|
|
|
#include "VideoBackends/D3D/DXTexture.h"
|
|
|
|
|
|
|
|
namespace DX11
|
|
|
|
{
|
2019-05-12 04:42:16 +00:00
|
|
|
SwapChain::SwapChain(const WindowSystemInfo& wsi, IDXGIFactory* dxgi_factory,
|
2019-03-09 13:31:36 +00:00
|
|
|
ID3D11Device* d3d_device)
|
|
|
|
: D3DCommon::SwapChain(wsi, dxgi_factory, d3d_device)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SwapChain::~SwapChain() = default;
|
|
|
|
|
|
|
|
std::unique_ptr<SwapChain> SwapChain::Create(const WindowSystemInfo& wsi)
|
|
|
|
{
|
|
|
|
std::unique_ptr<SwapChain> swap_chain =
|
|
|
|
std::make_unique<SwapChain>(wsi, D3D::dxgi_factory.Get(), D3D::device.Get());
|
|
|
|
if (!swap_chain->CreateSwapChain(WantsStereo()))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return swap_chain;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SwapChain::CreateSwapChainBuffers()
|
|
|
|
{
|
|
|
|
ComPtr<ID3D11Texture2D> texture;
|
|
|
|
HRESULT hr = m_swap_chain->GetBuffer(0, IID_PPV_ARGS(&texture));
|
|
|
|
CHECK(SUCCEEDED(hr), "Get swap chain buffer");
|
|
|
|
if (FAILED(hr))
|
|
|
|
return false;
|
|
|
|
|
2019-07-21 14:31:22 +00:00
|
|
|
m_texture = DXTexture::CreateAdopted(std::move(texture));
|
2019-03-09 13:31:36 +00:00
|
|
|
if (!m_texture)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_framebuffer = DXFramebuffer::Create(m_texture.get(), nullptr);
|
|
|
|
if (!m_framebuffer)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwapChain::DestroySwapChainBuffers()
|
|
|
|
{
|
|
|
|
m_framebuffer.reset();
|
|
|
|
m_texture.reset();
|
|
|
|
}
|
|
|
|
} // namespace DX11
|